Skip to content

Commit

Permalink
#2
Browse files Browse the repository at this point in the history
  • Loading branch information
mariohmol committed Nov 18, 2019
1 parent c14f3e0 commit 550ab3b
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 137 deletions.
2 changes: 1 addition & 1 deletion addons/pessoas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const TELEFONE_ESTADO = {
ma: 98, mt: 65, ms: 84, mg: 31, pr: 41, pb: 83, pa: 91, pe: 81, pi: 86, rj: 21, rn: 84, rs: 51, ro: 69,
rr: 95, sc: 48, se: 79, sp: 11, to: 63
}
// 154871-843

export const CEP_ESTADO = {
ac: [[69900000, 69999999]],
al: [[57000000, 57999999]],
Expand Down
102 changes: 58 additions & 44 deletions src/create.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { modulo11, getAllDigits, rand } from "./utils";
import { modulo11, getAllDigits, rand, fillString } from "./utils";

/**
*
* @param uf - UF do número da guia. Ex: 35(SP), 81(PE)
* @param ano - ANO do número da guia. Ex: 2018, 2019
* @param tipo - TIPO da guia. Aih = 1, APAC = 2
*/
export function create_aih(value){
export function create_aih(value) {
value = getAllDigits(value.toString());
if(value.length > 12){
value = value.toString().substr(0, value.length-1);
if (value.length > 12) {
value = value.toString().substr(0, value.length - 1);
}
const cod = parseInt(value);
const calc = Math.ceil(cod - (cod / 11));
Expand Down Expand Up @@ -199,24 +199,24 @@ export function create_cartaocredito(number) {
number = "00000000000000000" + number;
number = number.slice(number.length - 18);

let ccredDig1 = number.slice(17); let b1 = eval(ccredDig1);
let ccredDig2 = number.slice(16, 17); let b2 = eval(ccredDig2);
let ccredDig3 = number.slice(15, 16); let b3 = eval(ccredDig3);
let ccredDig4 = number.slice(14, 15); let b4 = eval(ccredDig4);
let ccredDig5 = number.slice(13, 14); let b5 = eval(ccredDig5);
let ccredDig6 = number.slice(12, 13); let b6 = eval(ccredDig6);
let ccredDig7 = number.slice(11, 12); let b7 = eval(ccredDig7);
let ccredDig8 = number.slice(10, 11); let b8 = eval(ccredDig8);
let ccredDig9 = number.slice(9, 10); let b9 = eval(ccredDig9);
let ccredDig10 = number.slice(8, 9); let b10 = eval(ccredDig10);
let ccredDig11 = number.slice(7, 8); let b11 = eval(ccredDig11);
let ccredDig12 = number.slice(6, 7); let b12 = eval(ccredDig12);
let ccredDig13 = number.slice(5, 6); let b13 = eval(ccredDig13);
let ccredDig14 = number.slice(4, 5); let b14 = eval(ccredDig14);
let ccredDig15 = number.slice(3, 4); let b15 = eval(ccredDig15);
let ccredDig16 = number.slice(2, 3); let b16 = eval(ccredDig16);
let ccredDig17 = number.slice(1, 2); let b17 = eval(ccredDig17);
let ccredDig18 = number.slice(0, 1); let b18 = eval(ccredDig18);
let b1 = parseInt(number.slice(17));
let b2 = parseInt(number.slice(16, 17));
let b3 = parseInt(number.slice(15, 16));
let b4 = parseInt(number.slice(14, 15));
let b5 = parseInt(number.slice(13, 14));
let b6 = parseInt(number.slice(12, 13));
let b7 = parseInt(number.slice(11, 12));
let b8 = parseInt(number.slice(10, 11));
let b9 = parseInt(number.slice(9, 10));
let b10 = parseInt(number.slice(8, 9));
let b11 = parseInt(number.slice(7, 8));
let b12 = parseInt(number.slice(6, 7));
let b13 = parseInt(number.slice(5, 6));
let b14 = parseInt(number.slice(4, 5));
let b15 = parseInt(number.slice(3, 4));
let b16 = parseInt(number.slice(2, 3));
let b17 = parseInt(number.slice(1, 2));
let b18 = parseInt(number.slice(0, 1));


let ci17 = b1 * 2; if (ci17 > 9) { ci17 = ci17 - 9; }
Expand Down Expand Up @@ -265,6 +265,21 @@ export function create_ect(number) {
return regEctDig;
}

export function create_pispasep(number: string) {

number = getAllDigits(number);
let nis = fillString(number, 11, '0');

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

const digit = (((10 * d) % 11) % 10);
return digit;
}

export function create_renavam(renavam: string) {
let dig1 = 0;
while (renavam.length < 11) {
Expand All @@ -291,32 +306,32 @@ export function create_renavam(renavam: string) {
* @param number
*/
export function create_processo(number) {

number = getAllDigits(number);
number = "00000000000000000" + number;
number = number.slice(number.length - 18);

let procDig1 = number.slice(0, 1); let b1 = eval(procDig1); b1 = b1 * 10000000000;
let procDig2 = number.slice(1, 2); let b2 = eval(procDig2); b2 = b2 * 1000000000;
let procDig3 = number.slice(2, 3); let b3 = eval(procDig3); b3 = b3 * 100000000;
let procDig4 = number.slice(3, 4); let b4 = eval(procDig4); b4 = b4 * 10000000;
let procDig5 = number.slice(4, 5); let b5 = eval(procDig5); b5 = b5 * 1000000;
let procDig6 = number.slice(5, 6); let b6 = eval(procDig6); b6 = b6 * 100000;
let procDig7 = number.slice(6, 7); let b7 = eval(procDig7); b7 = b7 * 10000;
let procDig8 = number.slice(7, 8); let b8 = eval(procDig8); b8 = b8 * 1000;
let procDig9 = number.slice(8, 9); let b9 = eval(procDig9); b9 = b9 * 100;
let procDig10 = number.slice(9, 10); let b10 = eval(procDig10); b10 = b10 * 10;
let procDig11 = number.slice(10, 11); let b11 = eval(procDig11);
let b1 = parseInt(number.slice(0, 1)) * 10000000000;
let b2 = parseInt(number.slice(1, 2)) * 1000000000;
let b3 = parseInt(number.slice(2, 3)) * 100000000;
let b4 = parseInt(number.slice(3, 4)) * 10000000;
let b5 = parseInt(number.slice(4, 5)) * 1000000;
let b6 = parseInt(number.slice(5, 6)) * 100000;
let b7 = parseInt(number.slice(6, 7)) * 10000;
let b8 = parseInt(number.slice(7, 8)) * 1000;
let b9 = parseInt(number.slice(8, 9)) * 100;
let b10 = parseInt(number.slice(9, 10)) * 10;
let b11 = parseInt(number.slice(10, 11));

const proc1a11 = b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9 + b10 + b11;
const resto1 = proc1a11 % 97;

let procDig12 = number.slice(11, 12); let b12 = eval(procDig12); b12 = b12 * 1000000;
let procDig13 = number.slice(12, 13); let b13 = eval(procDig13); b13 = b13 * 100000;
let procDig14 = number.slice(13, 14); let b14 = eval(procDig14); b14 = b14 * 10000;
let procDig15 = number.slice(14, 15); let b15 = eval(procDig15); b15 = b15 * 1000;
let procDig16 = number.slice(15, 16); let b16 = eval(procDig16); b16 = b16 * 100;
let procDig17 = number.slice(16, 17); let b17 = eval(procDig17); b17 = b17 * 10;
let procDig18 = number.slice(17); let b18 = eval(procDig18);
let b12 = parseInt(number.slice(11, 12)) * 1000000;
let b13 = parseInt(number.slice(12, 13)) * 100000;
let b14 = parseInt(number.slice(13, 14)) * 10000;
let b15 = parseInt(number.slice(14, 15)) * 1000;
let b16 = parseInt(number.slice(15, 16)) * 100;
let b17 = parseInt(number.slice(16, 17)) * 10;
let b18 = parseInt(number.slice(17));

const proc12a18 = b12 + b13 + b14 + b15 + b16 + b17 + b18;
const resto2 = (resto1 * 10000000 * 100 + proc12a18 * 100) % 97;
Expand All @@ -330,7 +345,8 @@ export function create_processo(number) {
let procJudCompl = b1 / 10000 + b2 / 10000 + b3 / 10000 + b4 / 10000 + b5 / 10000 + b6 / 10000 + b7 / 10000 + "-" + procJudDV + "." + b8 / 1000 + b9 / 100 + b10 / 10 + b11 + "." + b12 / 1000000 + "." + b13 / 100000 + b14 / 10000 + "." + b15 / 1000 + b16 / 100 + b17 / 10 + b18;

procJudCompl = "000000" + procJudCompl;
return procJudCompl.slice(procJudCompl.length - 25);
const result = procJudCompl.slice(procJudCompl.length - 25);
return result;
}


Expand Down Expand Up @@ -379,8 +395,6 @@ export function create_titulo_atual(titulo: string) {
return dig1.toString() + dig2.toString();
}



export function create_titulo(titNum) {
titNum = getAllDigits(titNum);

Expand Down
10 changes: 8 additions & 2 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { validate_placa } from './placa';
import { generateInscricaoEstadual } from './inscricaoestadual';
import {
create_cpf, create_cnpj, create_titulo, create_renavam, create_cnh,
create_cns, create_ect, create_certidao, create_aih
create_cns, create_ect, create_certidao, create_aih, create_pispasep
} from './create';
import { getAllDigits, randArray, CORES, randomLetterOrNumber, randomLetter, rand, randomNumber, randomEstadoSigla, slugify } from './utils';
import { VEICULOS, VEICULOS_CARROCERIAS, VEICULOS_CATEGORIAS, VEICULOS_TIPOS, VEICULOS_COMBUSTIVEIS, VEICULOS_ESPECIES, VEICULOS_RESTRICOES } from './veiculos';
Expand Down Expand Up @@ -328,7 +328,13 @@ export const fakerBr = {
}

},
pispasep: makeGeneric(MASKS['pispasep']),
pispasep: () => {
let pis = makeGeneric(MASKS['pispasep'])();
const digit = create_pispasep(pis);
const values = pis.split('');
values[values.length - 1] = digit;
return values;
},
placa: () => {
let placa: any;
do {
Expand Down
42 changes: 21 additions & 21 deletions src/iptu.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export function iptu_ctba(number) {
// if (number.length != 11) { alert("Você deve introduzir os ONZE dígitos-base \ndo IPTU, inclusive zeros à esquerda."); }

let iptuctbaDig1 = number.slice(10); let a1 = eval(iptuctbaDig1);
let iptuctbaDig2 = number.slice(9, 10); let a2 = eval(iptuctbaDig2);
let iptuctbaDig3 = number.slice(8, 9); let a3 = eval(iptuctbaDig3);
let iptuctbaDig4 = number.slice(7, 8); let a4 = eval(iptuctbaDig4);
let iptuctbaDig5 = number.slice(6, 7); let a5 = eval(iptuctbaDig5);
let iptuctbaDig6 = number.slice(5, 6); let a6 = eval(iptuctbaDig6);
let iptuctbaDig7 = number.slice(4, 5); let a7 = eval(iptuctbaDig7);
let iptuctbaDig8 = number.slice(3, 4); let a8 = eval(iptuctbaDig8);
let iptuctbaDig9 = number.slice(2, 3); let a9 = eval(iptuctbaDig9);
let iptuctbaDig10 = number.slice(1, 2); let a10 = eval(iptuctbaDig10);
let iptuctbaDig11 = number.slice(0, 1); let a11 = eval(iptuctbaDig11);
let a1 = parseInt(number.slice(10));
let a2 = parseInt(number.slice(9, 10));
let a3 = parseInt(number.slice(8, 9));
let a4 = parseInt(number.slice(7, 8));
let a5 = parseInt(number.slice(6, 7));
let a6 = parseInt(number.slice(5, 6));
let a7 = parseInt(number.slice(4, 5));
let a8 = parseInt(number.slice(3, 4));
let a9 = parseInt(number.slice(2, 3));
let a10 = parseInt(number.slice(1, 2));
let a11 = parseInt(number.slice(0, 1));

let iptuctbaDV = 10 - ((a1 * 2 + a2 * 3 + a3 * 4 + a4 * 7 + a5 * 8 + a6 * 9 + a7 * 2 + a8 * 3 + a9 * 4 + a10 * 7 + a11 * 8) % 10);
if (iptuctbaDV == 10) { iptuctbaDV = 0; }
Expand All @@ -23,16 +23,16 @@ export function iptu_sp(number) {

// if (number.length != 10) { alert("Você deve introduzir os DEZ dígitos \ndo IPTU, inclusive zeros à esquerda."); }

let iptuspDig1 = number.slice(9); let a1 = eval(iptuspDig1);
let iptuspDig2 = number.slice(8, 9); let a2 = eval(iptuspDig2);
let iptuspDig3 = number.slice(7, 8); let a3 = eval(iptuspDig3);
let iptuspDig4 = number.slice(6, 7); let a4 = eval(iptuspDig4);
let iptuspDig5 = number.slice(5, 6); let a5 = eval(iptuspDig5);
let iptuspDig6 = number.slice(4, 5); let a6 = eval(iptuspDig6);
let iptuspDig7 = number.slice(3, 4); let a7 = eval(iptuspDig7);
let iptuspDig8 = number.slice(2, 3); let a8 = eval(iptuspDig8);
let iptuspDig9 = number.slice(1, 2); let a9 = eval(iptuspDig9);
let iptuspDig10 = number.slice(0, 1); let a10 = eval(iptuspDig10);
let a1 = parseInt(number.slice(9));
let a2 = parseInt(number.slice(8, 9));
let a3 = parseInt(number.slice(7, 8));
let a4 = parseInt(number.slice(6, 7));
let a5 = parseInt(number.slice(5, 6));
let a6 = parseInt(number.slice(4, 5));
let a7 = parseInt(number.slice(3, 4));
let a8 = parseInt(number.slice(2, 3));
let a9 = parseInt(number.slice(1, 2));
let a10 =parseInt( number.slice(0, 1));

let iptuspDV = (a1 * 9 + a2 * 8 + a3 * 7 + a4 * 6 + a5 * 5 + a6 * 4 + a7 * 3 + a8 * 2 + a9 + a10 * 10) % 11;
if (iptuspDV == 10) { iptuspDV = 1; }
Expand Down
8 changes: 4 additions & 4 deletions src/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const MASKS = {
allowDecimal: true,
integerLimit: 15,
prefix: '',
suffix: '%'
// suffix: '%'
})
},
pispasep: {
Expand Down Expand Up @@ -205,7 +205,7 @@ const makeGeneric = (key: string) => {
}

export const maskBr = {
aih: makeGeneric('aih'),
aih: makeGeneric('aih'),
celular: makeGeneric('celular'),
cep: makeGeneric('cep'),
certidao: makeGeneric('certidao'),
Expand Down Expand Up @@ -287,13 +287,13 @@ export const maskBr = {
}
const vals = porcentagemValue.split(',');
const mask = MASKS.porcentagem.textMask(vals[0]);
const decimals = vals.length > 1 ? vals[1] : '00';
const decimals = vals.length > 1 ? ',' + vals[1] : '';

return conformToMask(
porcentagemValue,
mask,
{ guide: false }
).conformedValue + ',' + decimals;
).conformedValue + decimals + '%';
},
pispasep: makeGeneric('pispasep'),
placa: makeGeneric('placa'),
Expand Down
32 changes: 16 additions & 16 deletions src/rg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export function rg_sp(number) {
number = "0000000" + number;
number = number.slice(number.length - 8);

let cispDig1 = number.slice(7); let b1 = eval(cispDig1);
let cispDig2 = number.slice(6, 7); let b2 = eval(cispDig2);
let cispDig3 = number.slice(5, 6); let b3 = eval(cispDig3);
let cispDig4 = number.slice(4, 5); let b4 = eval(cispDig4);
let cispDig5 = number.slice(3, 4); let b5 = eval(cispDig5);
let cispDig6 = number.slice(2, 3); let b6 = eval(cispDig6);
let cispDig7 = number.slice(1, 2); let b7 = eval(cispDig7);
let cispDig8 = number.slice(0, 1); let b8 = eval(cispDig8);
let b1 = parseInt(number.slice(7));
let b2 = parseInt(number.slice(6, 7));
let b3 = parseInt(number.slice(5, 6));
let b4 = parseInt(number.slice(4, 5));
let b5 = parseInt(number.slice(3, 4));
let b6 = parseInt(number.slice(2, 3));
let b7 = parseInt(number.slice(1, 2));
let b8 = parseInt(number.slice(0, 1));

let cispDig: any = (b1 * 2 + b2 * 3 + b3 * 4 + b4 * 5 + b5 * 6 + b6 * 7 + b7 * 8 + b8 * 9) % 11;
if (cispDig == 10) {
Expand All @@ -31,14 +31,14 @@ export function rg_rj(number) {
number = "0000000" + number;
number = number.slice(number.length - 8);

let cirjDig1 = number.slice(7); let b1 = eval(cirjDig1);
let cirjDig2 = number.slice(6, 7); let b2 = eval(cirjDig2);
let cirjDig3 = number.slice(5, 6); let b3 = eval(cirjDig3);
let cirjDig4 = number.slice(4, 5); let b4 = eval(cirjDig4);
let cirjDig5 = number.slice(3, 4); let b5 = eval(cirjDig5);
let cirjDig6 = number.slice(2, 3); let b6 = eval(cirjDig6);
let cirjDig7 = number.slice(1, 2); let b7 = eval(cirjDig7);
let cirjDig8 = number.slice(0, 1); let b8 = eval(cirjDig8);
let b1 = parseInt(number.slice(7));
let b2 = parseInt(number.slice(6, 7));
let b3 = parseInt(number.slice(5, 6));
let b4 = parseInt(number.slice(4, 5));
let b5 = parseInt(number.slice(3, 4));
let b6 = parseInt(number.slice(2, 3));
let b7 = parseInt(number.slice(1, 2));
let b8 = parseInt(number.slice(0, 1));

let ci7 = b1 * 2; if (ci7 > 9) { ci7 = ci7 - 9; }
let ci56 = b3 * 2; if (ci56 > 9) { ci56 = ci56 - 9; }
Expand Down
Loading

0 comments on commit 550ab3b

Please sign in to comment.