1.1.2 • Published 9 months ago

@peralva/validate-cpf-cnpj v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@peralva/validate-cpf-cnpj

Validate CPF and CNPJ

NPM Version GitHub Release Date GitHub License NPM Downloads NPM Publish

Installation

npm install @peralva/validate-cpf-cnpj

Usage

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);
	}
}
1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.0

9 months ago