validation-br 2.0.0-next-9 → 2.0.0-next-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/cjs/certidao.d.ts +111 -0
  2. package/dist/{certidao.js → cjs/certidao.js} +83 -38
  3. package/dist/cjs/package.json +3 -0
  4. package/dist/{uuid.js → cjs/uuid.js} +7 -4
  5. package/dist/esm/_exceptions/ValidationBRError.d.ts +24 -0
  6. package/dist/esm/_exceptions/ValidationBRError.js +40 -0
  7. package/dist/esm/_helpers/crc.d.ts +7 -0
  8. package/dist/esm/_helpers/crc.js +43 -0
  9. package/dist/esm/_helpers/crockford.d.ts +31 -0
  10. package/dist/esm/_helpers/crockford.js +58 -0
  11. package/dist/esm/_helpers/mask.d.ts +18 -0
  12. package/dist/esm/_helpers/mask.js +33 -0
  13. package/dist/esm/_helpers/random.d.ts +27 -0
  14. package/dist/esm/_helpers/random.js +50 -0
  15. package/dist/esm/_helpers/utils.d.ts +94 -0
  16. package/dist/esm/_helpers/utils.js +119 -0
  17. package/dist/esm/base.d.ts +33 -0
  18. package/dist/esm/base.js +45 -0
  19. package/dist/esm/carplate.d.ts +31 -0
  20. package/dist/esm/carplate.js +65 -0
  21. package/dist/esm/cbi_sinter.d.ts +78 -0
  22. package/dist/esm/cbi_sinter.js +119 -0
  23. package/dist/esm/cep.d.ts +61 -0
  24. package/dist/esm/cep.js +183 -0
  25. package/dist/esm/certidao.d.ts +111 -0
  26. package/dist/esm/certidao.js +170 -0
  27. package/dist/esm/cnh.d.ts +80 -0
  28. package/dist/esm/cnh.js +124 -0
  29. package/dist/esm/cnpj.d.ts +107 -0
  30. package/dist/esm/cnpj.js +170 -0
  31. package/dist/esm/cpf.d.ts +88 -0
  32. package/dist/esm/cpf.js +132 -0
  33. package/dist/esm/email.d.ts +12 -0
  34. package/dist/esm/email.js +36 -0
  35. package/dist/esm/index.d.ts +15 -0
  36. package/dist/esm/index.js +39 -0
  37. package/dist/esm/judicial-process.d.ts +150 -0
  38. package/dist/esm/judicial-process.js +253 -0
  39. package/dist/esm/nup17.d.ts +98 -0
  40. package/dist/esm/nup17.js +150 -0
  41. package/dist/esm/package.json +3 -0
  42. package/dist/esm/phone.d.ts +103 -0
  43. package/dist/esm/phone.js +165 -0
  44. package/dist/esm/pis-pasep.d.ts +70 -0
  45. package/dist/esm/pis-pasep.js +111 -0
  46. package/dist/esm/pix-copy-paste.d.ts +26 -0
  47. package/dist/esm/pix-copy-paste.js +78 -0
  48. package/dist/esm/pix-key.d.ts +29 -0
  49. package/dist/esm/pix-key.js +83 -0
  50. package/dist/esm/postal-track-code.d.ts +76 -0
  51. package/dist/esm/postal-track-code.js +125 -0
  52. package/dist/esm/renavam.d.ts +31 -0
  53. package/dist/esm/renavam.js +108 -0
  54. package/dist/esm/tituloEleitor.d.ts +82 -0
  55. package/dist/esm/tituloEleitor.js +129 -0
  56. package/dist/esm/uf.d.ts +89 -0
  57. package/dist/esm/uf.js +223 -0
  58. package/dist/esm/uuid.d.ts +9 -0
  59. package/dist/esm/uuid.js +29 -0
  60. package/package.json +138 -132
  61. package/readme.md +412 -160
  62. package/dist/certidao.d.ts +0 -83
  63. /package/dist/{_exceptions → cjs/_exceptions}/ValidationBRError.d.ts +0 -0
  64. /package/dist/{_exceptions → cjs/_exceptions}/ValidationBRError.js +0 -0
  65. /package/dist/{_helpers → cjs/_helpers}/crc.d.ts +0 -0
  66. /package/dist/{_helpers → cjs/_helpers}/crc.js +0 -0
  67. /package/dist/{_helpers → cjs/_helpers}/crockford.d.ts +0 -0
  68. /package/dist/{_helpers → cjs/_helpers}/crockford.js +0 -0
  69. /package/dist/{_helpers → cjs/_helpers}/mask.d.ts +0 -0
  70. /package/dist/{_helpers → cjs/_helpers}/mask.js +0 -0
  71. /package/dist/{_helpers → cjs/_helpers}/random.d.ts +0 -0
  72. /package/dist/{_helpers → cjs/_helpers}/random.js +0 -0
  73. /package/dist/{_helpers → cjs/_helpers}/utils.d.ts +0 -0
  74. /package/dist/{_helpers → cjs/_helpers}/utils.js +0 -0
  75. /package/dist/{base.d.ts → cjs/base.d.ts} +0 -0
  76. /package/dist/{base.js → cjs/base.js} +0 -0
  77. /package/dist/{carplate.d.ts → cjs/carplate.d.ts} +0 -0
  78. /package/dist/{carplate.js → cjs/carplate.js} +0 -0
  79. /package/dist/{cbi_sinter.d.ts → cjs/cbi_sinter.d.ts} +0 -0
  80. /package/dist/{cbi_sinter.js → cjs/cbi_sinter.js} +0 -0
  81. /package/dist/{cep.d.ts → cjs/cep.d.ts} +0 -0
  82. /package/dist/{cep.js → cjs/cep.js} +0 -0
  83. /package/dist/{cnh.d.ts → cjs/cnh.d.ts} +0 -0
  84. /package/dist/{cnh.js → cjs/cnh.js} +0 -0
  85. /package/dist/{cnpj.d.ts → cjs/cnpj.d.ts} +0 -0
  86. /package/dist/{cnpj.js → cjs/cnpj.js} +0 -0
  87. /package/dist/{cpf.d.ts → cjs/cpf.d.ts} +0 -0
  88. /package/dist/{cpf.js → cjs/cpf.js} +0 -0
  89. /package/dist/{email.d.ts → cjs/email.d.ts} +0 -0
  90. /package/dist/{email.js → cjs/email.js} +0 -0
  91. /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  92. /package/dist/{index.js → cjs/index.js} +0 -0
  93. /package/dist/{judicial-process.d.ts → cjs/judicial-process.d.ts} +0 -0
  94. /package/dist/{judicial-process.js → cjs/judicial-process.js} +0 -0
  95. /package/dist/{nup17.d.ts → cjs/nup17.d.ts} +0 -0
  96. /package/dist/{nup17.js → cjs/nup17.js} +0 -0
  97. /package/dist/{phone.d.ts → cjs/phone.d.ts} +0 -0
  98. /package/dist/{phone.js → cjs/phone.js} +0 -0
  99. /package/dist/{pis-pasep.d.ts → cjs/pis-pasep.d.ts} +0 -0
  100. /package/dist/{pis-pasep.js → cjs/pis-pasep.js} +0 -0
  101. /package/dist/{pix-copy-paste.d.ts → cjs/pix-copy-paste.d.ts} +0 -0
  102. /package/dist/{pix-copy-paste.js → cjs/pix-copy-paste.js} +0 -0
  103. /package/dist/{pix-key.d.ts → cjs/pix-key.d.ts} +0 -0
  104. /package/dist/{pix-key.js → cjs/pix-key.js} +0 -0
  105. /package/dist/{postal-track-code.d.ts → cjs/postal-track-code.d.ts} +0 -0
  106. /package/dist/{postal-track-code.js → cjs/postal-track-code.js} +0 -0
  107. /package/dist/{renavam.d.ts → cjs/renavam.d.ts} +0 -0
  108. /package/dist/{renavam.js → cjs/renavam.js} +0 -0
  109. /package/dist/{tituloEleitor.d.ts → cjs/tituloEleitor.d.ts} +0 -0
  110. /package/dist/{tituloEleitor.js → cjs/tituloEleitor.js} +0 -0
  111. /package/dist/{uf.d.ts → cjs/uf.d.ts} +0 -0
  112. /package/dist/{uf.js → cjs/uf.js} +0 -0
  113. /package/dist/{uuid.d.ts → cjs/uuid.d.ts} +0 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Certidao
