https://github.com/peralva/validate-cpf-cnpj
Validate CPF and CNPJ
https://github.com/peralva/validate-cpf-cnpj
cnpj cpf validate
Last synced: 5 months ago
JSON representation
Validate CPF and CNPJ
- Host: GitHub
- URL: https://github.com/peralva/validate-cpf-cnpj
- Owner: peralva
- License: mit
- Created: 2024-10-27T12:51:26.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-10-27T13:15:47.000Z (6 months ago)
- Last Synced: 2024-10-28T15:57:08.359Z (6 months ago)
- Topics: cnpj, cpf, validate
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@peralva/validate-cpf-cnpj
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @peralva/validate-cpf-cnpj
Validate CPF and CNPJ
[](https://www.npmjs.com/package/@peralva/validate-cpf-cnpj?activeTab=versions)
[](https://github.com/peralva/validate-cpf-cnpj/releases)
[](https://github.com/peralva/validate-cpf-cnpj?tab=MIT-1-ov-file#readme)
[](https://www.npmjs.com/package/@peralva/validate-cpf-cnpj)
[](https://github.com/peralva/validate-cpf-cnpj/actions/workflows/npm-publish.yml)## Installation
```bash
npm install @peralva/validate-cpf-cnpj
```## Usage
```ts
import { validateCpfCnpj } from '@peralva/validate-cpf-cnpj';const cpfCnpj = validateCpfCnpj('123 456 789 09');
console.log(cpfCnpj.parsed, cpfCnpj.masked);
try {
validateCpfCnpj('12 345 678 9012 34', (issue) => {
if (issue.type === 'digits') {
return `Issue Type: ${issue.type}\nIssue Expected: ${issue.expected}\nIssue Received: ${issue.received}\nData Parsed: ${issue.data.parsed}\nData Received: ${issue.data.received}\nData Masked: ${issue.data.masked}`;
}return issue.defaultError;
});
} catch (err) {
if (err instanceof CpfCnpjError) {
if (err.issue.type === 'digits') console.error(err.message);
}
}
```