UNPKG

@euk-labs/beltz

Version:

![npm](https://img.shields.io/npm/v/@euk-labs/beltz) ![NPM](https://img.shields.io/npm/l/@euk-labs/beltz) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Eureka-Shoulders/beltz/CI) ![npm](https://img.shields.io/npm/dw/@euk-labs/bel

23 lines 854 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateCPF = void 0; function validateCPF(cpf) { cpf = cpf.replace(/[^\d]+/g, ''); let arr = []; if (cpf.length !== 11 || !!cpf.match(/(\d)\1{10}/)) return false; arr = cpf.split(''); const validator = arr .filter((digit, index, array) => index >= array.length - 2 && digit) .map((el) => +el); const toValidate = (pop) => arr .filter((digit, index, array) => index < array.length - pop && digit) .map((el) => +el); const rest = (count, pop) => ((toValidate(pop).reduce((soma, el, i) => soma + el * (count - i), 0) * 10) % 11) % 10; return !(rest(10, 2) !== validator[0] || rest(11, 1) !== validator[1]); } exports.validateCPF = validateCPF; //# sourceMappingURL=cpf.js.map