{"id":20375580,"url":"https://github.com/juliolmuller/cnpj-utils-js","last_synced_at":"2025-08-11T17:13:03.405Z","repository":{"id":57126120,"uuid":"374857875","full_name":"juliolmuller/cnpj-utils-js","owner":"juliolmuller","description":"Straight forward JavaScript package to handle CNPJ data (Brazilian employer ID).","archived":false,"fork":false,"pushed_at":"2025-04-19T07:12:05.000Z","size":968,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-08T18:54:04.233Z","etag":null,"topics":["br","cnpj","format","formatter","generate","generator","javascript","node","npm","validate","validator"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cnpj-utils","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juliolmuller.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-06-08T02:32:07.000Z","updated_at":"2025-04-26T03:42:03.000Z","dependencies_parsed_at":"2025-04-19T06:34:16.854Z","dependency_job_id":"aad71b1b-37b4-410b-80c7-872c0a7ebaba","html_url":"https://github.com/juliolmuller/cnpj-utils-js","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/juliolmuller/cnpj-utils-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliolmuller%2Fcnpj-utils-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliolmuller%2Fcnpj-utils-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliolmuller%2Fcnpj-utils-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliolmuller%2Fcnpj-utils-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliolmuller","download_url":"https://codeload.github.com/juliolmuller/cnpj-utils-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliolmuller%2Fcnpj-utils-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269643709,"owners_count":24452421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["br","cnpj","format","formatter","generate","generator","javascript","node","npm","validate","validator"],"created_at":"2024-11-15T01:31:43.973Z","updated_at":"2025-08-11T17:13:03.396Z","avatar_url":"https://github.com/juliolmuller.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cnpj-utils for JavaScript\n\n![NPM Latest Version](https://img.shields.io/npm/v/cnpj-utils)\n![Bundle Size](https://img.shields.io/bundlephobia/min/cnpj-utils?label=bundle%20size)\n![Downloads Count](https://img.shields.io/npm/dm/cnpj-utils.svg)\n![Test Status](https://img.shields.io/github/actions/workflow/status/juliolmuller/cnpj-utils-js/ci.yml?label=ci/cd)\n![Last Update Date](https://img.shields.io/github/last-commit/juliolmuller/cnpj-utils-js)\n![Project License](https://img.shields.io/github/license/juliolmuller/cnpj-utils-js)\n\nToolkit to handle the main operations with CNPJ data (Brazilian corporate ID): validation, formatting and generation of valid character sequences.\n\n## Browser Support\n\n![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |\n--- | --- | --- | --- | --- | --- |\nLatest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |\n\n## Installation\n\n```bash\n# using NPM\n$ npm install --save cnpj-utils\n\n# using Bun\n$ bun add cnpj-utils\n```\n\n## Import\n\n```js\n// Common JS syntax:\nconst cnpjUtils = require('cnpj-utils')\n\n// ES Module syntax:\nimport cnpjUtils from 'cnpj-utils'\n// or get the specific function with ES tree-shaking:\nimport { isValid, generate, format } from 'cnpj-utils'\n```\n\nor import it through your HTML file, using CDN:\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/cnpj-utils@latest/dist/cnpj-utils.min.js\"\u003e\u003c/script\u003e\n```\n\n## API\n\n`cnpj-utils` is only a wrapper to the libraries maintained by **LacusSoft**, [`cnpj-fmt`](https://www.npmjs.com/package/@lacussoft/cnpj-fmt), [`cnpj-gen`](https://www.npmjs.com/package/@lacussoft/cnpj-gen) and [`cnpj-val`](https://www.npmjs.com/package/@lacussoft/cnpj-val), so you can refer directly to their specific documentation. Anyway, the API is detailed hereby with examples.\n\n### `cnpjUtils.format(string[, options])`\n\n**returns** `string`\n\nThe `format` method expects a string as its first parameter.\n\nIf the input does not contain 14 digits (it does not need to be a valid CNPJ, but it MUST be 14-digits long) an `onFail` callback is invoked. By default, a copy of the input is returned as a fallback, but this callback and other customizations may be defined in the second parameter.\n\n```js\nconst cnpj = '03603568000195'\n\ncnpjUtils.format(cnpj)     // returns '03.603.568/0001-95'\n\ncnpjUtils.format(cnpj, {   // returns '03.603.***/****-**'\n  hidden: true\n})\n\ncnpjUtils.format(cnpj, {   // returns '03603568|0001_95'\n  delimiters: {\n    dot: '',\n    slash: '|',\n    dash: '_'\n  }\n})\n```\n\nHere are the available default configurations that can be overwritten by the `options` parameter:\n\n```js\ncnpjUtils.format(cnpj, {\n  delimiters: {\n    dot: '.',       // string to replace the dot characters\n    slash: '/',     // string to replace the slash character\n    dash: '-'       // string to replace the dash character\n  },\n  escape: false,    // boolean to define if the result should be HTML escaped\n  hidden: false,    // boolean to define if digits should be hidden\n  hiddenKey: '*',   // string to replace hidden digits\n  hiddenRange: {\n    start: 5,       // starting index of the numeric sequence to be hidden (min 0)\n    end: 13         // ending index of the numeric sequence to be hidden (max 13)\n  },\n  onFail(value) {   // fallback function to be invoked in case a non-14-digits is passed\n    return value\n  }\n})\n```\n\n### `cnpjUtils.generate([options])`\n\n**returns** `string`\n\nIf you need to generate valid CNPJs, the `generate` method makes this task easy and safe. Invoke it without parameters to obtain a 14‑digit string. You can also provide an `options` object to configure its output, like flagging it to format or to complete a digits string with a valid CNPJ sequence:\n\n```js\nlet cnpj = cnpjUtils.generate()   // returns '65453043000178'\n\ncnpj = cnpjUtils.generate({       // returns '73.008.535/0005-06'\n  format: true\n})\n\ncnpj = cnpjUtils.generate({       // returns '45623767000296'\n  prefix: '45623767'\n})\n\ncnpj = cnpjUtils.generate({       // returns '45.623.767/0002-96'\n  prefix: '456237670002',\n  format: true\n})\n```\n\nThe default configurations are:\n\n```js\ncnpjUtils.generate({\n  format: false,    // indicates if output should be formatted\n  prefix: ''        // if you have a CNPJ initials and want to complete it with valid\n})                  //   digits. The string provided must contain between 1 and 12 digits!\n```\n\nKeep in mind that, for the `prefix` option, it must be a **string** containing up to 12 digits.\n\n### `cnpjUtils.isValid(string)`\n\n**returns** `boolean`\n\nThe `isValid` method receives a string as its single parameter, evaluates it and returns `true` or `false` as output. This parameter may contain any character like letters, symbols, punctuation or white spaces, but it will immediately return `false` in case the expected 14 digits are not found to be deeply evaluated.\n\n\n```js\ncnpjUtils.isValid('98765432000198')      // returns 'true'\n\ncnpjUtils.isValid('98.765.432/0001-98')  // returns 'true'\n\ncnpjUtils.isValid('98765432000199')      // returns 'false'\n                                ^^\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliolmuller%2Fcnpj-utils-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliolmuller%2Fcnpj-utils-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliolmuller%2Fcnpj-utils-js/lists"}