@lacussoft/cnpj-fmt
v2.0.2
Published
Utility function to format CNPJ (Brazilian employer ID)
Maintainers
Readme

Utility function to format CNPJ (Brazilian employer ID).
Browser Support
|
|
|
|
|
|
|
|--- | --- | --- | --- | --- | --- |
| Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
Installation
# using NPM
$ npm install --save @lacussoft/cnpj-fmt
# using Bun
$ bun add @lacussoft/cnpj-fmtImport
// ES Modules
import cnpjFmt from '@lacussoft/cnpj-fmt'
// Common JS
const cnpjFmt = require('@lacussoft/cnpj-fmt')or import it through your HTML file, using CDN:
<script src="https://cdn.jsdelivr.net/npm/@lacussoft/cnpj-fmt@latest/dist/cnpj-fmt.min.js"></script>Usage
const cnpj = '03603568000195'
cnpjFmt(cnpj) // returns '03.603.568/0001-95'
cnpjFmt(cnpj, { // returns '03.603.***/****-**'
hidden: true
})
cnpjFmt(cnpj, { // returns '03603568|0001_95'
delimiters: {
dot: '',
slash: '|',
dash: '_'
}
})Formatting options
cnpjFmt(cnpj, {
delimiters: {
dot: '.', // string to replace the dot characters
slash: '/', // string to replace the slash character
dash: '-' // string to replace the dash character
},
escape: false, // boolean to define if the result should be HTML escaped
hidden: false, // boolean to define if digits should be hidden
hiddenKey: '*', // string to replace hidden digits
hiddenRange: {
start: 5, // starting index of the numeric sequence to be hidden (min 0)
end: 13 // ending index of the numeric sequence to be hidden (max 13)
},
onFail(value) { // fallback function to be invoked in case a non-14-digits is passed
return value
}
})Contribution & Support
We welcome contributions! Please see our Contributing Guidelines for details. But if you find this project helpful, please consider:
- ⭐ Starring the repository
- 🤝 Contributing to the codebase
- 💡 Suggesting new features
- 🐛 Reporting bugs
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG for a list of changes and version history.
Made with ❤️ by Lacus Solutions