3
+ * Detalhamento do cálculo da matrícula (CNJ - 32 dígitos)
4
+ *
5
+ * @doc
6
+ * O Número de Matrícula tem a configuração aaaaaa.bb.cc.dddd.e.fffff.ggg.hhhhhhh-ii, onde:
7
+ *
8
+ * - aaaaaa: Código Nacional da Serventia (identificação única do cartório) ex.: 10453-9
9
+ * - bb: Código do Acervo (01-Acervo Próprio e 02-Acervos incorporados)
10
+ * - cc: Tipo de Serviço Prestado (55 - Serviço de Registro Civil das Pessoas Naturais)
11
+ * - dddd: Ano do Registro - ex.: 2013
12
+ * - e: Tipo do livro
13
+ * 1 - Livro A (Nascimento)
14
+ * 2 - Livro B (Casamento)
15
+ * 3 - Livro B Auxiliar (Registro de casamentos religiosos para fins civis)
16
+ * 4 - Livro C (Óbito)
17
+ * 5 - Livro C Auxiliar (Registro de Natimortos)
18
+ * 6 - Livro D (Registro de Proclamas)
19
+ * 7 - Livro E (Demais atos relativos ao Registro Civil ou Livro E único)
20
+ * 8 - Livro E (Desdobrado para registro específico das Emancipações)
21
+ * 9 - Livro E (Desdobrado para registro específico das Interdições)
22
+ * - fffff: Número do livro - ex.: 00012
23
+ * - ggg: Número da folha - ex.: 021
24
+ * - hhhhhhh: Número do Termo - ex.: 0000123
25
+ * - ii: Dígito Verificador DV, cujo cálculo obedece ao esquema de MÓDULO 11.
26
+ *
27
+ * Exemplo de Cálculo: 104539.01.55.2013.1.00012.021.0000123-21
28
+ *
29
+ * 1) Cálculo do primeiro DV.
30
+ * - Soma-se o produto dos 30 primeiros dígitos por pesos específicos:
31
+ * Pesos: 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
32
+ *
33
+ * 1 0 4 5 3 9 0 1 5 5 2 0 1 3 1 0 0 0 1 2 0 2 1 0 0 0 0 1 2 3
34
+ * x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
35
+ * 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9
36
+ *
37
+ * Soma = 288
38
+ *
39
+ * - O somatório encontrado é dividido por 11.
40
+ * 288 ÷ 11 = 26, com resto 2.
41
+ * DV1 = Resto (2). Se resto for 10, DV1 será 1.
42
+ *
43
+ * 2) Cálculo do segundo DV.
44
+ * - Soma-se o produto dos 31 primeiros dígitos (incluindo DV1) por novos pesos.
45
+ * Pesos: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
46
+ *
47
+ * 1 0 4 5 3 9 0 1 5 5 2 0 1 3 1 0 0 0 1 2 0 2 1 0 0 0 0 1 2 3 2
48
+ * x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
49
+ * 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9
50
+ *
51
+ * Soma = 309
52
+ *
53
+ * - O somatório encontrado é dividido por 11.
54
+ * 309 ÷ 11 = 28, com resto 1.
55
+ * DV2 = Resto (1). Se resto for 10, DV2 será 1.
56
+ *
57
+ * Links:
58
+ * - http://ghiorzi.org/DVnew.htm#zc
59
+ * - https://www.arpensp.org.br/calculo-de-matricula
60
+ *
61
+ * @param {String} value Matrícula da Certidão
62
+ * @returns {Boolean}
63
+ */
64
+ import { Base } from './base';
65
+ export declare enum CertidaoTipoLivro {
66
+ Nascimento = "1",
67
+ Casamento = "2",
68
+ CasamentoReligioso = "3",
69
+ Obito = "4",
70
+ Natimorto = "5",
71
+ Proclamas = "6",
72
+ Outros = "7"
73
+ }
74
+ export declare enum CertidaoServico {
75
+ Notas = "51",
76
+ Protesto = "52",
77
+ RegistroImoveis = "53",
78
+ RegistroTitulosDocumentos = "54",
79
+ RegistroCivilPessoasNaturais = "55",
80
+ RegistroContratosMaritimos = "56",
81
+ RegistroDistribuicao = "57"
82
+ }
83
+ export interface FakeCertidaoOptions {
84
+ cns?: string;
85
+ acervo?: string;
86
+ servico?: CertidaoServico;
87
+ ano?: number;
88
+ tipoLivro?: CertidaoTipoLivro;
89
+ livro?: number;
90
+ folha?: number;
91
+ termo?: number;
92
+ }
93
+ export declare class Certidao extends Base {
94
+ protected _value: string;
95
+ protected _mask: string;
96
+ constructor(_value: string);
97
+ protected normalize(): void;
98
+ /**
99
+ * Valida se a certidão atual possui o DV correto e tamanho 32
100
+ */
101
+ validate(): boolean;
102
+ /**
103
+ * Calcula o DV para uma sequência de 30 dígitos
104
+ * Algoritmo Módulo 97:
105
+ */
106
+ static checksum(base30: string): string;
107
+ /**
108
+ * Gera uma instância de Certidao válida com dados aleatórios ou específicos
109
+ */
110
+ static fake(options?: FakeCertidaoOptions): Certidao;
111
+ }
@@ -1,39 +1,66 @@
1
1
  "use strict";
2
2
  /**
3
- * DETALHAMENTO DO CÁLCULO DA MATRÍCULA (CNJ - 32 DÍGITOS)
4
- * ---------------------------------------------------------------------------------
5
- * A matrícula é composta por 32 algarismos, divididos em 9 blocos:
6
- * 1. CNS (6 dígitos): Código Nacional da Serventia (Cartório).
7
- * 2. Acervo (2 dígitos): "01" para próprio, "02" para incorporado.
8
- * 3. Serviço (2 dígitos): Tipo de registro (ex: 55 para Registro Civil).
9
- * 4. Ano (4 dígitos): Ano em que o registro foi feito.
10
- * 5. Tipo de Livro (1 dígito): 1 (Nascimento), 2 (Casamento), etc.
11
- * 6. Número do Livro (5 dígitos): Sequencial do livro.
12
- * 7. Número da Folha (3 dígitos): Página do registro.
13
- * 8. Número do Termo (7 dígitos): Sequencial do registro.
14
- * 9. DV (2 dígitos): Dígitos verificadores calculados via Módulo 11.
15
- * * CÁLCULO DO DÍGITO VERIFICADOR (Módulo 11):
16
- * Para os dois últimos dígitos (DV1 e DV2):
17
- * * DV1 (31º dígito):
18
- * - Toma-se os primeiros 30 dígitos.
19
- * - Multiplica-se cada dígito por pesos decrescentes de 31 a 2.
20
- * - Soma-se os resultados.
21
- * - Resto = Soma % 11.
22
- * - Se Resto < 10, DV1 = Resto. Se Resto == 10, DV1 = 1.
23
- * * DV2 (32º dígito):
24
- * - Toma-se os 31 dígitos (30 originais + DV1 calculado).
25
- * - Multiplica-se cada dígito por pesos decrescentes de 32 a 2.
26
- * - Soma-se os resultados.
27
- * - Resto = Soma % 11.
28
- * - Se Resto < 10, DV2 = Resto. Se Resto == 10, DV2 = 1.
29
- * ---------------------------------------------------------------------------------
3
+ * Certidao
4
+ * Detalhamento do cálculo da matrícula (CNJ - 32 dígitos)
5
+ *
6
+ * @doc
7
+ * O Número de Matrícula tem a configuração aaaaaa.bb.cc.dddd.e.fffff.ggg.hhhhhhh-ii, onde:
8
+ *
9
+ * - aaaaaa: Código Nacional da Serventia (identificação única do cartório) ex.: 10453-9
10
+ * - bb: Código do Acervo (01-Acervo Próprio e 02-Acervos incorporados)
11
+ * - cc: Tipo de Serviço Prestado (55 - Serviço de Registro Civil das Pessoas Naturais)
12
+ * - dddd: Ano do Registro - ex.: 2013
13
+ * - e: Tipo do livro
14
+ * 1 - Livro A (Nascimento)
15
+ * 2 - Livro B (Casamento)
16
+ * 3 - Livro B Auxiliar (Registro de casamentos religiosos para fins civis)
17
+ * 4 - Livro C (Óbito)
18
+ * 5 - Livro C Auxiliar (Registro de Natimortos)
19
+ * 6 - Livro D (Registro de Proclamas)
20
+ * 7 - Livro E (Demais atos relativos ao Registro Civil ou Livro E único)
21
+ * 8 - Livro E (Desdobrado para registro específico das Emancipações)
22
+ * 9 - Livro E (Desdobrado para registro específico das Interdições)
23
+ * - fffff: Número do livro - ex.: 00012
24
+ * - ggg: Número da folha - ex.: 021
25
+ * - hhhhhhh: Número do Termo - ex.: 0000123
26
+ * - ii: Dígito Verificador DV, cujo cálculo obedece ao esquema de MÓDULO 11.
27
+ *
28
+ * Exemplo de Cálculo: 104539.01.55.2013.1.00012.021.0000123-21
29
+ *
30
+ * 1) Cálculo do primeiro DV.
31
+ * - Soma-se o produto dos 30 primeiros dígitos por pesos específicos:
32
+ * Pesos: 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
33
+ *
34
+ * 1 0 4 5 3 9 0 1 5 5 2 0 1 3 1 0 0 0 1 2 0 2 1 0 0 0 0 1 2 3
35
+ * x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
36
+ * 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9
37
+ *
38
+ * Soma = 288
39
+ *
40
+ * - O somatório encontrado é dividido por 11.
41
+ * 288 ÷ 11 = 26, com resto 2.
42
+ * DV1 = Resto (2). Se resto for 10, DV1 será 1.
43
+ *
44
+ * 2) Cálculo do segundo DV.
45
+ * - Soma-se o produto dos 31 primeiros dígitos (incluindo DV1) por novos pesos.
46
+ * Pesos: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
47
+ *
48
+ * 1 0 4 5 3 9 0 1 5 5 2 0 1 3 1 0 0 0 1 2 0 2 1 0 0 0 0 1 2 3 2
49
+ * x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
50
+ * 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9
51
+ *
52
+ * Soma = 309
53
+ *
54
+ * - O somatório encontrado é dividido por 11.
55
+ * 309 ÷ 11 = 28, com resto 1.
56
+ * DV2 = Resto (1). Se resto for 10, DV2 será 1.
30
57
  *
31
58
  * Links:
32
- * - https://www.arpensp.org.br/noticia/10670
59
+ * - http://ghiorzi.org/DVnew.htm#zc
33
60
  * - https://www.arpensp.org.br/calculo-de-matricula
34
- * - https://www.skyinformatica.com.br/produtos/civil/manual2/module_2_6.html
35
- * - https://atos.cnj.jus.br/files/provimento/provimento_2_27042009_26102012180800.pdf
36
61
  *
62
+ * @param {String} value Matrícula da Certidão
63
+ * @returns {Boolean}
37
64
  */
38
65
  Object.defineProperty(exports, "__esModule", { value: true });
39
66
  exports.Certidao = exports.CertidaoServico = exports.CertidaoTipoLivro = void 0;
@@ -87,23 +114,40 @@ class Certidao extends base_1.Base {
87
114
  }
88
115
  /**
89
116
  * Calcula o DV para uma sequência de 30 dígitos
117
+ * Algoritmo Módulo 97:
90
118
  */
91
119
  static checksum(base30) {
92
120
  if (!base30)
93
121
  throw new ValidationBRError_1.EmptyValueException();
94
122
  if (base30.length !== 30)
95
123
  throw new ValidationBRError_1.InvalidFormatException();
96
- // Pesos de 31 a 2
97
- const weights1 = Array.from({ length: 30 }, (_, i) => 31 - i);
98
- const soma1 = (0, utils_1.sumElementsByMultipliers)(base30, weights1);
99
- let dv1 = soma1 % 11;
124
+ // Pesos específicos conforme solicitação:
125
+ // DV1: 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
126
+ const weights1 = [
127
+ 2, 3, 4, 5, 6, 7, 8, 9, 10, 0,
128
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
129
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
130
+ ];
131
+ let sum1 = 0;
132
+ for (let i = 0; i < 30; i++) {
133
+ sum1 += parseInt(base30[i], 10) * weights1[i];
134
+ }
135
+ let dv1 = sum1 % 11;
100
136
  if (dv1 === 10)
101
137
  dv1 = 1;
102
- // Pesos de 32 a 2
138
+ // DV2: Inclui o DV1 no final
139
+ // Pesos: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
103
140
  const base31 = base30 + dv1.toString();
104
- const weights2 = Array.from({ length: 31 }, (_, i) => 32 - i);
105
- const soma2 = (0, utils_1.sumElementsByMultipliers)(base31, weights2);
106
- let dv2 = soma2 % 11;
141
+ const weights2 = [
142
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
143
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
144
+ 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
145
+ ];
146
+ let sum2 = 0;
147
+ for (let i = 0; i < 31; i++) {
148
+ sum2 += parseInt(base31[i], 10) * weights2[i];
149
+ }
150
+ let dv2 = sum2 % 11;
107
151
  if (dv2 === 10)
108
152
  dv2 = 1;
109
153
  return `${dv1}${dv2}`;
@@ -113,6 +157,7 @@ class Certidao extends base_1.Base {
113
157
  */
114
158
  static fake(options = {}) {
115
159
  const pad = (n, size) => n.toString().padStart(size, '0');
160
+ const meupa = (0, utils_1.clearValue)(0, 3, { fillZerosAtLeft: true });
116
161
  const cns = options.cns ? pad(options.cns, 6) : pad(Math.floor(Math.random() * 999999), 6);
117
162
  const acervo = options.acervo ? pad(options.acervo, 2) : '01';
118
163
  const servico = options.servico || CertidaoServico.RegistroCivilPessoasNaturais;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -21,13 +21,16 @@ class UUID extends base_1.Base {
21
21
  this._value = this._value.replace(/[^0-9a-z]+/gi, '').toLocaleLowerCase();
22
22
  }
23
23
  validate() {
24
- return /^[0-9a-z]{8}-?[0-9a-z]{4}-?4[0-9a-z]{3}-?[0-9a-z]{4}-?[0-9a-z]{12}$/i.test(this._value);
24
+ // O quarto grupo (variante, RFC 4122) deve iniciar com 8, 9, a ou b.
25
+ // Os demais caracteres devem ser hexadecimais (0-9, a-f).
26
+ return /^[0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$/i.test(this._value);
25
27
  }
26
- //
28
+ //
27
29
  // STATIC
28
- //
30
+ //
29
31
  static fake() {
30
- return new UUID(`${random_1.Random.number(8, true)}-${random_1.Random.number(4, true)}-4${random_1.Random.number(3, true)}-${random_1.Random.number(4, true)}-${random_1.Random.number(12, true)}`);
32
+ const variant = random_1.Random.fromArray(['8', '9', 'a', 'b']);
33
+ return new UUID(`${random_1.Random.number(8, true)}-${random_1.Random.number(4, true)}-4${random_1.Random.number(3, true)}-${variant}${random_1.Random.alpha(3, false, true)}-${random_1.Random.number(12, true)}`);
31
34
  }
32
35
  }
33
36
  exports.UUID = UUID;
@@ -0,0 +1,24 @@
1
+ export default class ValidationBRError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class InvalidChecksumException extends ValidationBRError {
5
+ constructor();
6
+ }
7
+ export declare class InvalidFormatException extends ValidationBRError {
8
+ constructor();
9
+ }
10
+ export declare class EmptyValueException extends ValidationBRError {
11
+ constructor();
12
+ }
13
+ export declare class TooLongException extends ValidationBRError {
14
+ constructor();
15
+ }
16
+ export declare class TooShortException extends ValidationBRError {
17
+ constructor();
18
+ }
19
+ export declare class RepeatedSequenceException extends ValidationBRError {
20
+ constructor();
21
+ }
22
+ export declare class NoChecksumException extends ValidationBRError {
23
+ constructor();
24
+ }
@@ -0,0 +1,40 @@
1
+ export default class ValidationBRError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ }
5
+ }
6
+ export class InvalidChecksumException extends ValidationBRError {
7
+ constructor() {
8
+ super('Dígito verificador inválido');
9
+ }
10
+ }
11
+ export class InvalidFormatException extends ValidationBRError {
12
+ constructor() {
13
+ super('Formato inválido');
14
+ }
15
+ }
16
+ export class EmptyValueException extends ValidationBRError {
17
+ constructor() {
18
+ super('Valor não preenchido');
19
+ }
20
+ }
21
+ export class TooLongException extends ValidationBRError {
22
+ constructor() {
23
+ super('Número de caracteres excedido');
24
+ }
25
+ }
26
+ export class TooShortException extends ValidationBRError {
27
+ constructor() {
28
+ super('Número de caracteres muito curto');
29
+ }
30
+ }
31
+ export class RepeatedSequenceException extends ValidationBRError {
32
+ constructor() {
33
+ super('Sequência de números repetidos não permitida');
34
+ }
35
+ }
36
+ export class NoChecksumException extends ValidationBRError {
37
+ constructor() {
38
+ super('Este objeto não possui dígito verificador');
39
+ }
40
+ }
@@ -0,0 +1,7 @@
1
+ export declare class CRC {
2
+ private _value;
3
+ constructor(_value: string);
4
+ get value(): string;
5
+ static numToHex(n: number, digits?: number): string;
6
+ calculate(invert?: boolean): string;
7
+ }
@@ -0,0 +1,43 @@
1
+ export class CRC {
2
+ constructor(_value) {
3
+ this._value = _value;
4
+ }
5
+ get value() {
6
+ return this._value;
7
+ }
8
+ // https://github.com/NascentSecureTech/pix-qrcode-utils/blob/01a072f458d63dea2376e631284085405fd8b027/packages/data-schemas/src/data-utils.ts#L9
9
+ static numToHex(n, digits = 4) {
10
+ const hex = n.toString(16).toUpperCase();
11
+ return ('0'.repeat(digits) + hex).slice(-digits);
12
+ }
13
+ calculate(invert = false) {
14
+ const bytes = new TextEncoder().encode(this._value);
15
+ const crcTable = [
16
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273,
17
+ 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7,
18
+ 0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b,
19
+ 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af,
20
+ 0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b,
21
+ 0xab1a, 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6,
22
+ 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c,
23
+ 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
24
+ 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2, 0x24c3, 0x14a0,
25
+ 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676,
26
+ 0x4615, 0x5634, 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d,
27
+ 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d,
28
+ 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9,
29
+ 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
30
+ ];
31
+ let crc = 0xffff;
32
+ for (let i = 0; i < bytes.length; i++) {
33
+ const c = bytes[i];
34
+ const j = (c ^ (crc >> 8)) & 0xff;
35
+ crc = crcTable[j] ^ (crc << 8);
36
+ }
37
+ const answer = (crc ^ 0) & 0xffff;
38
+ const hex = CRC.numToHex(answer, 4);
39
+ if (invert)
40
+ return hex.slice(2) + hex.slice(0, 2);
41
+ return hex;
42
+ }
43
+ }
@@ -0,0 +1,31 @@
1
+ export declare class Crockford {
2
+ private static readonly ALPHABET;
3
+ /**
4
+ * Normaliza a string conforme as regras do SINTER/CIB:
5
+ * 1. Remove pontuação e espaços
6
+ * 2. Converte para Maiúsculas
7
+ * 3. Substitui 'I' e 'L' por '1'
8
+ * 4. Substitui 'O' por '0'
9
+ * 5. Lança erro para o caractere proibido 'U'
10
+ */
11
+ static normalize(value: string): string;
12
+ /**
13
+ * Converte um caractere alfanumérico para seu valor decimal (0-31)
14
+ */
15
+ static charToInt(char: string): number;
16
+ /**
17
+ * Converte um valor numérico (0-31) para o caractere correspondente
18
+ */
19
+ static intToChar(value: number): string;
20
+ /**
21
+ *
22
+ * Retorna o alfabeto utilizado
23
+ */
24
+ static getAlphabet(): string;
25
+ static getAlphabet(options: {
26
+ returnArray: false;
27
+ }): string;
28
+ static getAlphabet(options: {
29
+ returnArray: true;
30
+ }): string[];
31
+ }
@@ -0,0 +1,58 @@
1
+ export class Crockford {
2
+ /**
3
+ * Normaliza a string conforme as regras do SINTER/CIB:
4
+ * 1. Remove pontuação e espaços
5
+ * 2. Converte para Maiúsculas
6
+ * 3. Substitui 'I' e 'L' por '1'
7
+ * 4. Substitui 'O' por '0'
8
+ * 5. Lança erro para o caractere proibido 'U'
9
+ */
10
+ static normalize(value) {
11
+ if (!value)
12
+ return "";
13
+ let normalized = value
14
+ .toUpperCase()
15
+ .replace(/[-.\s]/g, ""); // Remove hífens, pontos e espaços
16
+ // Substituições de ambiguidade visual
17
+ normalized = normalized.replace(/[IL]/g, "1");
18
+ normalized = normalized.replace(/O/g, "0");
19
+ // Validação do caractere proibido
20
+ if (normalized.includes("U")) {
21
+ throw new Error("O caractere 'U' é proibido no padrão CIB/SINTER para evitar palavras obscenas.");
22
+ }
23
+ return normalized;
24
+ }
25
+ /**
26
+ * Converte um caractere alfanumérico para seu valor decimal (0-31)
27
+ */
28
+ static charToInt(char) {
29
+ // Normaliza apenas o caractere para garantir que substituições (como 'i' -> '1') ocorram
30
+ const cleanChar = this.normalize(char);
31
+ if (cleanChar.length !== 1) {
32
+ throw new Error("Deve ser fornecido apenas um caractere.");
33
+ }
34
+ const index = this.ALPHABET.indexOf(cleanChar);
35
+ if (index === -1) {
36
+ throw new Error(`Caractere '${char}' não pertence ao alfabeto Crockford Base32.`);
37
+ }
38
+ return index;
39
+ }
40
+ /**
41
+ * Converte um valor numérico (0-31) para o caractere correspondente
42
+ */
43
+ static intToChar(value) {
44
+ if (value < 0 || value > 31) {
45
+ throw new Error("O valor deve estar entre 0 e 31 para conversão em Base32.");
46
+ }
47
+ return this.ALPHABET[value];
48
+ }
49
+ static getAlphabet(options) {
50
+ const { returnArray = false } = options || {};
51
+ if (returnArray) {
52
+ return this.ALPHABET.split('');
53
+ }
54
+ return this.ALPHABET;
55
+ }
56
+ }
57
+ // Alfabeto Base 32 de Douglas Crockford (32 caracteres)
58
+ Crockford.ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
@@ -0,0 +1,18 @@
1
+ export declare class Mask {
2
+ private _value;
3
+ constructor(_value: string);
4
+ /**
5
+ * applyMask()
6
+ * Aplica uma máscara a uma string
7
+ *
8
+ * @example
9
+ * applyMask('59650000', '00.000-000') // -> 59.650-000
10
+ * applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
11
+ *
12
+ * @param {String|Number} value Valor original
13
+ * @param {String} mask
14
+ * @returns {String}
15
+ *
16
+ */
17
+ apply(mask: string): string;
18
+ }
@@ -0,0 +1,33 @@
1
+ import { clearValue, insertAtPosition } from './utils.js';
2
+ export class Mask {
3
+ constructor(_value) {
4
+ this._value = _value;
5
+ }
6
+ /**
7
+ * applyMask()
8
+ * Aplica uma máscara a uma string
9
+ *
10
+ * @example
11
+ * applyMask('59650000', '00.000-000') // -> 59.650-000
12
+ * applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
13
+ *
14
+ * @param {String|Number} value Valor original
15
+ * @param {String} mask
16
+ * @returns {String}
17
+ *
18
+ */
19
+ apply(mask) {
20
+ const maskLen = clearValue(mask).length;
21
+ let masked = clearValue(this._value, maskLen, {
22
+ fillZerosAtLeft: true,
23
+ trimAtRight: true,
24
+ });
25
+ const specialChars = ['/', '-', '.', '(', ')', ' '];
26
+ for (let position = 0; position < mask.length; position += 1) {
27
+ const current = mask[position];
28
+ if (specialChars.includes(current))
29
+ masked = insertAtPosition(masked, current, position);
30
+ }
31
+ return masked;
32
+ }
33
+ }
@@ -0,0 +1,27 @@
1
+ export declare class Random {
2
+ /**
3
+ * Devolve um inteiro aleatório entre um mínimo e um máximo.
4
+ */
5
+ static between(min: number, max: number): number;
6
+ /**
7
+ * Devolve um texto aleatório
8
+ */
9
+ static alpha(length?: number, isUppercase?: boolean, isHex?: boolean): string;
10
+ /**
11
+ * Seleciona um item de um array aleatoramente
12
+ *
13
+ * @example
14
+ * const array = [1, 2, 3, 4, 5];
15
+ *
16
+ * const singleItem = Random.fromArray(array); // Pode retornar 1, 2, 3, 4 ou 5
17
+ * const multipleItems = Random.fromArray(array, 3); // Pode retornar [1, 2, 3], [4, 5, 1], etc.
18
+ *
19
+ *
20
+ */
21
+ static fromArray<T>(array: T[], length: number): T[];
22
+ static fromArray<T>(array: T[], length?: 1): T;
23
+ /**
24
+ * Cria um número aleatório com a quantidade definida de caracteres
25
+ */
26
+ static number(length: number, forceLength?: boolean, isAlpha?: boolean): string;
27
+ }
@@ -0,0 +1,50 @@
1
+ export class Random {
2
+ /**
3
+ * Devolve um inteiro aleatório entre um mínimo e um máximo.
4
+ */
5
+ static between(min, max) {
6
+ return Math.floor(Math.random() * (max - min + 1) + min);
7
+ }
8
+ /**
9
+ * Devolve um texto aleatório
10
+ */
11
+ static alpha(length = 1, isUppercase = false, isHex = false) {
12
+ const letters = isHex ? '0123456789abcdef' : 'abcdefghijklmnopqrstuvwxyz';
13
+ let result = '';
14
+ for (let i = 0; i < length; i++) {
15
+ const index = Random.between(0, letters.length - 1);
16
+ result += letters[index];
17
+ }
18
+ if (isUppercase)
19
+ return result.toLocaleUpperCase();
20
+ return result;
21
+ }
22
+ static fromArray(array, length = 1) {
23
+ const _get = () => array[Random.between(0, array.length - 1)];
24
+ if (length === 1)
25
+ return _get();
26
+ const result = [];
27
+ for (let i = 0; i < length; i++) {
28
+ const item = _get();
29
+ if (item !== undefined) {
30
+ result.push(item);
31
+ }
32
+ }
33
+ return result;
34
+ }
35
+ /**
36
+ * Cria um número aleatório com a quantidade definida de caracteres
37
+ */
38
+ static number(length, forceLength = false, isAlpha = false) {
39
+ let value;
40
+ if (isAlpha)
41
+ value = Math.round(Math.random() * 36 ** length)
42
+ .toString(36)
43
+ .toLocaleUpperCase();
44
+ else
45
+ value = Math.floor(Math.random() * 10 ** length).toString();
46
+ if (forceLength)
47
+ return String(value).padStart(length, '0');
48
+ return String(value);
49
+ }
50
+ }