validation-br 1.6.2-e → 1.6.3-a

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 (46) hide show
  1. package/.prettierignore +1 -0
  2. package/.prettierrc.js +7 -0
  3. package/.publish/dist/_exceptions/ValidationBRError.d.ts +7 -0
  4. package/.publish/dist/_exceptions/ValidationBRError.js +11 -0
  5. package/.publish/dist/_exceptions/ValidationBRError.js.map +1 -0
  6. package/.publish/dist/cnh.d.ts +98 -0
  7. package/.publish/dist/cnh.js +149 -0
  8. package/.publish/dist/cnh.js.map +1 -0
  9. package/.publish/dist/cnpj.d.ts +121 -0
  10. package/.publish/dist/cnpj.js +193 -0
  11. package/.publish/dist/cnpj.js.map +1 -0
  12. package/.publish/dist/cpf.d.ts +106 -0
  13. package/.publish/dist/cpf.js +157 -0
  14. package/.publish/dist/cpf.js.map +1 -0
  15. package/.publish/dist/index.d.ts +21 -0
  16. package/.publish/dist/index.js +42 -0
  17. package/.publish/dist/index.js.map +1 -0
  18. package/.publish/dist/judicialProcess.d.ts +133 -0
  19. package/.publish/dist/judicialProcess.js +200 -0
  20. package/.publish/dist/judicialProcess.js.map +1 -0
  21. package/.publish/dist/nup17.d.ts +103 -0
  22. package/.publish/dist/nup17.js +159 -0
  23. package/.publish/dist/nup17.js.map +1 -0
  24. package/.publish/dist/pisPasep.d.ts +88 -0
  25. package/.publish/dist/pisPasep.js +136 -0
  26. package/.publish/dist/pisPasep.js.map +1 -0
  27. package/.publish/dist/postalCode.d.ts +92 -0
  28. package/.publish/dist/postalCode.js +144 -0
  29. package/.publish/dist/postalCode.js.map +1 -0
  30. package/.publish/dist/renavam.d.ts +82 -0
  31. package/.publish/dist/renavam.js +132 -0
  32. package/.publish/dist/renavam.js.map +1 -0
  33. package/.publish/dist/tituloEleitor.d.ts +100 -0
  34. package/.publish/dist/tituloEleitor.js +157 -0
  35. package/.publish/dist/tituloEleitor.js.map +1 -0
  36. package/.publish/dist/utils.d.ts +131 -0
  37. package/.publish/dist/utils.js +190 -0
  38. package/.publish/dist/utils.js.map +1 -0
  39. package/.publish/package-lock.json +4372 -0
  40. package/.publish/package.json +112 -0
  41. package/.publish/readme.md +492 -0
  42. package/eslint.config.js +82 -0
  43. package/jest.config.js +11 -0
  44. package/package.json +6 -8
  45. package/publish.sh +31 -0
  46. package/tsconfig.json +25 -0
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Calcula o DV verificador a partir das regras do MOD11:
3
+ * O valor da soma é dividido por 11. O resultado é o resto da divisão. Caso o resto seja
4
+ * menor que 2, ou seja, o valor da divisão seja 10 ou 11, o resultado é 0.
5
+ *
6
+ * @param {Integer} sum Soma
7
+ * @returns {Integer}
8
+ */
9
+ export declare function sumToDV(sum: number): number;
10
+ /**
11
+ * Checa se o número repassado possui todos os digitos iguais
12
+ *
13
+ * @example
14
+ * checkRepeatedSequence(12345678)
15
+ * // -> false
16
+ * checkRepeatedSequence(11111111)
17
+ * // -> true
18
+ *
19
+ */
20
+ export declare function checkRepeatedSequence(value: string): boolean;
21
+ /**
22
+ * Multiplica os elementos de uma string com os elementos de outra, ou de um array
23
+ * e soma o resultado ao final
24
+ *
25
+ * @example
26
+ * sumElementsByMultipliers('123', '987') //-> 46
27
+ * sumElementsByMultipliers('123', [9, 8, 7]) //-> 46
28
+ *
29
+ * @param {String} value
30
+ * @param {String|Array} multiplier
31
+ * @returns {Integer} Somatório
32
+ */
33
+ export declare function sumElementsByMultipliers(value: string, multiplier: number[]): number;
34
+ /**
35
+ * fakeNumber()
36
+ * Cria um número aleatório com o número de caracteres
37
+ *
38
+ * @example
39
+ * fakeNumber(8, true) // -> 00083159
40
+ * fakeNumber(4) // -> 831
41
+ *
42
+ * @param {Integer} length
43
+ * @param {Boolean} forceLength Adiciona zeros à esquerda para ter os números de caractes exatos
44
+ * @returns {String}
45
+ */
46
+ export declare function fakeNumber(length: number, forceLength?: boolean, isAlpha?: boolean): string;
47
+ /**
48
+ * Limpa um número informado, retirando caracteres diferentes de números,
49
+ * preenchendo com zeros à esquerda se for menor que o tamanho exato e
50
+ * removendo uma parte do número se for maior que tamanho definido.
51
+ *
52
+ * 1) Retira caracteres não-numéricos
53
+ * 2) Preenche com zeros à esquerda se 'value' for menor que 'length'
54
+ * 3) Remove caracteres à direita se 'value' for maior que 'length'
55
+ *
56
+ * @example
57
+ * clearValue(12345-6, 6) // -> 123456
58
+ * clearValue(12345678, 3) // -> 123
59
+ * clearValue(12345, 10) // -> 0000001234
60
+ *
61
+ * @param {Number|String} value
62
+ * @param {Number} length Tamanho exato. Se for null, só retira os caracteres não-numéricos
63
+ * @returns {String} Número com o tamanho exato
64
+ */
65
+ export declare function clearValue(value: string | number, length?: number | null, options?: ClearValueOptions): string;
66
+ /**
67
+ * insertAtPosition()
68
+ * Insere um conjunto de caracteres em um local específico de uma string
69
+ *
70
+ * @example
71
+ * insertAtPosition('AAABBB', 'C', 3) // -> AAACBBB
72
+ * insertAtPosition('000011122223445555', 99, 7) // -> 00001119922223445555
73
+ *
74
+ * @param {String|Number} value Valor original
75
+ * @param {String|Number} insertValue Valor que será inserido
76
+ * @param {String|Number} position Posição que receberá o novo valor
77
+ * @returns {String}
78
+ *
79
+ */
80
+ export declare function insertAtPosition(value: string, insertValue: string, position: number): string;
81
+ /**
82
+ * removeFromPosition()
83
+ * Retira um conjunto de caracteres de um local específico de uma string
84
+ *
85
+ * @example
86
+ * removeFromPosition('00001119922223445555', 7,9) // -> 000011122223445555
87
+ * removeFromPosition('AAACBBB', 3,4) // -> AAABBB
88
+ *
89
+ * @param {String|Number} value Valor original
90
+ * @param {String|Number} startPosition
91
+ * @param {String|Number} endPosition
92
+ * @returns {String}
93
+ *
94
+ */
95
+ export declare function removeFromPosition(value: string, startPosition: number, endPosition: number): string;
96
+ /**
97
+ * applyMask()
98
+ * Aplica uma máscara a uma string
99
+ *
100
+ * @example
101
+ * applyMask('59650000', '00.000-000') // -> 59.650-000
102
+ * applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
103
+ *
104
+ * @param {String|Number} value Valor original
105
+ * @param {String} mask
106
+ * @returns {String}
107
+ *
108
+ */
109
+ export declare function applyMask(value: string | number, mask: string): string;
110
+ /**
111
+ * randomLetter()
112
+ * Pega uma letra maiúscula aleatoriamente
113
+ *
114
+ * @example
115
+ * randomLetter() // -> A
116
+ * randomLetter() // -> S
117
+ *
118
+ * @returns {String}
119
+ */
120
+ export declare function randomLetter(): string;
121
+ /**
122
+ * Opções do clearValue
123
+ */
124
+ interface ClearValueOptions {
125
+ fillZerosAtLeft?: boolean;
126
+ trimAtRight?: boolean;
127
+ rejectEmpty?: boolean;
128
+ rejectHigherLength?: boolean;
129
+ rejectEqualSequence?: boolean;
130
+ }
131
+ export {};
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sumToDV = sumToDV;
7
+ exports.checkRepeatedSequence = checkRepeatedSequence;
8
+ exports.sumElementsByMultipliers = sumElementsByMultipliers;
9
+ exports.fakeNumber = fakeNumber;
10
+ exports.clearValue = clearValue;
11
+ exports.insertAtPosition = insertAtPosition;
12
+ exports.removeFromPosition = removeFromPosition;
13
+ exports.applyMask = applyMask;
14
+ exports.randomLetter = randomLetter;
15
+ const ValidationBRError_1 = __importDefault(require("./_exceptions/ValidationBRError"));
16
+ /**
17
+ * Calcula o DV verificador a partir das regras do MOD11:
18
+ * O valor da soma é dividido por 11. O resultado é o resto da divisão. Caso o resto seja
19
+ * menor que 2, ou seja, o valor da divisão seja 10 ou 11, o resultado é 0.
20
+ *
21
+ * @param {Integer} sum Soma
22
+ * @returns {Integer}
23
+ */
24
+ function sumToDV(sum) {
25
+ return sum % 11 < 2 ? 0 : 11 - (sum % 11);
26
+ }
27
+ /**
28
+ * Checa se o número repassado possui todos os digitos iguais
29
+ *
30
+ * @example
31
+ * checkRepeatedSequence(12345678)
32
+ * // -> false
33
+ * checkRepeatedSequence(11111111)
34
+ * // -> true
35
+ *
36
+ */
37
+ function checkRepeatedSequence(value) {
38
+ return [...value].every(digit => digit === value[0]);
39
+ }
40
+ /**
41
+ * Multiplica os elementos de uma string com os elementos de outra, ou de um array
42
+ * e soma o resultado ao final
43
+ *
44
+ * @example
45
+ * sumElementsByMultipliers('123', '987') //-> 46
46
+ * sumElementsByMultipliers('123', [9, 8, 7]) //-> 46
47
+ *
48
+ * @param {String} value
49
+ * @param {String|Array} multiplier
50
+ * @returns {Integer} Somatório
51
+ */
52
+ function sumElementsByMultipliers(value, multiplier) {
53
+ return multiplier.reduce((accu, curr, i) => accu + curr * Number(value[i]), 0);
54
+ }
55
+ /**
56
+ * fakeNumber()
57
+ * Cria um número aleatório com o número de caracteres
58
+ *
59
+ * @example
60
+ * fakeNumber(8, true) // -> 00083159
61
+ * fakeNumber(4) // -> 831
62
+ *
63
+ * @param {Integer} length
64
+ * @param {Boolean} forceLength Adiciona zeros à esquerda para ter os números de caractes exatos
65
+ * @returns {String}
66
+ */
67
+ function fakeNumber(length, forceLength = false, isAlpha = false) {
68
+ let value;
69
+ if (isAlpha)
70
+ value = Math.round(Math.random() * 36 ** length).toString(36).toLocaleUpperCase();
71
+ else
72
+ value = Math.floor(Math.random() * 10 ** length).toString();
73
+ if (forceLength)
74
+ return String(value).padStart(length, '0');
75
+ return String(value);
76
+ }
77
+ /**
78
+ * Limpa um número informado, retirando caracteres diferentes de números,
79
+ * preenchendo com zeros à esquerda se for menor que o tamanho exato e
80
+ * removendo uma parte do número se for maior que tamanho definido.
81
+ *
82
+ * 1) Retira caracteres não-numéricos
83
+ * 2) Preenche com zeros à esquerda se 'value' for menor que 'length'
84
+ * 3) Remove caracteres à direita se 'value' for maior que 'length'
85
+ *
86
+ * @example
87
+ * clearValue(12345-6, 6) // -> 123456
88
+ * clearValue(12345678, 3) // -> 123
89
+ * clearValue(12345, 10) // -> 0000001234
90
+ *
91
+ * @param {Number|String} value
92
+ * @param {Number} length Tamanho exato. Se for null, só retira os caracteres não-numéricos
93
+ * @returns {String} Número com o tamanho exato
94
+ */
95
+ function clearValue(value, length = null, options) {
96
+ let clearedValue = String(value).replace(/([/.-\s]+)/gi, '');
97
+ if (options) {
98
+ const shouldRejectEmpty = options.rejectEmpty === true && clearedValue.length === 0;
99
+ if (shouldRejectEmpty) {
100
+ throw ValidationBRError_1.default.EMPTY_VALUE;
101
+ }
102
+ const shouldRejectHigherLength = options.rejectHigherLength === true && length && clearedValue.length > length;
103
+ if (shouldRejectHigherLength) {
104
+ throw ValidationBRError_1.default.MAX_LEN_EXCEDEED;
105
+ }
106
+ const shouldRejectEqualSequence = options.rejectEqualSequence === true && length;
107
+ if (shouldRejectEqualSequence) {
108
+ if (checkRepeatedSequence(clearedValue))
109
+ throw ValidationBRError_1.default.REPEATED_SEQUENCE;
110
+ }
111
+ if (length && options.fillZerosAtLeft)
112
+ clearedValue = clearedValue.padStart(length, '0');
113
+ if (length && options.trimAtRight)
114
+ clearedValue = clearedValue.substring(0, length);
115
+ }
116
+ return clearedValue;
117
+ }
118
+ /**
119
+ * insertAtPosition()
120
+ * Insere um conjunto de caracteres em um local específico de uma string
121
+ *
122
+ * @example
123
+ * insertAtPosition('AAABBB', 'C', 3) // -> AAACBBB
124
+ * insertAtPosition('000011122223445555', 99, 7) // -> 00001119922223445555
125
+ *
126
+ * @param {String|Number} value Valor original
127
+ * @param {String|Number} insertValue Valor que será inserido
128
+ * @param {String|Number} position Posição que receberá o novo valor
129
+ * @returns {String}
130
+ *
131
+ */
132
+ function insertAtPosition(value, insertValue, position) {
133
+ return `${value.substring(0, position)}${insertValue}${value.substring(position)}`;
134
+ }
135
+ /**
136
+ * removeFromPosition()
137
+ * Retira um conjunto de caracteres de um local específico de uma string
138
+ *
139
+ * @example
140
+ * removeFromPosition('00001119922223445555', 7,9) // -> 000011122223445555
141
+ * removeFromPosition('AAACBBB', 3,4) // -> AAABBB
142
+ *
143
+ * @param {String|Number} value Valor original
144
+ * @param {String|Number} startPosition
145
+ * @param {String|Number} endPosition
146
+ * @returns {String}
147
+ *
148
+ */
149
+ function removeFromPosition(value, startPosition, endPosition) {
150
+ return [value.slice(0, startPosition), value.slice(endPosition)].join('');
151
+ }
152
+ /**
153
+ * applyMask()
154
+ * Aplica uma máscara a uma string
155
+ *
156
+ * @example
157
+ * applyMask('59650000', '00.000-000') // -> 59.650-000
158
+ * applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
159
+ *
160
+ * @param {String|Number} value Valor original
161
+ * @param {String} mask
162
+ * @returns {String}
163
+ *
164
+ */
165
+ function applyMask(value, mask) {
166
+ const maskLen = clearValue(mask).length;
167
+ let masked = clearValue(value, maskLen, { fillZerosAtLeft: true, trimAtRight: true });
168
+ const specialChars = ['/', '-', '.', '(', ')', ' '];
169
+ for (let position = 0; position < mask.length; position += 1) {
170
+ const current = mask[position];
171
+ if (specialChars.includes(current))
172
+ masked = insertAtPosition(masked, current, position);
173
+ }
174
+ return masked;
175
+ }
176
+ /**
177
+ * randomLetter()
178
+ * Pega uma letra maiúscula aleatoriamente
179
+ *
180
+ * @example
181
+ * randomLetter() // -> A
182
+ * randomLetter() // -> S
183
+ *
184
+ * @returns {String}
185
+ */
186
+ function randomLetter() {
187
+ const idx = Math.floor(1 + Math.random() * 26);
188
+ return String.fromCharCode(idx + 64);
189
+ }
190
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;;;AAUA,0BAEC;AAYD,sDAEC;AAcD,4DAKC;AAcD,gCASC;AAoBD,gCA4BC;AAgBD,4CAEC;AAgBD,gDAMC;AAeD,8BAWC;AAYD,oCAGC;AArMD,wFAAgE;AAEhE;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAC,GAAW;IACjC,OAAO,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,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