validation-br 1.0.0-b → 1.0.0-c

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 (63) hide show
  1. package/.eslintcache +1 -0
  2. package/package.json +64 -2
  3. package/dist/cnh.test.js +0 -117
  4. package/dist/cnh.test.js.map +0 -1
  5. package/dist/cnpj.test.js +0 -141
  6. package/dist/cnpj.test.js.map +0 -1
  7. package/dist/cpf.test.js +0 -130
  8. package/dist/cpf.test.js.map +0 -1
  9. package/dist/index.test.js +0 -33
  10. package/dist/index.test.js.map +0 -1
  11. package/dist/judicialProcess.test.js +0 -123
  12. package/dist/judicialProcess.test.js.map +0 -1
  13. package/dist/pisPasep.test.js +0 -129
  14. package/dist/pisPasep.test.js.map +0 -1
  15. package/dist/postalCode.test.js +0 -135
  16. package/dist/postalCode.test.js.map +0 -1
  17. package/dist/renavam.test.js +0 -113
  18. package/dist/renavam.test.js.map +0 -1
  19. package/dist/tituloEleitor.test.js +0 -132
  20. package/dist/tituloEleitor.test.js.map +0 -1
  21. package/dist/utils-applyMask.test.js +0 -17
  22. package/dist/utils-applyMask.test.js.map +0 -1
  23. package/dist/utils-clearValue.test.js +0 -50
  24. package/dist/utils-clearValue.test.js.map +0 -1
  25. package/dist/utils-fakeNumber.test.js +0 -17
  26. package/dist/utils-fakeNumber.test.js.map +0 -1
  27. package/dist/utils-insertAtPosition.test.js +0 -16
  28. package/dist/utils-insertAtPosition.test.js.map +0 -1
  29. package/dist/utils-invalidListGenerator.test.js +0 -23
  30. package/dist/utils-invalidListGenerator.test.js.map +0 -1
  31. package/dist/utils-removeFromPosition.test.js +0 -16
  32. package/dist/utils-removeFromPosition.test.js.map +0 -1
  33. package/dist/utils-sumElementsByMultipliers.test.js +0 -32
  34. package/dist/utils-sumElementsByMultipliers.test.js.map +0 -1
  35. package/dist/utils-sumToDV.test.js +0 -16
  36. package/dist/utils-sumToDV.test.js.map +0 -1
  37. package/src/cnh.test.ts +0 -114
  38. package/src/cnh.ts +0 -140
  39. package/src/cnpj.test.ts +0 -136
  40. package/src/cnpj.ts +0 -128
  41. package/src/cpf.test.ts +0 -125
  42. package/src/cpf.ts +0 -150
  43. package/src/index.test.ts +0 -35
  44. package/src/index.ts +0 -19
  45. package/src/judicialProcess.test.ts +0 -118
  46. package/src/judicialProcess.ts +0 -167
  47. package/src/pisPasep.test.ts +0 -124
  48. package/src/pisPasep.ts +0 -128
  49. package/src/postalCode.test.ts +0 -132
  50. package/src/postalCode.ts +0 -164
  51. package/src/renavam.test.ts +0 -110
  52. package/src/renavam.ts +0 -122
  53. package/src/tituloEleitor.test.ts +0 -129
  54. package/src/tituloEleitor.ts +0 -146
  55. package/src/utils-applyMask.test.ts +0 -17
  56. package/src/utils-clearValue.test.ts +0 -55
  57. package/src/utils-fakeNumber.test.ts +0 -19
  58. package/src/utils-insertAtPosition.test.ts +0 -15
  59. package/src/utils-invalidListGenerator.test.ts +0 -27
  60. package/src/utils-removeFromPosition.test.ts +0 -15
  61. package/src/utils-sumElementsByMultipliers.test.ts +0 -34
  62. package/src/utils-sumToDV.test.ts +0 -16
  63. package/src/utils.ts +0 -172
package/src/utils.ts DELETED
@@ -1,172 +0,0 @@
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 function sumToDV(sum: number): number {
10
- return sum % 11 < 2 ? 0 : 11 - (sum % 11)
11
- }
12
-
13
- /**
14
- * Cria uma lista de valores repetidos no tamanho do documento para eliminar
15
- * valores que já conhecemos como inválidos
16
- *
17
- * @example
18
- * invalidListGenerator(10, 11)
19
- * //-> [00000000000, 11111111111, ....., 99999999999]
20
- *
21
- * @param {Integer} length Número de itens do array
22
- * @param {Integer} size Tamanho da string gerada
23
- * @returns {Array} Lista de valores
24
- */
25
- export function invalidListGenerator(size: number): string[] {
26
- return [...Array(10).keys()].map((f) => String(f).repeat(size))
27
- }
28
-
29
- /**
30
- * Multiplica os elementos de uma string com os elementos de outra, ou de um array
31
- * e soma o resultado ao final
32
- *
33
- * @example
34
- * sumElementsByMultipliers('123', '987') //-> 46
35
- * sumElementsByMultipliers('123', [9, 8, 7]) //-> 46
36
- *
37
- * @param {String} value
38
- * @param {String|Array} multiplier
39
- * @returns {Integer} Somatório
40
- */
41
- export function sumElementsByMultipliers(value: string, multiplier: string | number[]): number {
42
- if (typeof multiplier === 'string') multiplier = multiplier.split('').map((n) => Number(n))
43
-
44
- return multiplier.reduce(
45
- (accu: number, curr: any, i: number) => accu + curr * Number(value.charAt(i)),
46
- 0,
47
- )
48
- }
49
-
50
- /**
51
- * fakeNumber()
52
- * Cria um número aleatório com o número de caracteres
53
- *
54
- * @example
55
- * fakeNumber(8, true) // -> 00083159
56
- * fakeNumber(4) // -> 831
57
- *
58
- * @param {Integer} length
59
- * @param {Boolean} forceLength Adiciona zeros à esquerda para ter os números de caractes exatos
60
- * @returns {String}
61
- */
62
- export function fakeNumber(length: number, forceLength: boolean = false): number | string {
63
- const value = (Math.random() * 10 ** length).toFixed(0)
64
-
65
- if (forceLength) return value.padStart(length, '0')
66
-
67
- return +value
68
- }
69
-
70
- /**
71
- * Limpa um número informado, retirando caracteres diferentes de números,
72
- * preenchendo com zeros à esquerda se for menor que o tamanho exato e
73
- * removendo uma parte do número se for maior que tamanho definido.
74
- *
75
- * 1) Retira caracteres não-numéricos
76
- * 2) Preenche com zeros à esquerda se 'value' for menor que 'length'
77
- * 3) Remove caracteres à direita se 'value' for maior que 'length'
78
- *
79
- * @example
80
- * clearValue(12345-6, 6) // -> 123456
81
- * clearValue(12345678, 3) // -> 123
82
- * clearValue(12345, 10) // -> 0000001234
83
- *
84
- * @param {Number|String} value
85
- * @param {Number} length Tamanho exato. Se for null, só retira os caracteres não-numéricos
86
- * @returns {String} Número com o tamanho exato
87
- */
88
- export function clearValue(value: string | number, length: number | null = null): string {
89
- const clearedValue = String(value).replace(/([^\d]+)/gi, '')
90
-
91
- if (!length || clearedValue.length === length) return clearedValue
92
-
93
- if (clearedValue.length > length) return clearedValue.substring(0, length)
94
- return clearedValue.padStart(length, '0')
95
- }
96
-
97
- /**
98
- * insertAtPosition()
99
- * Insere um conjunto de caracteres em um local específico de uma string
100
- *
101
- * @example
102
- * insertAtPosition('AAABBB', 'C', 3) // -> AAACBBB
103
- * insertAtPosition('000011122223445555', 99, 7) // -> 00001119922223445555
104
- *
105
- * @param {String|Number} value Valor original
106
- * @param {String|Number} insertValue Valor que será inserido
107
- * @param {String|Number} position Posição que receberá o novo valor
108
- * @returns {String}
109
- *
110
- */
111
- export function insertAtPosition(value: string, insertValue: string, position: number): string {
112
- return `${value.substring(0, position)}${insertValue}${value.substring(position)}`
113
- }
114
-
115
- /**
116
- * removeFromPosition()
117
- * Retira um conjunto de caracteres de um local específico de uma string
118
- *
119
- * @example
120
- * removeFromPosition('00001119922223445555', 7,9) // -> 000011122223445555
121
- * removeFromPosition('AAACBBB', 3,4) // -> AAABBB
122
- *
123
- * @param {String|Number} value Valor original
124
- * @param {String|Number} startPosition
125
- * @param {String|Number} endPosition
126
- * @returns {String}
127
- *
128
- */
129
- export function removeFromPosition(
130
- value: string,
131
- startPosition: number,
132
- endPosition: number,
133
- ): string {
134
- return [value.slice(0, startPosition), value.slice(endPosition)].join('')
135
- }
136
-
137
- /**
138
- * applyMask()
139
- * Aplica uma máscara a uma string
140
- *
141
- * @example
142
- * applyMask('59650000', '00.000-000') // -> 59.650-000
143
- * applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
144
- *
145
- * @param {String|Number} value Valor original
146
- * @param {String} mask
147
- * @returns {String}
148
- *
149
- */
150
- export function applyMask(value: string | number, mask: string): string {
151
- const maskLen = clearValue(mask).length
152
- let masked = clearValue(value, maskLen)
153
- const specialChars = ['/', '-', '.', '(', ')', ' ']
154
-
155
- for (let position = 0; position < mask.length; position += 1) {
156
- const current = mask[position]
157
- if (specialChars.includes(current)) masked = insertAtPosition(masked, current, position)
158
- }
159
-
160
- return masked
161
- }
162
-
163
- // module.exports = {
164
- // sumToDV,
165
- // invalidListGenerator,
166
- // sumElementsByMultipliers,
167
- // fakeNumber,
168
- // applyMask,
169
- // clearValue,
170
- // insertAtPosition,
171
- // removeFromPosition,
172
- // }