Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

br-validations

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

br-validations - npm Package Compare versions

Comparing version 0.2.0 to 0.2.3

.travis.yml

2

bower.json
{
"name": "br-validations",
"version": "0.2.0",
"version": "0.2.2",
"description": "A library of validations applicable to several Brazilian data like I.E., CNPJ, CPF and others",

@@ -5,0 +5,0 @@ "homepage": "http://github.com/the-darc/br-validations",

@@ -88,4 +88,6 @@ var gulp = require('gulp'),

gulp.task('test', ['jshint', 'build', 'runtest'], function() {
gulp.task('test', ['jshint', 'build', 'runtest']);
gulp.task('test-watch', ['jshint', 'build', 'runtest'], function() {
gulp.watch(path.src.files, ['jshint', 'build', 'runtest']);
});
{
"name": "br-validations",
"version": "0.2.0",
"version": "0.2.3",
"description": "A library of validations applicable to several Brazilian data like I.E., CNPJ, CPF and others",

@@ -5,0 +5,0 @@ "id": "/br-validations",

@@ -0,1 +1,4 @@

[![NPM version](https://badge.fury.io/js/br-validations.svg)](http://badge.fury.io/js/br-validations)
[![Build Status](https://travis-ci.org/the-darc/br-validations.svg?branch=master)](https://travis-ci.org/the-darc/br-validations)
# br-validations #

@@ -36,3 +39,3 @@

See: [Conferência de Inscrições Estaduais](http://www.sintegra.gov.br/insc_est.html)
### CPF ###

@@ -39,0 +42,0 @@

/**
* br-validations
* A library of validations applicable to several Brazilian data like I.E., CNPJ, CPF and others
* @version v0.1.0
* @version v0.2.2
* @link http://github.com/the-darc/br-validations

@@ -14,6 +14,9 @@ * @license MIT

var b = [6,5,4,3,2,9,8,7,6,5,4,3,2];
c = c.replace(/[^\d]/g,'').split('');
if(c.length !== 14) {
c = c.replace(/[^\d]/g,'');
var r = /^(0{14}|1{14}|2{14}|3{14}|4{14}|5{14}|6{14}|7{14}|8{14}|9{14})$/;
if (!c || c.length !== 14 || r.test(c)) {
return false;
}
c = c.split('');

@@ -45,3 +48,4 @@ for (var i = 0, n = 0; i < 12; i++) {

cpf = cpf.replace(/[^\d]+/g,'');
if (cpf === '' || cpf === '00000000000' || cpf.length !== 11) {
var r = /^(0{11}|1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11})$/;
if (!cpf || cpf.length !== 11 || r.test(cpf)) {
return false;

@@ -120,7 +124,7 @@ }

var sum = this.normalSum(handledStr, pesos);
var ref = parseInt(handledStr.join(''));
if (ref >= 030000010 && ref <= 030170009) {
var ref = handledStr.join('');
if (ref >= '030000010' && ref <= '030170009') {
return sum + 5;
}
if (ref >= 030170010 && ref <= 030190229) {
if (ref >= '030170010' && ref <= '030190229') {
return sum + 9;

@@ -156,5 +160,5 @@ }

goSpec: function(rest, handledStr) {
var ref = parseInt(handledStr.join(''));
var ref = handledStr.join('');
if (rest === 1) {
return ref >= 101031050 && ref <= 101199979 ? 1 : 0;
return ref >= '101031050' && ref <= '101199979' ? 1 : 0;
}

@@ -164,5 +168,5 @@ return rest === 0 ? 0 : 11 - rest;

apSpec: function(rest, handledStr) {
var ref = parseInt(handledStr.join(''));
var ref = handledStr.join('');
if (rest === 0) {
return ref >= 030170010 && ref <= 030190229 ? 1 : 0;
return ref >= '030170010' && ref <= '030190229' ? 1 : 0;
}

@@ -187,3 +191,3 @@ return rest === 1 ? 0 : 11 - rest;

var steps = options.algorithmSteps;
// Step 01: Handle String

@@ -234,3 +238,3 @@ var handledStr = algorithmSteps.handleStr[steps[0]](value);

validate: function(value) { return validateIE(value, this); }
},{
},{
// mask: new StringMask('00.0.000.0000000-0'),

@@ -237,0 +241,0 @@ chars: 14,

@@ -1,1 +0,1 @@

(function(){function s(s,t){var o=t.algorithmSteps,r=u.handleStr[o[0]](s),e=u.sum[o[1]](r,t.pesos),n=u.rest[o[2]](e),m=parseInt(r[t.dvpos]),a=u.expectedDV[o[3]](n,r);return m===a}function t(t,o){if(o.match&&!o.match.test(t))return!1;for(var r=0;r<o.dvs.length;r++)if(!s(t,o.dvs[r]))return!1;return!0}var o=this,r={};r.validate=function(s){var t=[6,5,4,3,2,9,8,7,6,5,4,3,2];if(s=s.replace(/[^\d]/g,"").split(""),14!==s.length)return!1;for(var o=0,r=0;12>o;o++)r+=s[o]*t[o+1];if(r=11-r%11,r=r>=10?0:r,parseInt(s[12])!==r)return!1;for(o=0,r=0;12>=o;o++)r+=s[o]*t[o];return r=11-r%11,r=r>=10?0:r,parseInt(s[13])!==r?!1:!0};var e={};e.validate=function(s){function t(t){for(var o=0,r=t-9,e=0;9>e;e++)o+=parseInt(s.charAt(e+r))*(e+1);return o%11%10===parseInt(s.charAt(t))}return s=s.replace(/[^\d]+/g,""),""===s||"00000000000"===s||11!==s.length?!1:t(9)&&t(10)};var n=function(s){return this instanceof n?(this.rules=m[s]||[],this.rule,n.prototype._defineRule=function(s){this.rule=void 0;for(var t=0;t<this.rules.length&&void 0===this.rule;t++){var o=s.replace(/[^\d]/g,""),r=this.rules[t];o.length!==r.chars||r.match&&!r.match.test(s)||(this.rule=r)}return!!this.rule},n.prototype.validate=function(s){return s&&this._defineRule(s)?this.rule.validate(s):!1},void 0):new n(s)},m={},u={handleStr:{onlyNumbers:function(s){return s.replace(/[^\d]/g,"").split("")},mgSpec:function(s){var t=s.replace(/[^\d]/g,"");return t=t.substr(0,3)+"0"+t.substr(3,t.length),t.split("")}},sum:{normalSum:function(s,t){for(var o=s,r=0,e=0;e<t.length;e++)r+=parseInt(o[e])*t[e];return r},individualSum:function(s,t){for(var o=s,r=0,e=0;e<t.length;e++){var n=parseInt(o[e])*t[e];r+=n%10+parseInt(n/10)}return r},apSpec:function(s,t){var o=this.normalSum(s,t),r=parseInt(s.join(""));return r>=6291464&&30170009>=r?o+5:r>=6352904&&30190229>=r?o+9:o}},rest:{mod11:function(s){return s%11},mod10:function(s){return s%10},mod9:function(s){return s%9}},expectedDV:{minusRestOf11:function(s){return 2>s?0:11-s},minusRestOf11v2:function(s){return 2>s?11-s-10:11-s},minusRestOf10:function(s){return 1>s?0:10-s},mod10:function(s){return s%10},goSpec:function(s,t){var o=parseInt(t.join(""));return 1===s?o>=101031050&&101199979>=o?1:0:0===s?0:11-s},apSpec:function(s,t){var o=parseInt(t.join(""));return 0===s?o>=6352904&&30190229>=o?1:0:1===s?0:11-s},voidFn:function(s){return s}}};m.PE=[{chars:9,dvs:[{dvpos:7,pesos:[8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}},{chars:14,pesos:[[1,2,3,4,5,9,8,7,6,5,4,3,2]],dvs:[{dvpos:13,pesos:[5,4,3,2,1,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11v2"]}],validate:function(s){return t(s,this)}}],m.RS=[{chars:10,dvs:[{dvpos:9,pesos:[2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.AC=[{chars:13,match:/^01/,dvs:[{dvpos:11,pesos:[4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:12,pesos:[5,4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.MG=[{chars:13,dvs:[{dvpos:12,pesos:[1,2,1,2,1,2,1,2,1,2,1,2],algorithmSteps:["mgSpec","individualSum","mod10","minusRestOf10"]},{dvpos:12,pesos:[3,2,11,10,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.SP=[{chars:12,match:/^[0-9]/,dvs:[{dvpos:8,pesos:[1,3,4,5,6,7,8,10],algorithmSteps:["onlyNumbers","normalSum","mod11","mod10"]},{dvpos:11,pesos:[3,2,10,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","mod10"]}],validate:function(s){return t(s,this)}},{chars:12,match:/^P/i,dvs:[{dvpos:8,pesos:[1,3,4,5,6,7,8,10],algorithmSteps:["onlyNumbers","normalSum","mod11","mod10"]}],validate:function(s){return t(s,this)}}],m.DF=[{chars:13,dvs:[{dvpos:11,pesos:[4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:12,pesos:[5,4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.ES=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.BA=[{chars:8,match:/^[0123458]/,dvs:[{dvpos:7,pesos:[7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod10","minusRestOf10"]},{dvpos:6,pesos:[8,7,6,5,4,3,0,2],algorithmSteps:["onlyNumbers","normalSum","mod10","minusRestOf10"]}],validate:function(s){return t(s,this)}},{chars:8,match:/^[679]/,dvs:[{dvpos:7,pesos:[7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:6,pesos:[8,7,6,5,4,3,0,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}},{chars:9,match:/^[0-9][0123458]/,dvs:[{dvpos:8,pesos:[8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod10","minusRestOf10"]},{dvpos:7,pesos:[9,8,7,6,5,4,3,0,2],algorithmSteps:["onlyNumbers","normalSum","mod10","minusRestOf10"]}],validate:function(s){return t(s,this)}},{chars:9,match:/^[0-9][679]/,dvs:[{dvpos:8,pesos:[8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:7,pesos:[9,8,7,6,5,4,3,0,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.AM=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.RN=[{chars:9,match:/^20/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}},{chars:10,match:/^20/,dvs:[{dvpos:8,pesos:[10,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.RO=[{chars:14,dvs:[{dvpos:13,pesos:[6,5,4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.PR=[{chars:10,dvs:[{dvpos:8,pesos:[3,2,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:9,pesos:[4,3,2,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.SC=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.RJ=[{chars:8,dvs:[{dvpos:7,pesos:[2,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.PA=[{chars:9,match:/^15/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.SE=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.PB=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.CE=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.PI=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.MA=[{chars:9,match:/^12/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.MT=[{chars:11,dvs:[{dvpos:10,pesos:[3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.MS=[{chars:9,match:/^28/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.TO=[{chars:11,match:/^[0-9]{2}((0[123])|(99))/,dvs:[{dvpos:10,pesos:[9,8,0,0,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.AL=[{chars:9,match:/^24[03578]/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.RR=[{chars:9,match:/^24/,dvs:[{dvpos:8,pesos:[1,2,3,4,5,6,7,8],algorithmSteps:["onlyNumbers","normalSum","mod9","voidFn"]}],validate:function(s){return t(s,this)}}],m.GO=[{chars:9,match:/^1[015]/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","goSpec"]}],validate:function(s){return t(s,this)}}],m.AP=[{chars:9,match:/^03/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","apSpec","mod11","apSpec"]}],validate:function(s){return t(s,this)}}];var a={ie:n,cpf:e,cnpj:r},i={"function":!0,object:!0};i[typeof module]?module.exports=a:o.BrV=a}).call(this);
(function(){function s(s,t){var o=t.algorithmSteps,r=u.handleStr[o[0]](s),e=u.sum[o[1]](r,t.pesos),n=u.rest[o[2]](e),m=parseInt(r[t.dvpos]),a=u.expectedDV[o[3]](n,r);return m===a}function t(t,o){if(o.match&&!o.match.test(t))return!1;for(var r=0;r<o.dvs.length;r++)if(!s(t,o.dvs[r]))return!1;return!0}var o=this,r={};r.validate=function(s){var t=[6,5,4,3,2,9,8,7,6,5,4,3,2];s=s.replace(/[^\d]/g,"");var o=/^(0{14}|1{14}|2{14}|3{14}|4{14}|5{14}|6{14}|7{14}|8{14}|9{14})$/;if(!s||14!==s.length||o.test(s))return!1;s=s.split("");for(var r=0,e=0;12>r;r++)e+=s[r]*t[r+1];if(e=11-e%11,e=e>=10?0:e,parseInt(s[12])!==e)return!1;for(r=0,e=0;12>=r;r++)e+=s[r]*t[r];return e=11-e%11,e=e>=10?0:e,parseInt(s[13])!==e?!1:!0};var e={};e.validate=function(s){function t(t){for(var o=0,r=t-9,e=0;9>e;e++)o+=parseInt(s.charAt(e+r))*(e+1);return o%11%10===parseInt(s.charAt(t))}s=s.replace(/[^\d]+/g,"");var o=/^(0{11}|1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11})$/;return!s||11!==s.length||o.test(s)?!1:t(9)&&t(10)};var n=function(s){return this instanceof n?(this.rules=m[s]||[],this.rule,n.prototype._defineRule=function(s){this.rule=void 0;for(var t=0;t<this.rules.length&&void 0===this.rule;t++){var o=s.replace(/[^\d]/g,""),r=this.rules[t];o.length!==r.chars||r.match&&!r.match.test(s)||(this.rule=r)}return!!this.rule},n.prototype.validate=function(s){return s&&this._defineRule(s)?this.rule.validate(s):!1},void 0):new n(s)},m={},u={handleStr:{onlyNumbers:function(s){return s.replace(/[^\d]/g,"").split("")},mgSpec:function(s){var t=s.replace(/[^\d]/g,"");return t=t.substr(0,3)+"0"+t.substr(3,t.length),t.split("")}},sum:{normalSum:function(s,t){for(var o=s,r=0,e=0;e<t.length;e++)r+=parseInt(o[e])*t[e];return r},individualSum:function(s,t){for(var o=s,r=0,e=0;e<t.length;e++){var n=parseInt(o[e])*t[e];r+=n%10+parseInt(n/10)}return r},apSpec:function(s,t){var o=this.normalSum(s,t),r=s.join("");return r>="030000010"&&"030170009">=r?o+5:r>="030170010"&&"030190229">=r?o+9:o}},rest:{mod11:function(s){return s%11},mod10:function(s){return s%10},mod9:function(s){return s%9}},expectedDV:{minusRestOf11:function(s){return 2>s?0:11-s},minusRestOf11v2:function(s){return 2>s?11-s-10:11-s},minusRestOf10:function(s){return 1>s?0:10-s},mod10:function(s){return s%10},goSpec:function(s,t){var o=t.join("");return 1===s?o>="101031050"&&"101199979">=o?1:0:0===s?0:11-s},apSpec:function(s,t){var o=t.join("");return 0===s?o>="030170010"&&"030190229">=o?1:0:1===s?0:11-s},voidFn:function(s){return s}}};m.PE=[{chars:9,dvs:[{dvpos:7,pesos:[8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}},{chars:14,pesos:[[1,2,3,4,5,9,8,7,6,5,4,3,2]],dvs:[{dvpos:13,pesos:[5,4,3,2,1,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11v2"]}],validate:function(s){return t(s,this)}}],m.RS=[{chars:10,dvs:[{dvpos:9,pesos:[2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.AC=[{chars:13,match:/^01/,dvs:[{dvpos:11,pesos:[4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:12,pesos:[5,4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.MG=[{chars:13,dvs:[{dvpos:12,pesos:[1,2,1,2,1,2,1,2,1,2,1,2],algorithmSteps:["mgSpec","individualSum","mod10","minusRestOf10"]},{dvpos:12,pesos:[3,2,11,10,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.SP=[{chars:12,match:/^[0-9]/,dvs:[{dvpos:8,pesos:[1,3,4,5,6,7,8,10],algorithmSteps:["onlyNumbers","normalSum","mod11","mod10"]},{dvpos:11,pesos:[3,2,10,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","mod10"]}],validate:function(s){return t(s,this)}},{chars:12,match:/^P/i,dvs:[{dvpos:8,pesos:[1,3,4,5,6,7,8,10],algorithmSteps:["onlyNumbers","normalSum","mod11","mod10"]}],validate:function(s){return t(s,this)}}],m.DF=[{chars:13,dvs:[{dvpos:11,pesos:[4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:12,pesos:[5,4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.ES=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.BA=[{chars:8,match:/^[0123458]/,dvs:[{dvpos:7,pesos:[7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod10","minusRestOf10"]},{dvpos:6,pesos:[8,7,6,5,4,3,0,2],algorithmSteps:["onlyNumbers","normalSum","mod10","minusRestOf10"]}],validate:function(s){return t(s,this)}},{chars:8,match:/^[679]/,dvs:[{dvpos:7,pesos:[7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:6,pesos:[8,7,6,5,4,3,0,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}},{chars:9,match:/^[0-9][0123458]/,dvs:[{dvpos:8,pesos:[8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod10","minusRestOf10"]},{dvpos:7,pesos:[9,8,7,6,5,4,3,0,2],algorithmSteps:["onlyNumbers","normalSum","mod10","minusRestOf10"]}],validate:function(s){return t(s,this)}},{chars:9,match:/^[0-9][679]/,dvs:[{dvpos:8,pesos:[8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:7,pesos:[9,8,7,6,5,4,3,0,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.AM=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.RN=[{chars:9,match:/^20/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}},{chars:10,match:/^20/,dvs:[{dvpos:8,pesos:[10,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.RO=[{chars:14,dvs:[{dvpos:13,pesos:[6,5,4,3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.PR=[{chars:10,dvs:[{dvpos:8,pesos:[3,2,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]},{dvpos:9,pesos:[4,3,2,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.SC=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.RJ=[{chars:8,dvs:[{dvpos:7,pesos:[2,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.PA=[{chars:9,match:/^15/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.SE=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.PB=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.CE=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.PI=[{chars:9,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.MA=[{chars:9,match:/^12/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.MT=[{chars:11,dvs:[{dvpos:10,pesos:[3,2,9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.MS=[{chars:9,match:/^28/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.TO=[{chars:11,match:/^[0-9]{2}((0[123])|(99))/,dvs:[{dvpos:10,pesos:[9,8,0,0,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.AL=[{chars:9,match:/^24[03578]/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","minusRestOf11"]}],validate:function(s){return t(s,this)}}],m.RR=[{chars:9,match:/^24/,dvs:[{dvpos:8,pesos:[1,2,3,4,5,6,7,8],algorithmSteps:["onlyNumbers","normalSum","mod9","voidFn"]}],validate:function(s){return t(s,this)}}],m.GO=[{chars:9,match:/^1[015]/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","normalSum","mod11","goSpec"]}],validate:function(s){return t(s,this)}}],m.AP=[{chars:9,match:/^03/,dvs:[{dvpos:8,pesos:[9,8,7,6,5,4,3,2],algorithmSteps:["onlyNumbers","apSpec","mod11","apSpec"]}],validate:function(s){return t(s,this)}}];var a={ie:n,cpf:e,cnpj:r},i={"function":!0,object:!0};i[typeof module]?module.exports=a:o.BrV=a}).call(this);

@@ -5,6 +5,9 @@ var CNPJ = {};

var b = [6,5,4,3,2,9,8,7,6,5,4,3,2];
c = c.replace(/[^\d]/g,'').split('');
if(c.length !== 14) {
c = c.replace(/[^\d]/g,'');
var r = /^(0{14}|1{14}|2{14}|3{14}|4{14}|5{14}|6{14}|7{14}|8{14}|9{14})$/;
if (!c || c.length !== 14 || r.test(c)) {
return false;
}
c = c.split('');

@@ -11,0 +14,0 @@ for (var i = 0, n = 0; i < 12; i++) {

@@ -6,3 +6,4 @@

cpf = cpf.replace(/[^\d]+/g,'');
if (cpf === '' || cpf === '00000000000' || cpf.length !== 11) {
var r = /^(0{11}|1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11})$/;
if (!cpf || cpf.length !== 11 || r.test(cpf)) {
return false;

@@ -9,0 +10,0 @@ }

@@ -34,7 +34,7 @@ var IErules = {};

var sum = this.normalSum(handledStr, pesos);
var ref = parseInt(handledStr.join(''));
if (ref >= 030000010 && ref <= 030170009) {
var ref = handledStr.join('');
if (ref >= '030000010' && ref <= '030170009') {
return sum + 5;
}
if (ref >= 030170010 && ref <= 030190229) {
if (ref >= '030170010' && ref <= '030190229') {
return sum + 9;

@@ -70,5 +70,5 @@ }

goSpec: function(rest, handledStr) {
var ref = parseInt(handledStr.join(''));
var ref = handledStr.join('');
if (rest === 1) {
return ref >= 101031050 && ref <= 101199979 ? 1 : 0;
return ref >= '101031050' && ref <= '101199979' ? 1 : 0;
}

@@ -78,5 +78,5 @@ return rest === 0 ? 0 : 11 - rest;

apSpec: function(rest, handledStr) {
var ref = parseInt(handledStr.join(''));
var ref = handledStr.join('');
if (rest === 0) {
return ref >= 030170010 && ref <= 030190229 ? 1 : 0;
return ref >= '030170010' && ref <= '030190229' ? 1 : 0;
}

@@ -101,3 +101,3 @@ return rest === 1 ? 0 : 11 - rest;

var steps = options.algorithmSteps;
// Step 01: Handle String

@@ -148,3 +148,3 @@ var handledStr = algorithmSteps.handleStr[steps[0]](value);

validate: function(value) { return validateIE(value, this); }
},{
},{
// mask: new StringMask('00.0.000.0000000-0'),

@@ -151,0 +151,0 @@ chars: 14,

@@ -26,3 +26,11 @@ var should = require('should'),

});
it('should not validate equal numbers sequence', function(done) {
var template = '##.###.###/####-##';
for (var i = 0; i < 10; i++) {
var cnpj = template.replace(/#/g,i);
should(BrV.cnpj.validate(cnpj)).be.false;
}
done();
});
});
});

@@ -26,3 +26,11 @@ var should = require('should'),

});
it('should not validate equal numbers sequence', function(done) {
var template = '###.###.###-##';
for (var i = 0; i < 10; i++) {
var cpf = template.replace(/#/g,i);
should(BrV.cpf.validate(cpf)).be.false;
}
done();
});
});
});

@@ -241,12 +241,12 @@ var should = require('should'),

var uf = 'AM';
it('should validate 99999999-0', function(done) {
should(BrV.ie(uf).validate('99999999-0')).be.true;
it('should validate 99.999.999-0', function(done) {
should(BrV.ie(uf).validate('99.999.999-0')).be.true;
done();
});
it('should validate 19871230-8', function(done) {
should(BrV.ie(uf).validate('19871230-8')).be.true;
it('should validate 19.871.230-8', function(done) {
should(BrV.ie(uf).validate('19.871.230-8')).be.true;
done();
});
it('should invalidate 99912999-0', function(done) {
should(BrV.ie(uf).validate('99912999-0')).be.false;
it('should invalidate 99.912.999-0', function(done) {
should(BrV.ie(uf).validate('99.912.999-0')).be.false;
done();

@@ -253,0 +253,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc