UNPKG

@teaploy/megaprint

Version:
19 lines (18 loc) 548 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function validateNit(nit) { if (nit.toUpperCase() === 'CF') { return true; } const nd = /^(\d+)-?([\dk])$/i.exec(nit); let add = 0; if (nd) { nd[2] = nd[2].toLowerCase() === 'k' ? 10 : parseInt(nd[2], 10); for (let i = 0; i < nd[1].length; i += 1) { add += ((i - nd[1].length) * -1 + 1) * nd[1][i]; } return (11 - (add % 11)) % 11 === nd[2]; } return false; } exports.default = validateNit;