diff --git a/.editorconfig b/.editorconfig index 44c9cfe..1ac37b7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,4 +9,11 @@ end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true +max_line_length = 80 trim_trailing_whitespace = true + +[*.md] +max_line_length = 0 +trim_trailing_whitespace = false + +root = true diff --git a/.gitignore b/.gitignore index 4b309b1..03cbfc4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ coverage node_modules -post +dist diff --git a/.npmignore b/.npmignore index ffe0fed..640797c 100644 --- a/.npmignore +++ b/.npmignore @@ -5,8 +5,10 @@ .gitignore .npmignore eslint.config.js -package.lock.json eslint-results.sarif -coverage -lib/ -post/ +package.lock.json +coverage/ +src/ +data/ +test/ +rollup.config.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 481c82b..396781c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ Todas as mudanças notáveis neste projeto serão documentadas neste arquivo. --- +## 1.1.0 (2024-10-18) + +### Adiciona Dependência + +* Adicionado Rollup como ferramenta de build para empacotamento do projeto. +* Configurado Rollup para gerar builds nos formatos CommonJS e ESModule. +* Melhorado o processo de build para melhor performance e compatibilidade com diferentes sistemas de módulos. + +--- + ## 1.0.6 (2024-10-09) ### Adiciona Funcionalidades diff --git a/README.md b/README.md index 19825d7..cff6ac6 100644 --- a/README.md +++ b/README.md @@ -47,15 +47,29 @@ O pacote foi testado e é compatível com as versões mais recentes dos seguinte npm install gerador-br ``` -## Uso +## Importação -### *Named import* +### *CommonsJS* +```js +const gerar = require('gerador-br'); +``` + +### *ES Module* +```js +import gerar from 'gerador-br'; +``` + +## Utilização -Importe apenas a(s) função(ões) que desejar +***Named import:*** Importe apenas a(s) função(ões) que desejar ```js +// ES Module import { nome, cpf, cnpj, placaMercosul } from 'gerador-br'; +// CommonJS +// const { nome, cpf, cnpj, placaMercosul } = require('gerador-br'); + console.log(nome.femininoCompleto()); // Ex: "Maria" console.log(cpf()); // Gera CPF sem máscara e do estado aleatório console.log(cpf(false, "PE")); // Gera CPF sem máscara e do estado info @@ -63,15 +77,19 @@ console.log(cnpj(true)); // Gera CNPJ com máscara console.log(placaMercosul(true)); // Gera placa no formato Mercosul com máscara "ABC-1D23" ``` -### *Default import* - -Importe todo o módulo `gerar` e depois use qualquer função que desejar +***Default import:*** Importe todo o módulo **`gerar`** e depois use qualquer função que desejar > Observação: Todas as funções do modulo `gerar` podem ser importadas individualmente (como nos exemplos acima - *named import*) ```js +// Para ES Module: import gerar from 'gerador-br'; +// Para CommonJS: +// const gerar = require('gerador-br'); + +// Exemplos: + /* ******************** DOCUMENTOS ********************** */ // Gera CNH aleatória console.log(gerar.cnh()); @@ -448,6 +466,10 @@ console.log(gerar.paragrafo(5)); console.log(gerar.paragrafo(3,8)); ``` +## Contribuições + +Contribuições são bem-vindas! Faça um *fork* do repositório e sinta-se à vontade para enviar seus *pull requests*. + ## Extensão Chrome - Gerador de Dados Fictícios Todas essas funções foram utilizadas na [Extensão Chrome - Gerador de Dados Fictícios](https://chromewebstore.google.com/detail/ipfihnddjaepajgdamecijfdefikdgam). diff --git a/package-lock.json b/package-lock.json index ed64ec2..d3bcf54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,23 @@ { "name": "gerador-br", - "version": "1.0.5", + "version": "1.0.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gerador-br", - "version": "1.0.5", + "version": "1.0.6", "license": "MIT", "devDependencies": { "@eslint/js": "^9.12.0", "@microsoft/eslint-formatter-sarif": "^3.1.0", + "@rollup/plugin-commonjs": "^28.0.0", + "@rollup/plugin-node-resolve": "^15.3.0", "c8": "^10.1.2", "coveralls": "^3.1.1", "eslint-plugin-import": "^2.31.0", - "globals": "^15.10.0" + "globals": "^15.10.0", + "rollup": "^4.24.0" }, "engines": { "node": ">=18.0.0", @@ -323,12 +326,322 @@ "node": ">=14" } }, + "node_modules/@rollup/plugin-commonjs": { + "version": "28.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-28.0.0.tgz", + "integrity": "sha512-BJcu+a+Mpq476DMXG+hevgPSl56bkUoi88dKT8t3RyUp8kGuOh+2bU8Gs7zXDlu+fyZggnJ+iOBGrb/O1SorYg==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "commondir": "^1.0.1", + "estree-walker": "^2.0.2", + "fdir": "^6.1.1", + "is-reference": "1.2.1", + "magic-string": "^0.30.3", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=16.0.0 || 14 >= 14.17" + }, + "peerDependencies": { + "rollup": "^2.68.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-commonjs/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/@rollup/plugin-node-resolve": { + "version": "15.3.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.3.0.tgz", + "integrity": "sha512-9eO5McEICxMzJpDW9OnMYSv4Sta3hmt7VtBFz5zR9273suNOydOyq/FrGeGy+KsTRFm8w0SLVhzig2ILFT63Ag==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "@types/resolve": "1.20.2", + "deepmerge": "^4.2.2", + "is-module": "^1.0.0", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.78.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.2.tgz", + "integrity": "sha512-/FIdS3PyZ39bjZlwqFnWqCOVnW7o963LtKMwQOD0NhQqw22gSr2YY1afu3FxRip4ZCZNsD5jq6Aaz6QV3D/Njw==", + "dev": true, + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.24.0.tgz", + "integrity": "sha512-Q6HJd7Y6xdB48x8ZNVDOqsbh2uByBhgK8PiQgPhwkIw/HC/YX5Ghq2mQY5sRMZWHb3VsFkWooUVOZHKr7DmDIA==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.24.0.tgz", + "integrity": "sha512-ijLnS1qFId8xhKjT81uBHuuJp2lU4x2yxa4ctFPtG+MqEE6+C5f/+X/bStmxapgmwLwiL3ih122xv8kVARNAZA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.24.0.tgz", + "integrity": "sha512-bIv+X9xeSs1XCk6DVvkO+S/z8/2AMt/2lMqdQbMrmVpgFvXlmde9mLcbQpztXm1tajC3raFDqegsH18HQPMYtA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.24.0.tgz", + "integrity": "sha512-X6/nOwoFN7RT2svEQWUsW/5C/fYMBe4fnLK9DQk4SX4mgVBiTA9h64kjUYPvGQ0F/9xwJ5U5UfTbl6BEjaQdBQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.24.0.tgz", + "integrity": "sha512-0KXvIJQMOImLCVCz9uvvdPgfyWo93aHHp8ui3FrtOP57svqrF/roSSR5pjqL2hcMp0ljeGlU4q9o/rQaAQ3AYA==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.24.0.tgz", + "integrity": "sha512-it2BW6kKFVh8xk/BnHfakEeoLPv8STIISekpoF+nBgWM4d55CZKc7T4Dx1pEbTnYm/xEKMgy1MNtYuoA8RFIWw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.24.0.tgz", + "integrity": "sha512-i0xTLXjqap2eRfulFVlSnM5dEbTVque/3Pi4g2y7cxrs7+a9De42z4XxKLYJ7+OhE3IgxvfQM7vQc43bwTgPwA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.24.0.tgz", + "integrity": "sha512-9E6MKUJhDuDh604Qco5yP/3qn3y7SLXYuiC0Rpr89aMScS2UAmK1wHP2b7KAa1nSjWJc/f/Lc0Wl1L47qjiyQw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.24.0.tgz", + "integrity": "sha512-2XFFPJ2XMEiF5Zi2EBf4h73oR1V/lycirxZxHZNc93SqDN/IWhYYSYj8I9381ikUFXZrz2v7r2tOVk2NBwxrWw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.24.0.tgz", + "integrity": "sha512-M3Dg4hlwuntUCdzU7KjYqbbd+BLq3JMAOhCKdBE3TcMGMZbKkDdJ5ivNdehOssMCIokNHFOsv7DO4rlEOfyKpg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.24.0.tgz", + "integrity": "sha512-mjBaoo4ocxJppTorZVKWFpy1bfFj9FeCMJqzlMQGjpNPY9JwQi7OuS1axzNIk0nMX6jSgy6ZURDZ2w0QW6D56g==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.24.0.tgz", + "integrity": "sha512-ZXFk7M72R0YYFN5q13niV0B7G8/5dcQ9JDp8keJSfr3GoZeXEoMHP/HlvqROA3OMbMdfr19IjCeNAnPUG93b6A==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.24.0.tgz", + "integrity": "sha512-w1i+L7kAXZNdYl+vFvzSZy8Y1arS7vMgIy8wusXJzRrPyof5LAb02KGr1PD2EkRcl73kHulIID0M501lN+vobQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.24.0.tgz", + "integrity": "sha512-VXBrnPWgBpVDCVY6XF3LEW0pOU51KbaHhccHw6AS6vBWIC60eqsH19DAeeObl+g8nKAz04QFdl/Cefta0xQtUQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.24.0.tgz", + "integrity": "sha512-xrNcGDU0OxVcPTH/8n/ShH4UevZxKIO6HJFK0e15XItZP2UcaiLFd5kiX7hJnqCbSztUF8Qot+JWBC/QXRPYWQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.24.0.tgz", + "integrity": "sha512-fbMkAF7fufku0N2dE5TBXcNlg0pt0cJue4xBRE2Qc5Vqikxr4VCgKj/ht6SMdFcOacVA9rqF70APJ8RN/4vMJw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@rtsao/scc": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@rtsao/scc/-/scc-1.1.0.tgz", "integrity": "sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g==", "dev": true }, + "node_modules/@types/estree": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", + "dev": true + }, "node_modules/@types/istanbul-lib-coverage": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", @@ -341,6 +654,12 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "node_modules/@types/resolve": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", + "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", + "dev": true + }, "node_modules/@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", @@ -734,6 +1053,12 @@ "node": ">= 0.8" } }, + "node_modules/commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", + "dev": true + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -893,6 +1218,15 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, + "node_modules/deepmerge": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", + "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/define-data-property": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", @@ -1395,6 +1729,12 @@ "node": ">=4.0" } }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -1446,6 +1786,20 @@ "reusify": "^1.0.4" } }, + "node_modules/fdir": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.0.tgz", + "integrity": "sha512-3oB133prH1o4j/L5lLW7uOCF1PlD+/It2L0eL/iAqWMB91RBbqTewABqxhj0ibBd90EEmWZq7ntIWzVaWcXTGQ==", + "dev": true, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -1548,6 +1902,20 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -2038,6 +2406,12 @@ "node": ">=0.10.0" } }, + "node_modules/is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", + "dev": true + }, "node_modules/is-negative-zero": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.3.tgz", @@ -2074,6 +2448,15 @@ "node": ">=8" } }, + "node_modules/is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "dependencies": { + "@types/estree": "*" + } + }, "node_modules/is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -2394,6 +2777,15 @@ "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", "dev": true }, + "node_modules/magic-string": { + "version": "0.30.12", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.12.tgz", + "integrity": "sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==", + "dev": true, + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0" + } + }, "node_modules/make-dir": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", @@ -2710,6 +3102,20 @@ "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==", "dev": true }, + "node_modules/picomatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", + "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "dev": true, + "optional": true, + "peer": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/possible-typed-array-names": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", @@ -2883,6 +3289,41 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rollup": { + "version": "4.24.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.24.0.tgz", + "integrity": "sha512-DOmrlGSXNk1DM0ljiQA+i+o0rSLhtii1je5wgk60j49d1jHT5YYttBv1iWOnYSTG+fZZESUOSNiAl89SIet+Cg==", + "dev": true, + "dependencies": { + "@types/estree": "1.0.6" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.24.0", + "@rollup/rollup-android-arm64": "4.24.0", + "@rollup/rollup-darwin-arm64": "4.24.0", + "@rollup/rollup-darwin-x64": "4.24.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.24.0", + "@rollup/rollup-linux-arm-musleabihf": "4.24.0", + "@rollup/rollup-linux-arm64-gnu": "4.24.0", + "@rollup/rollup-linux-arm64-musl": "4.24.0", + "@rollup/rollup-linux-powerpc64le-gnu": "4.24.0", + "@rollup/rollup-linux-riscv64-gnu": "4.24.0", + "@rollup/rollup-linux-s390x-gnu": "4.24.0", + "@rollup/rollup-linux-x64-gnu": "4.24.0", + "@rollup/rollup-linux-x64-musl": "4.24.0", + "@rollup/rollup-win32-arm64-msvc": "4.24.0", + "@rollup/rollup-win32-ia32-msvc": "4.24.0", + "@rollup/rollup-win32-x64-msvc": "4.24.0", + "fsevents": "~2.3.2" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", diff --git a/package.json b/package.json index f3dd0b8..baff0f0 100644 --- a/package.json +++ b/package.json @@ -1,28 +1,31 @@ { "name": "gerador-br", - "version": "1.0.6", + "version": "1.1.0", "description": " Gerador de Dados Fictícios - Brasil", - "main": "index.js", - "module": "index.js", "type": "module", + "main": "dist/cjs/index.cjs", + "module": "dist/mjs/index.mjs", + "files": [ + "dist" + ], "license": "MIT", "author": "Marcelo Lourenço ", "scripts": { + "build": "rollup -c", "lint": "eslint . -c eslint.config.js -f @microsoft/eslint-formatter-sarif -o eslint-results.sarif", "test": "node --test test", - "coverage":"npx c8 --reporter=lcov node --test" + "coverage": "npx c8 --reporter=lcov node --test" }, "devDependencies": { "@eslint/js": "^9.12.0", "@microsoft/eslint-formatter-sarif": "^3.1.0", + "@rollup/plugin-commonjs": "^28.0.0", + "@rollup/plugin-node-resolve": "^15.3.0", "c8": "^10.1.2", "coveralls": "^3.1.1", "eslint-plugin-import": "^2.31.0", - "globals": "^15.10.0" - }, - "engines": { - "node": ">=18.0.0", - "npm": ">=9.0.0" + "globals": "^15.10.0", + "rollup": "^4.24.0" }, "repository": { "type": "git", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..380c13b --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,38 @@ +import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; + +export default { + input: 'src/index.js', // Arquivo principal de entrada + output: [ + { + dir: 'dist/cjs', // Diretório de saída para CommonJS + format: 'cjs', + entryFileNames: '[name].cjs', // Mantém o nome do arquivo original + exports: 'auto', + preserveModules: true, // Preserva a estrutura dos módulos + preserveModulesRoot: 'src', // Diretório base que será mantido + }, + { + dir: 'dist/mjs', // Diretório de saída para ES Modules + format: 'es', + entryFileNames: '[name].mjs', + preserveModules: true, + preserveModulesRoot: 'src', + } + /* + { + file: 'dist/index.cjs', + format: 'cjs', // Gera CommonJS + exports: 'auto' + }, + { + file: 'dist/index.mjs', + format: 'es', // Gera ESModule + } + */ + ], + plugins: [ + resolve(), // Resolve módulos de node_modules + commonjs() // Converte pacotes CommonJS para ESModules + ] +}; diff --git a/data/db-bancos.js b/src/data/db-bancos.js similarity index 100% rename from data/db-bancos.js rename to src/data/db-bancos.js diff --git a/data/db-ceps.js b/src/data/db-ceps.js similarity index 100% rename from data/db-ceps.js rename to src/data/db-ceps.js diff --git a/data/db-general.js b/src/data/db-general.js similarity index 100% rename from data/db-general.js rename to src/data/db-general.js diff --git a/src/generators/banco.js b/src/generators/banco.js index 3ca7458..2b6d325 100644 --- a/src/generators/banco.js +++ b/src/generators/banco.js @@ -1,4 +1,4 @@ -import banks from '../../data/db-bancos.js'; +import banks from '../data/db-bancos.js'; const getRandom = (arr) => arr[Math.floor(Math.random() * arr.length)]; diff --git a/src/generators/cep.js b/src/generators/cep.js index 0acbe3c..687c33a 100644 --- a/src/generators/cep.js +++ b/src/generators/cep.js @@ -1,4 +1,4 @@ -import dbCep from '../../data/db-ceps.js'; +import dbCep from '../data/db-ceps.js'; import { stateRand } from '../utils.js'; const getRandom = (arr) => arr[Math.floor(Math.random() * arr.length)]; diff --git a/src/generators/endereco.js b/src/generators/endereco.js index 4b17f8b..17e66b4 100644 --- a/src/generators/endereco.js +++ b/src/generators/endereco.js @@ -1,4 +1,4 @@ -import dbCep from '../../data/db-ceps.js'; +import dbCep from '../data/db-ceps.js'; import { stateRand } from '../utils.js'; const getRandom = (arr) => arr[Math.floor(Math.random() * arr.length)]; diff --git a/src/generators/texto.js b/src/generators/texto.js index cdb0c99..e4a1133 100644 --- a/src/generators/texto.js +++ b/src/generators/texto.js @@ -1,4 +1,4 @@ -import { palavras } from '../../data/db-general.js'; +import { palavras } from '../data/db-general.js'; /** * Gera uma palavra aleatória. diff --git a/index.js b/src/index.js similarity index 94% rename from index.js rename to src/index.js index 408cb65..8491dc9 100644 --- a/index.js +++ b/src/index.js @@ -1,28 +1,28 @@ -import * as utils from './src/utils.js'; -import { nome } from './src/generators/nome.js'; -import { banco, listaCodigosBancos } from './src/generators/banco.js'; -import { cartaoCredito } from './src/generators/cartao-credito.js'; -import { contaBancaria } from './src/generators/conta-bancaria.js'; -import { cnh } from './src/generators/cnh.js'; -import { cnpj } from './src/generators/cnpj.js'; -import { cpf } from './src/generators/cpf.js'; -import { rg } from './src/generators/rg.js'; -import { pis } from './src/generators/pis.js'; -import { cns } from './src/generators/cartao-nacional-saude.js'; -import { passaporte } from './src/generators/passaporte.js'; -import { tituloEleitor } from './src/generators/titulo-eleitor.js'; -import { dataNascimento } from './src/generators/data-nascimento.js'; -import { email } from './src/generators/email.js'; -import { celular } from './src/generators/celular.js'; -import { telefone } from './src/generators/telefone.js'; -import { cep } from './src/generators/cep.js'; -import { endereco } from './src/generators/endereco.js'; -import { placaAntiga, placaMercosul } from './src/generators/placa.js'; -import { renavam } from './src/generators/renavam.js'; -import { ddd } from './src/generators/ddd.js'; -import { codigoOperadora } from './src/generators/operadora.js'; -import { palavra, sentenca, paragrafo } from './src/generators/texto.js'; -import { inscricaoEstadual } from './src/generators/inscricao-estadual.js'; +import * as utils from './utils.js'; +import { nome } from './generators/nome.js'; +import { banco, listaCodigosBancos } from './generators/banco.js'; +import { cartaoCredito } from './generators/cartao-credito.js'; +import { contaBancaria } from './generators/conta-bancaria.js'; +import { cnh } from './generators/cnh.js'; +import { cnpj } from './generators/cnpj.js'; +import { cpf } from './generators/cpf.js'; +import { rg } from './generators/rg.js'; +import { pis } from './generators/pis.js'; +import { cns } from './generators/cartao-nacional-saude.js'; +import { passaporte } from './generators/passaporte.js'; +import { tituloEleitor } from './generators/titulo-eleitor.js'; +import { dataNascimento } from './generators/data-nascimento.js'; +import { email } from './generators/email.js'; +import { celular } from './generators/celular.js'; +import { telefone } from './generators/telefone.js'; +import { cep } from './generators/cep.js'; +import { endereco } from './generators/endereco.js'; +import { placaAntiga, placaMercosul } from './generators/placa.js'; +import { renavam } from './generators/renavam.js'; +import { ddd } from './generators/ddd.js'; +import { codigoOperadora } from './generators/operadora.js'; +import { palavra, sentenca, paragrafo } from './generators/texto.js'; +import { inscricaoEstadual } from './generators/inscricao-estadual.js'; function apelido() { return utils.apelidoRand; @@ -729,7 +729,7 @@ gerar.paragrafo = paragrafo; */ gerar.inscricaoEstadual = inscricaoEstadual; -export default { +export { gerar, nome, banco, diff --git a/index-teste.js b/src/teste.js similarity index 99% rename from index-teste.js rename to src/teste.js index b243aa4..9a95eda 100644 --- a/index-teste.js +++ b/src/teste.js @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import gerar from './index.js'; +import {gerar} from './index.js'; /* ******************** DOCUMENTOS ********************** */ // Gera CNH aleatória diff --git a/src/utils.js b/src/utils.js index 2819330..80fea63 100644 --- a/src/utils.js +++ b/src/utils.js @@ -17,7 +17,7 @@ import { categoriasCnh, escolaridade, profissao, -} from '../data/db-general.js'; +} from './data/db-general.js'; /** * Retorna um elemento aleatório de um array. diff --git a/test/utils.test.js b/test/utils.test.js index 585e3cc..626d11e 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -1,7 +1,7 @@ import { describe, test } from 'node:test'; import { strictEqual, ok } from 'node:assert'; import * as utils from '../src/utils.js'; -import * as db from '../data/db-general.js'; +import * as db from '../src/data/db-general.js'; describe('Utils', () => { describe('getRandom', () => {