@lacussoft/cpf-gen
Version:
Utility function to generate valid CPF (Brazilian personal ID)
92 lines (63 loc) • 3.45 kB
Markdown
# Lacus :: cpf-gen
[](https://npmjs.com/package/@lacussoft/cpf-gen)
[](https://bundlephobia.com/package/@lacussoft/cpf-gen)
[](https://npmjs.com/package/@lacussoft/cpf-gen)
[](https://github.com/LacusSolutions/br-utils-js/actions)
[](https://github.com/LacusSolutions/br-utils-js)
[](https://github.com/LacusSolutions/br-utils-js/blob/main/LICENSE)
Utility function to generate valid CPF (Brazilian personal ID).
## Browser Support
|  |  |  |  |  |  |
|--- | --- | --- | --- | --- | --- |
| Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
## Installation
```bash
# using NPM
$ npm install --save @lacussoft/cpf-gen
# using Bun
$ bun add @lacussoft/cpf-gen
```
## Import
```js
// ES Modules
import cpfGen from '@lacussoft/cpf-gen'
// Common JS
const cpfGen = require('@lacussoft/cpf-gen')
```
or import it through your HTML file, using CDN:
```html
<script src="https://cdn.jsdelivr.net/npm/@lacussoft/cpf-gen@latest/dist/cpf-gen.min.js"></script>
```
## Usage
```js
let cpf = cpfGen() // returns '47844241055'
cpf = cpfGen({ // returns '005.265.352-88'
format: true
})
cpf = cpfGen({ // returns '52825091138'
prefix: '528250911'
})
cpf = cpfGen({ // returns '528.250.911-38'
prefix: '528250911',
format: true
})
```
### Generator options
```js
cpfGen({
format: false, // indicates if output should be formatted
prefix: '' // if you have a CPF initials and want to complete it with valid digits.
}) // The string provided must contain between 0 and 9 digits!
```
## Contribution & Support
We welcome contributions! Please see our [Contributing Guidelines](./CONTRIBUTING.md) for details. But if you find this project helpful, please consider:
- ⭐ Starring the repository
- 🤝 Contributing to the codebase
- 💡 [Suggesting new features](https://github.com/LacusSolutions/br-utils-js/issues)
- 🐛 [Reporting bugs](https://github.com/LacusSolutions/br-utils-js/issues)
## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/LacusSolutions/br-utils-js/blob/main/LICENSE) file for details.
## Changelog
See [CHANGELOG](tps://github.com/LacusSolutions/br-utils-js/blob/main/CHANGELOG.md) for a list of changes and version history.
---
Made with ❤️ by [Lacus Solutions](https://github.com/LacusSolutions)