1.2.0 • Published 11 months ago

@peralva/validate-cpf-cnpj v1.2.0

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

@peralva/validate-cpf-cnpj

Validate CPF and CNPJ

NPM Version GitHub Release Date GitHub License NPM Downloads NPM Publish

Installation

npm install --save @peralva/validate-cpf-cnpj

Usage

import { CpfCnpjError, validateCpfCnpj } from '@peralva/validate-cpf-cnpj';

const cpfCnpj = validateCpfCnpj('123 456 789 09', { clearData: true });

console.log(cpfCnpj.parsed, cpfCnpj.masked);

try {
	validateCpfCnpj('12 345 678 9012 34', {
		errorMap(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.2.0

11 months ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago