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

js-brasil

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-brasil - npm Package Compare versions

Comparing version 2.4.5 to 2.4.6

47

dist/src/create.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.create_titulo = exports.create_titulo_atual = exports.create_processo = exports.create_renavam = exports.create_pispasep = exports.create_ect = exports.create_cartaocredito = exports.create_cpf = exports.create_cns = exports.create_cnpj = exports.create_cnh_antigo = exports.create_cnh = exports.create_certidao = exports.create_aih = void 0;
exports.create_titulo = exports.create_titulo_atual = exports.create_processo = exports.create_renavam = exports.create_pispasep = exports.create_ect = exports.create_cartaocredito = exports.create_cpf = exports.create_cns = exports.create_cnpj = exports.create_cnh = exports.create_cnh_mod11 = exports.create_certidao = exports.create_aih = void 0;
var utils_1 = require("./utils");

@@ -74,22 +74,24 @@ /**

exports.create_certidao = create_certidao;
function create_cnh(cnh) {
var v = 0;
for (var i = 0, j = 9; i < 9; ++i, --j) {
v += +(parseInt(cnh.charAt(i)) * j);
/**
* TODO: Not working with mod11 function
* @param strCNH
* @returns
*/
function create_cnh_mod11(strCNH) {
strCNH = strCNH.replace(/[^\d]+/g, '');
if (strCNH === '00000000000') {
return false;
}
var dsc = 0, vl1 = v % 11;
if (vl1 >= 10) {
vl1 = 0;
dsc = 2;
}
for (var i = 0, j = 1, v_1 = 0; i < 9; ++i, ++j) {
v_1 += +(parseInt(cnh.charAt(i)) * j);
}
var x = v % 11;
var vl2 = (x >= 10) ? 0 : x - dsc;
return ('' + vl1 + vl2); // === cnh.substr(-2);
var v1 = utils_1.modulo11(strCNH, 9, 11);
var v2 = utils_1.modulo11(strCNH, 10, 11);
if (v1 < 1)
v1 = 0;
if (v2 < 1)
v2 = 0;
console.warn(strCNH, v1, v2);
return '' + v1 + v2;
}
exports.create_cnh = create_cnh;
function create_cnh_antigo(value) {
value = utils_1.getAllDigits(value);
exports.create_cnh_mod11 = create_cnh_mod11;
function create_cnh(value) {
value = value.replace(/[^\d]+/g, '');
if (value.length != 11 || value === '0') {

@@ -105,10 +107,7 @@ return false;

dv1 = (dv1 > 9 ? 0 : dv1);
if (parseInt(value[9]) !== dv1) {
return false;
}
var dv2 = s2 % 11 - (dv1 > 9 ? 2 : 0);
var check = dv2 < 0 ? dv2 + 11 : dv2 > 9 ? 0 : dv2;
return check;
return "" + dv1 + check;
}
exports.create_cnh_antigo = create_cnh_antigo;
exports.create_cnh = create_cnh;
function create_cnpj(cnpj) {

@@ -115,0 +114,0 @@ cnpj = cnpj.replace(/[^\d]+/g, '');

@@ -20,3 +20,3 @@ "use strict";

}
var cispDV = cispDig;
return cispDig;
}

@@ -23,0 +23,0 @@ exports.rg_sp = rg_sp;

@@ -71,3 +71,2 @@ "use strict";

var cepString = cep.toString();
var keys = Object.keys(exports.CEPRange);
var found;

@@ -138,5 +137,5 @@ for (var estado in exports.CEPRange) {

function validate_cnh(value) {
value = utils_1.getAllDigits(value);
value = value.replace(/[^\d]/g, '');
var char1 = value.charAt(0);
if (value.replace(/[^\d]/g, '').length !== 11 || char1.repeat(11) === value) {
if (value.length !== 11) {
return false;

@@ -143,0 +142,0 @@ }

@@ -54,6 +54,8 @@ "use strict";

chai_1.expect(index_1.validateBr.cnh('9973')).to.be.false;
chai_1.expect(index_1.validateBr.cnh('997395071-33')).to.be.true;
chai_1.expect(index_1.validateBr.cnh('99739507133')).to.be.true;
chai_1.expect(index_1.validateBr.cnh('997395071-31')).to.be.false;
chai_1.expect(index_1.validateBr.cnh('99739507131')).to.be.false;
chai_1.expect(index_1.validateBr.cnh('997395071-33')).to.be.false;
chai_1.expect(index_1.validateBr.cnh('99739507133')).to.be.false;
chai_1.expect(index_1.validateBr.cnh('99739507132')).to.be.true;
chai_1.expect(index_1.validateBr.cnh('59796888141')).to.be.true;
chai_1.expect(index_1.validateBr.cnh('07021871297')).to.be.true;
chai_1.expect(index_1.validateBr.cnh('07021871296')).to.be.false;
});

@@ -399,3 +401,3 @@ it('CNPJ', function () {

});
// it.only('PROCESSO', () => {
// it('PROCESSO', () => {
// // expect(validateBr.processo('0123456-15.2008.100.0000')).to.be.true;

@@ -402,0 +404,0 @@ // expect(validateBr.processo('000208-36.0201.2.51.50049')).to.be.true;

{
"name": "js-brasil",
"version": "2.4.5",
"version": "2.4.6",
"description": "Javascript Utils para Brasil (cpf, cnpj...)",

@@ -43,3 +43,4 @@ "main": "dist/index.js",

"codelyzer": "^5.2.0",
"mocha": "^5.2.0",
"mocha": "^8.3.2",
"onchange": "^7.1.0",
"ts-node": "^7.0.1",

@@ -46,0 +47,0 @@ "typescript": "~4.0.2"

@@ -67,30 +67,23 @@ import { modulo11, getAllDigits, fillString } from './utils';

export function create_cnh(cnh: string) {
let v = 0;
for (let i = 0, j = 9; i < 9; ++i, --j) {
v += +(parseInt(cnh.charAt(i)) * j);
/**
* TODO: Not working with mod11 function
* @param strCNH
* @returns
*/
export function create_cnh_mod11(strCNH: string) {
strCNH = strCNH.replace(/[^\d]+/g, '');
if (strCNH === '00000000000') {
return false;
}
let dsc = 0,
vl1 = v % 11;
if (vl1 >= 10) {
vl1 = 0;
dsc = 2;
}
for (let i = 0, j = 1, v = 0; i < 9; ++i, ++j) {
v += +(parseInt(cnh.charAt(i)) * j);
}
let x = v % 11;
let vl2 = (x >= 10) ? 0 : x - dsc;
return ('' + vl1 + vl2); // === cnh.substr(-2);
let v1 = modulo11(strCNH, 9, 11);
let v2 = modulo11(strCNH, 10, 11)
if (v1 < 1) v1 = 0;
if (v2 < 1) v2 = 0;
console.warn(strCNH, v1, v2)
return '' + v1+v2;
}
export function create_cnh_antigo(value: string) {
value = getAllDigits(value);
export function create_cnh(value: string) {
value = value.replace(/[^\d]+/g, '');
if (value.length != 11 || value === '0') {

@@ -100,3 +93,3 @@ return false;

let s1: number, s2: number;
for (let c = s1 = s2 = 0, p = 9; c < 9; c++ , p--) {
for (let c = s1 = s2 = 0, p = 9; c < 9; c++, p--) {
s1 += parseInt(value[c]) * p;

@@ -107,8 +100,6 @@ s2 += parseInt(value[c]) * (10 - p);

dv1 = (dv1 > 9 ? 0 : dv1);
if (parseInt(value[9]) !== dv1) {
return false;
}
let dv2 = s2 % 11 - (dv1 > 9 ? 2 : 0);
let check = dv2 < 0 ? dv2 + 11 : dv2 > 9 ? 0 : dv2;
return check;
return ""+dv1+check;
}

@@ -279,3 +270,3 @@

let p = 2, c = 9;
for (d = 0; c >= 0; c-- , (p < 9) ? p++ : p = 2) {
for (d = 0; c >= 0; c--, (p < 9) ? p++ : p = 2) {
d += parseInt(nis[c]) * p;

@@ -282,0 +273,0 @@ }

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

import { isArray, processCaretTraps, getSpecialProperty } from './utils';
import { isArray, processCaretTraps } from './utils';
import { BigObject, MaskType, MasksIE } from './interfaces';

@@ -3,0 +3,0 @@ export { MASKSIE } from './inscricaoestadual';

@@ -22,4 +22,4 @@ import { BigObject } from './interfaces';

}
let cispDV = cispDig;
return cispDig;
}

@@ -26,0 +26,0 @@

@@ -76,3 +76,2 @@ import { getAllDigits, fillString, getAllWords } from './utils';

const cepString: string = cep.toString();
const keys = Object.keys(CEPRange);
let found: any;

@@ -159,9 +158,8 @@ for (let estado in CEPRange) {

export function validate_cnh(value: string) {
value = getAllDigits(value);
value = value.replace(/[^\d]/g, '');
var char1 = value.charAt(0);
if (value.replace(/[^\d]/g, '').length !== 11 || char1.repeat(11) === value) {
if (value.length !== 11) {
return false;
}
const check = create_cnh(value);
return value.substr(-2) == check;

@@ -205,5 +203,5 @@ }

if(!restos ||
if (!restos ||
restos[0] !== parseInt(strCPF.substring(9, 10), 10) ||
restos[1] !== parseInt(strCPF.substring(10, 11), 10) ){
restos[1] !== parseInt(strCPF.substring(10, 11), 10)) {
return false;

@@ -526,3 +524,3 @@ }

export function validate_titulo(titulo: any) {
if(!titulo){
if (!titulo) {
return false;

@@ -529,0 +527,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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