validation-br 1.0.0-b → 1.2.0-rc2

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 (111) hide show
  1. package/.eslintcache +1 -0
  2. package/{src/cnh.ts → dist/cnh.d.ts} +91 -140
  3. package/dist/cnh.js +9 -4
  4. package/dist/cnh.js.map +1 -1
  5. package/dist/cnh.test.d.ts +1 -0
  6. package/{src/cnpj.ts → dist/cnpj.d.ts} +82 -128
  7. package/dist/cnpj.js +8 -3
  8. package/dist/cnpj.js.map +1 -1
  9. package/dist/cnpj.test.d.ts +1 -0
  10. package/{src/cpf.ts → dist/cpf.d.ts} +99 -150
  11. package/dist/cpf.js +7 -5
  12. package/dist/cpf.js.map +1 -1
  13. package/dist/cpf.test.d.ts +1 -0
  14. package/dist/index.d.ts +12 -0
  15. package/dist/index.js +2 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.test.d.ts +1 -0
  18. package/{src/judicialProcess.ts → dist/judicialProcess.d.ts} +114 -167
  19. package/dist/judicialProcess.js +13 -6
  20. package/dist/judicialProcess.js.map +1 -1
  21. package/dist/judicialProcess.test.d.ts +1 -0
  22. package/dist/nup17.d.ts +102 -0
  23. package/dist/nup17.js +145 -0
  24. package/dist/nup17.js.map +1 -0
  25. package/dist/nup17.test.d.ts +1 -0
  26. package/{src/pisPasep.ts → dist/pisPasep.d.ts} +81 -128
  27. package/dist/pisPasep.js +4 -2
  28. package/dist/pisPasep.js.map +1 -1
  29. package/dist/pisPasep.test.d.ts +1 -0
  30. package/dist/postalCode.d.ts +83 -0
  31. package/dist/postalCode.js +4 -2
  32. package/dist/postalCode.js.map +1 -1
  33. package/dist/postalCode.test.d.ts +1 -0
  34. package/{src/renavam.ts → dist/renavam.d.ts} +75 -122
  35. package/dist/renavam.js +4 -2
  36. package/dist/renavam.js.map +1 -1
  37. package/dist/renavam.test.d.ts +1 -0
  38. package/{src/tituloEleitor.ts → dist/tituloEleitor.d.ts} +93 -146
  39. package/dist/tituloEleitor.js +4 -2
  40. package/dist/tituloEleitor.js.map +1 -1
  41. package/dist/tituloEleitor.test.d.ts +1 -0
  42. package/dist/utils-applyMask.test.d.ts +1 -0
  43. package/dist/utils-clearValue.test.d.ts +1 -0
  44. package/dist/utils-fakeNumber.test.d.ts +1 -0
  45. package/dist/utils-insertAtPosition.test.d.ts +1 -0
  46. package/dist/utils-invalidListGenerator.test.d.ts +1 -0
  47. package/dist/utils-removeFromPosition.test.d.ts +1 -0
  48. package/dist/utils-sumElementsByMultipliers.test.d.ts +1 -0
  49. package/dist/utils-sumToDV.test.d.ts +1 -0
  50. package/{src/utils.ts → dist/utils.d.ts} +111 -172
  51. package/dist/utils.js +2 -2
  52. package/dist/utils.js.map +1 -1
  53. package/dist/vuelidate.d.ts +36 -0
  54. package/dist/vuelidate.js +31 -0
  55. package/dist/vuelidate.js.map +1 -0
  56. package/package.json +68 -2
  57. package/readme.md +75 -18
  58. package/tsconfig.json +1 -0
  59. package/dist/cnh.test.js +0 -117
  60. package/dist/cnh.test.js.map +0 -1
  61. package/dist/cnpj.test.js +0 -141
  62. package/dist/cnpj.test.js.map +0 -1
  63. package/dist/cpf.test.js +0 -130
  64. package/dist/cpf.test.js.map +0 -1
  65. package/dist/index.test.js +0 -33
  66. package/dist/index.test.js.map +0 -1
  67. package/dist/judicialProcess.test.js +0 -123
  68. package/dist/judicialProcess.test.js.map +0 -1
  69. package/dist/pisPasep.test.js +0 -129
  70. package/dist/pisPasep.test.js.map +0 -1
  71. package/dist/postalCode.test.js +0 -135
  72. package/dist/postalCode.test.js.map +0 -1
  73. package/dist/renavam.test.js +0 -113
  74. package/dist/renavam.test.js.map +0 -1
  75. package/dist/tituloEleitor.test.js +0 -132
  76. package/dist/tituloEleitor.test.js.map +0 -1
  77. package/dist/utils-applyMask.test.js +0 -17
  78. package/dist/utils-applyMask.test.js.map +0 -1
  79. package/dist/utils-clearValue.test.js +0 -50
  80. package/dist/utils-clearValue.test.js.map +0 -1
  81. package/dist/utils-fakeNumber.test.js +0 -17
  82. package/dist/utils-fakeNumber.test.js.map +0 -1
  83. package/dist/utils-insertAtPosition.test.js +0 -16
  84. package/dist/utils-insertAtPosition.test.js.map +0 -1
  85. package/dist/utils-invalidListGenerator.test.js +0 -23
  86. package/dist/utils-invalidListGenerator.test.js.map +0 -1
  87. package/dist/utils-removeFromPosition.test.js +0 -16
  88. package/dist/utils-removeFromPosition.test.js.map +0 -1
  89. package/dist/utils-sumElementsByMultipliers.test.js +0 -32
  90. package/dist/utils-sumElementsByMultipliers.test.js.map +0 -1
  91. package/dist/utils-sumToDV.test.js +0 -16
  92. package/dist/utils-sumToDV.test.js.map +0 -1
  93. package/src/cnh.test.ts +0 -114
  94. package/src/cnpj.test.ts +0 -136
  95. package/src/cpf.test.ts +0 -125
  96. package/src/index.test.ts +0 -35
  97. package/src/index.ts +0 -19
  98. package/src/judicialProcess.test.ts +0 -118
  99. package/src/pisPasep.test.ts +0 -124
  100. package/src/postalCode.test.ts +0 -132
  101. package/src/postalCode.ts +0 -164
  102. package/src/renavam.test.ts +0 -110
  103. package/src/tituloEleitor.test.ts +0 -129
  104. package/src/utils-applyMask.test.ts +0 -17
  105. package/src/utils-clearValue.test.ts +0 -55
  106. package/src/utils-fakeNumber.test.ts +0 -19
  107. package/src/utils-insertAtPosition.test.ts +0 -15
  108. package/src/utils-invalidListGenerator.test.ts +0 -27
  109. package/src/utils-removeFromPosition.test.ts +0 -15
  110. package/src/utils-sumElementsByMultipliers.test.ts +0 -34
  111. package/src/utils-sumToDV.test.ts +0 -16
@@ -1,172 +1,111 @@
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, 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
- // }
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
+ * Cria uma lista de valores repetidos no tamanho do documento para eliminar
12
+ * valores que já conhecemos como inválidos
13
+ *
14
+ * @example
15
+ * invalidListGenerator(10, 11)
16
+ * //-> [00000000000, 11111111111, ....., 99999999999]
17
+ *
18
+ * @param {Integer} length Número de itens do array
19
+ * @param {Integer} size Tamanho da string gerada
20
+ * @returns {Array} Lista de valores
21
+ */
22
+ export declare function invalidListGenerator(size: number): string[];
23
+ /**
24
+ * Multiplica os elementos de uma string com os elementos de outra, ou de um array
25
+ * e soma o resultado ao final
26
+ *
27
+ * @example
28
+ * sumElementsByMultipliers('123', '987') //-> 46
29
+ * sumElementsByMultipliers('123', [9, 8, 7]) //-> 46
30
+ *
31
+ * @param {String} value
32
+ * @param {String|Array} multiplier
33
+ * @returns {Integer} Somatório
34
+ */
35
+ export declare function sumElementsByMultipliers(value: string, multiplier: string | number[]): number;
36
+ /**
37
+ * fakeNumber()
38
+ * Cria um número aleatório com o número de caracteres
39
+ *
40
+ * @example
41
+ * fakeNumber(8, true) // -> 00083159
42
+ * fakeNumber(4) // -> 831
43
+ *
44
+ * @param {Integer} length
45
+ * @param {Boolean} forceLength Adiciona zeros à esquerda para ter os números de caractes exatos
46
+ * @returns {String}
47
+ */
48
+ export declare function fakeNumber(length: number, forceLength?: boolean): number | string;
49
+ /**
50
+ * Limpa um número informado, retirando caracteres diferentes de números,
51
+ * preenchendo com zeros à esquerda se for menor que o tamanho exato e
52
+ * removendo uma parte do número se for maior que tamanho definido.
53
+ *
54
+ * 1) Retira caracteres não-numéricos
55
+ * 2) Preenche com zeros à esquerda se 'value' for menor que 'length'
56
+ * 3) Remove caracteres à direita se 'value' for maior que 'length'
57
+ *
58
+ * @example
59
+ * clearValue(12345-6, 6) // -> 123456
60
+ * clearValue(12345678, 3) // -> 123
61
+ * clearValue(12345, 10) // -> 0000001234
62
+ *
63
+ * @param {Number|String} value
64
+ * @param {Number} length Tamanho exato. Se for null, só retira os caracteres não-numéricos
65
+ * @returns {String} Número com o tamanho exato
66
+ */
67
+ export declare function clearValue(value: string | number, length?: number | null): string;
68
+ /**
69
+ * insertAtPosition()
70
+ * Insere um conjunto de caracteres em um local específico de uma string
71
+ *
72
+ * @example
73
+ * insertAtPosition('AAABBB', 'C', 3) // -> AAACBBB
74
+ * insertAtPosition('000011122223445555', 99, 7) // -> 00001119922223445555
75
+ *
76
+ * @param {String|Number} value Valor original
77
+ * @param {String|Number} insertValue Valor que será inserido
78
+ * @param {String|Number} position Posição que receberá o novo valor
79
+ * @returns {String}
80
+ *
81
+ */
82
+ export declare function insertAtPosition(value: string, insertValue: string, position: number): string;
83
+ /**
84
+ * removeFromPosition()
85
+ * Retira um conjunto de caracteres de um local específico de uma string
86
+ *
87
+ * @example
88
+ * removeFromPosition('00001119922223445555', 7,9) // -> 000011122223445555
89
+ * removeFromPosition('AAACBBB', 3,4) // -> AAABBB
90
+ *
91
+ * @param {String|Number} value Valor original
92
+ * @param {String|Number} startPosition
93
+ * @param {String|Number} endPosition
94
+ * @returns {String}
95
+ *
96
+ */
97
+ export declare function removeFromPosition(value: string, startPosition: number, endPosition: number): string;
98
+ /**
99
+ * applyMask()
100
+ * Aplica uma máscara a uma string
101
+ *
102
+ * @example
103
+ * applyMask('59650000', '00.000-000') // -> 59.650-000
104
+ * applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
105
+ *
106
+ * @param {String|Number} value Valor original
107
+ * @param {String} mask
108
+ * @returns {String}
109
+ *
110
+ */
111
+ export declare function applyMask(value: string | number, mask: string): string;
package/dist/utils.js CHANGED
@@ -60,9 +60,9 @@ exports.sumElementsByMultipliers = sumElementsByMultipliers;
60
60
  * @returns {String}
61
61
  */
62
62
  function fakeNumber(length, forceLength = false) {
63
- const value = (Math.random() * Math.pow(10, length)).toFixed(0);
63
+ const value = Math.floor(Math.random() * Math.pow(10, length));
64
64
  if (forceLength)
65
- return value.padStart(length, '0');
65
+ return String(value).padStart(length, '0');
66
66
  return +value;
67
67
  }
68
68
  exports.fakeNumber = fakeNumber;
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAC,GAAW;IACjC,OAAO,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAA;AAC3C,CAAC;AAFD,0BAEC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,OAAO,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CA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AC,EAAE,CAAC,CAAA;AAC3E,CAAC;AAND,gDAMC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,SAAS,CAAC,KAAsB,EAAE,IAAY;IAC5D,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,CAAA;IACvC,IAAI,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IACvC,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;IAEnD,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC,EAAE;QAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC9B,IAAI,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,MAAM,GAAG,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;KACzF;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAXD,8BAWC;AAED,qBAAqB;AACrB,aAAa;AACb,0BAA0B;AAC1B,8BAA8B;AAC9B,gBAAgB;AAChB,eAAe;AACf,gBAAgB;AAChB,sBAAsB;AACtB,wBAAwB;AACxB,IAAI"}
@@ -0,0 +1,36 @@
1
+ export declare const cnh: {
2
+ $validator: (value: string | number) => boolean;
3
+ $message: string;
4
+ };
5
+ export declare const cpf: {
6
+ $validator: (value: string | number) => boolean;
7
+ $message: string;
8
+ };
9
+ export declare const cnpj: {
10
+ $validator: (value: string | number) => boolean;
11
+ $message: string;
12
+ };
13
+ export declare const renavam: {
14
+ $validator: (value: string | number) => boolean;
15
+ $message: string;
16
+ };
17
+ export declare const judicialProcess: {
18
+ $validator: (value: string) => boolean;
19
+ $message: string;
20
+ };
21
+ export declare const nup17: {
22
+ $validator: (value: string) => boolean;
23
+ $message: string;
24
+ };
25
+ export declare const postalCode: {
26
+ $validator: (value: string) => boolean;
27
+ $message: string;
28
+ };
29
+ export declare const tituloEleitor: {
30
+ $validator: (value: string | number) => boolean;
31
+ $message: string;
32
+ };
33
+ export declare const pisPasep: {
34
+ $validator: (value: string | number) => boolean;
35
+ $message: string;
36
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pisPasep = exports.tituloEleitor = exports.postalCode = exports.nup17 = exports.judicialProcess = exports.renavam = exports.cnpj = exports.cpf = exports.cnh = void 0;
4
+ const cnh_1 = require("./cnh");
5
+ const cpf_1 = require("./cpf");
6
+ const cnpj_1 = require("./cnpj");
7
+ const renavam_1 = require("./renavam");
8
+ const judicialProcess_1 = require("./judicialProcess");
9
+ const nup17_1 = require("./nup17");
10
+ const postalCode_1 = require("./postalCode");
11
+ const tituloEleitor_1 = require("./tituloEleitor");
12
+ const pisPasep_1 = require("./pisPasep");
13
+ exports.cnh = { $validator: cnh_1.validateOrFail, $message: 'CNH inválido' };
14
+ exports.cpf = { $validator: cpf_1.validateOrFail, $message: 'CNPJ inválido' };
15
+ exports.cnpj = { $validator: cnpj_1.validateOrFail, $message: 'CPF inválido' };
16
+ exports.renavam = { $validator: renavam_1.validateOrFail, $message: 'Renavam inválido' };
17
+ exports.judicialProcess = {
18
+ $validator: judicialProcess_1.validateOrFail,
19
+ $message: 'JudicialProcess inválido',
20
+ };
21
+ exports.nup17 = { $validator: nup17_1.validateOrFail, $message: 'NUP17 inválido' };
22
+ exports.postalCode = {
23
+ $validator: postalCode_1.validateOrFail,
24
+ $message: 'PostalCode inválido',
25
+ };
26
+ exports.tituloEleitor = {
27
+ $validator: tituloEleitor_1.validateOrFail,
28
+ $message: 'TituloEleitor inválido',
29
+ };
30
+ exports.pisPasep = { $validator: pisPasep_1.validateOrFail, $message: 'PIS inválido' };
31
+ //# sourceMappingURL=vuelidate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vuelidate.js","sourceRoot":"","sources":["../src/vuelidate.ts"],"names":[],"mappings":";;;AAAA,+BAA+C;AAC/C,+BAAgD;AAChD,iCAAgD;AAChD,uCAAuD;AACvD,uDAAuE;AACvE,mCAAmD;AACnD,6CAA6D;AAC7D,mDAAmE;AACnE,yCAAoD;AAEvC,QAAA,GAAG,GAAG,EAAE,UAAU,EAAE,oBAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAA;AACrD,QAAA,GAAG,GAAG,EAAE,UAAU,EAAE,oBAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;AACvD,QAAA,IAAI,GAAG,EAAE,UAAU,EAAE,qBAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAA;AACtD,QAAA,OAAO,GAAG,EAAE,UAAU,EAAE,wBAAS,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAA;AACjE,QAAA,eAAe,GAAG;IAC7B,UAAU,EAAE,gCAAiB;IAC7B,QAAQ,EAAE,0BAA0B;CACrC,CAAA;AACY,QAAA,KAAK,GAAG,EAAE,UAAU,EAAE,sBAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA;AAC3D,QAAA,UAAU,GAAG;IACxB,UAAU,EAAE,2BAAY;IACxB,QAAQ,EAAE,qBAAqB;CAChC,CAAA;AACY,QAAA,aAAa,GAAG;IAC3B,UAAU,EAAE,8BAAe;IAC3B,QAAQ,EAAE,wBAAwB;CACnC,CAAA;AACY,QAAA,QAAQ,GAAG,EAAE,UAAU,EAAE,yBAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "validation-br",
3
- "version": "1.0.0-b",
3
+ "description": "Brazilian personal documents validation - cpf, cnpj, titulo, pis/pasep, cnh, renavam, processos judiciais, protocolo federal, código de rastreamento dos correios",
4
+ "version": "1.2.0-rc2",
4
5
  "main": "dist/index.js",
6
+ "exports": {
7
+ ".": "./dist",
8
+ "./vuelidate": "./dist/vuelidate"
9
+ },
5
10
  "types": "./dist/types.d.ts",
6
11
  "author": "Cláudio Medeiros <klawdyo@gmail.com>",
7
12
  "license": "MIT",
@@ -44,5 +49,66 @@
44
49
  "ts-jest": "^27.1.2",
45
50
  "ts-node": "^9.0.0",
46
51
  "typescript": "^4.0.3"
47
- }
52
+ },
53
+ "repository": {
54
+ "url": "https://github.com/klawdyo/validation-br"
55
+ },
56
+ "bugs": {
57
+ "url": "https://github.com/klawdyo/validation-br/issues"
58
+ },
59
+ "homepage": "https://github.com/klawdyo/validation-br#readme",
60
+ "keywords": [
61
+ "validation-br",
62
+ "validation",
63
+ "personal documents",
64
+ "document",
65
+ "brazil",
66
+ "brasil",
67
+ "brazilian",
68
+ "brasileiro",
69
+ "cpf",
70
+ "cnpj",
71
+ "pis",
72
+ "pasep",
73
+ "cnh",
74
+ "titulo eleitor",
75
+ "eleitoral",
76
+ "titulo",
77
+ "renavam",
78
+ "processos",
79
+ "judiciais",
80
+ "judicial",
81
+ "justiça",
82
+ "protocolo",
83
+ "federal",
84
+ "fake",
85
+ "falso",
86
+ "mock",
87
+ "faker",
88
+ "mockup",
89
+ "mask",
90
+ "mascara",
91
+ "fake cpf",
92
+ "fake cnpj",
93
+ "fake cnh",
94
+ "fake pis",
95
+ "fake pasep",
96
+ "fake cadunico",
97
+ "fake renavam",
98
+ "fake titulo",
99
+ "fake titulo eleitor",
100
+ "fake titulo eleitoral",
101
+ "fake número processo",
102
+ "processo justiça",
103
+ "processo judicial",
104
+ "valida",
105
+ "validar",
106
+ "validação",
107
+ "valide",
108
+ "validate",
109
+ "format",
110
+ "formatar",
111
+ "formatador",
112
+ "formatter"
113
+ ]
48
114
  }
package/readme.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # validation-br
2
2
 
3
- Biblioteca de validação de documentos pessoais do Brasil com suporte a CPF, CNPJ, Título Eleitoral, PIS/PASEP, CNH. Também valida numerações de outros tipos de registros como RENAVAM, Processos Judiciais e Objetos registrados de Rastreamento dos Correios.
4
-
5
- Validation-BR também permite a criação de números fake das numerações acima para fins de teste de desenvolvimento, além de aplicação de máscaras e cálculo do dígito verificador.
3
+ Biblioteca de validação de documentos pessoais do Brasil com suporte a CPF, CNPJ, Título Eleitoral, PIS/PASEP, CNH. Também valida numerações de outros tipos de registros como RENAVAM, Processos Judiciais, Número de Protocolo do Governo Federal e Objetos registrados de Rastreamento dos Correios.
6
4
 
7
5
  Validation-BR também permite criação de números fake para facilitar o desenvolvimento e testes, além de aplicar máscaras e calcular somente os dígitos verificadores.
8
6
 
@@ -71,6 +69,7 @@ cpf.validateOrFail('01234567890') // -> true
71
69
  - [isCNH](#isCNH-value-) - Validação do CNH
72
70
  - [isCPF](#isCPF-value-) - Validação do CPF
73
71
  - [isCNPJ](#isCNPJ-value-) - Validação do CNPJ
72
+ - [isNUP17](#isNUP17-value-) - Validação de Número Unificado de Protocolo do Governo Federal
74
73
  - [isPostalCode](#isPostalCode-value-) - Validação de Objetos Registrados dos Correios
75
74
  - [isJudicialProcess](#isJudicialProcess-value-) - Validação de Números de Processos Judiciais
76
75
  - [isPIS](#isPIS-value-) - Validação de PIS, PASEP, NIS e NIT
@@ -167,31 +166,86 @@ cpf.dv('012345678') // -> '90'
167
166
 
168
167
  ### isJudicialProcess( `value` )
169
168
 
170
- Valida códigos PIS, PASEP, NIS e NIT, que usam o mesmo algoritmo. Aceita números com e sem pontos e traços.
169
+ Valida números de processo da esfera judicial. Esta padronização foi adotada em 2010 e de para todos os processos judiciais abertos no país seguem o mesmo padrão, seja eleitoral, cível, militar etc.
170
+
171
+ O número é composto por 6 partes:
172
+
173
+ 1. Número sequencial dado pelo órgão de registro, reiniciado a cada ano, com até 7 caracteres
174
+ 2. Dígito verificador com 2 caracteres
175
+ 3. Ano de registro com 4 caracteres
176
+ 4. Órgão do poder judiciário com 1 caractere, sendo eles:
177
+
178
+ - 1 - Supremo Tribunal Federal
179
+ - 2 - Conselho Nacional de Justiça
180
+ - 3 - Superior Tribunal de Justiça
181
+ - 4 - Justiça Federal
182
+ - 5 - Justiça do Trabalho
183
+ - 6 - Justiça Eleitoral
184
+ - 7 - Justiça Militar da União
185
+ - 8 - Justiça dos Estados e do Distrito Federal e Territórios
186
+ - 9 - Justiça Militar Estadual
187
+
188
+ 5. Tribunal do segmento do poder judiciário com 2 caracteres
189
+ 6. Código da unidade de origem do processo com 4 caracteres
171
190
 
172
191
  ```js
173
192
  // Importação somente da validação
174
193
  import { isJudicialProcess } from 'validation-br'
175
194
  // ou
176
195
  // Importação do submódulo
177
- import judicialProcess from 'validation-br/judicial-process'
196
+ import judicialProcess from 'validation-br/judicialProcess'
197
+
198
+ // Valida
199
+ isJudicialProcess('20802520125150049') //-> true
200
+ isJudicialProcess('0011006-07.2016.8.20.0100') //-> true
201
+ isJudicialProcess('00110060720168200101') //-> false
202
+ judicialProcess.validate('00110060720168200100') //-> true
203
+ judicialProcess.validateOrFail('00110060720168200100') //-> true
204
+
205
+ // Número fake com e sem máscara
206
+ judicialProcess.fake() // -> 00110060720168200100
207
+ judicialProcess.fake(true) // -> 0011006-07.2016.8.20.0100
208
+
209
+ // Aplica uma máscara
210
+ judicialProcess.mask('00110060720168200100') // -> 0011006-07.2016.8.20.0100
211
+
212
+ // Calcula o DV.
213
+ // Obs.: Antes do cálculo, é necessário que o número do processo não possua o dígito verificador para que o resultado seja correto. Isso é necessário pois o DV fica no meio da numeração, na posição 8 e 9.
214
+ judicialProcess.dv('001100620168200100') // -> '07'
215
+ ```
216
+
217
+ ### isNUP17( `value` )
218
+
219
+ Válida um Número Unificado de Protocolo de 17 dígitos. Esta numeração é usada pelo Governo Federal como forma única de numerar processos em todas os órgãos do executivo.
220
+
221
+ 1. Os primeiros 5 dígitos correspondem código do órgão
222
+ 2. Os dígitos de 6 a 11 são um número sequencial dado pelo órgão em questão e é reiniciado a cada ano
223
+ 3. Os dígitos 12 a 15 representam o ano de registro do protocolo
224
+ 4. Os caracteres 16 a 17 são o dígito verificador
225
+
226
+ ```js
227
+ // Importação somente da validação
228
+ import { isNUP17 } from 'validation-br'
229
+ // ou
230
+ // Importação do submódulo
231
+ import nup from 'validation-br/nup17'
178
232
 
179
233
  // Valida
180
- isJudicialProcess('71282677380') //-> true
181
- isJudicialProcess('237.95126.95-5') //-> true
182
- isJudicialProcess('500.12973.80-1') //-> false
183
- judicialProcess.validate('71282677380') //-> true
184
- judicialProcess.validateOrFail('71282677380') //-> true
234
+ isNUP17('23037001462202165') //-> true
235
+ isNUP17('23037.001462/2021-65') //-> true
236
+ isNUP17('23037.001462/2021-66') //-> false
237
+ nup.validate('23037.001462/2021-65') //-> true
238
+ nup.validateOrFail('23037.001462/2021-65') //-> true
185
239
 
186
240
  // Número fake com e sem máscara
187
- judicialProcess.fake() // -> 71282677380
188
- judicialProcess.fake(true) // -> 712.82677.38-0
241
+ nup.fake() // -> 71282677380
242
+ nup.fake(true) // -> 712.82677.38-0
189
243
 
190
244
  // Aplica uma máscara
191
- judicialProcess.mask('71282677380') // -> 712.82677.38-0
245
+ nup.mask('23037001462202165') // -> 23037.001462/2021-65
192
246
 
193
247
  // Calcula o DV
194
- judicialProcess.dv('7128267738') // -> '0'
248
+ nup.dv('230370014622021') // -> '65'
195
249
  ```
196
250
 
197
251
  ### isPIS( `value` )
@@ -237,7 +291,7 @@ Valida um código de rastreamento de objetos postais no formato XX00000000DYY, o
237
291
  import { isPostalCode } from 'validation-br'
238
292
  // ou
239
293
  // Importação do submódulo
240
- import postalCode from 'validation-br/postal-code'
294
+ import postalCode from 'validation-br/postalCode'
241
295
 
242
296
  // Valida
243
297
  isPostalCode('PN718252423BR') //-> true
@@ -296,7 +350,7 @@ Valida um título eleitoral
296
350
  import { isTituloEleitor } from 'validation-br'
297
351
  // ou
298
352
  // Importação do submódulo
299
- import titulo from 'validation-br/titulo'
353
+ import titulo from 'validation-br/tituloEleitor'
300
354
 
301
355
  // Valida
302
356
  isTituloEleitor('743650641660') //-> true
@@ -316,12 +370,14 @@ titulo.mask('525028881694') // -> 5250.2888.1694
316
370
  titulo.dv('5250288816') // -> '94'
317
371
  ```
318
372
 
319
- # Tests
373
+ # Testes
320
374
 
321
- ![image](https://user-images.githubusercontent.com/100168/148705528-7c810b3c-851a-49c4-bc08-f9631498d526.png)
375
+ ![Testes](https://user-images.githubusercontent.com/100168/148857050-df40e291-a13d-4643-b64d-6603cf0a06f1.png)
322
376
 
323
377
  # Changelog
324
378
 
379
+ - **10/01/2022**:
380
+ - 1.1.0 - Adicionado NUP17 - Número Unificado de Protocolo de 17 dígitos do Governo Federal
325
381
  - **09/01/2022**:
326
382
  - 1.0.0 - Biblioteca convertida para Typescript e testes convertidos para Jest
327
383
  - **08/01/2022**:
@@ -340,3 +396,4 @@ titulo.dv('5250288816') // -> '94'
340
396
  - [Diferença entre PIS, PASEP, NIS e NIT](https://www.jornalcontabil.com.br/entenda-de-uma-vez-a-diferenca-entre-pis-pasep-nit-e-nis/#:~:text=NIS%20%E2%80%93%20N%C3%BAmero%20de%20Identifica%C3%A7%C3%A3o%20Social,do%20Patrim%C3%B4nio%20do%20Servidor%20P%C3%BAblico)
341
397
  - [Documentação Oficial de Numeração de Processos Judiciais](https://juslaboris.tst.jus.br/bitstream/handle/20.500.12178/30318/2008_res0065_cnj_rep01.pdf?sequence=2)
342
398
  - [Cálculos de DV](http://ghiorzi.org/DVnew.htm)
399
+ - [Cálculo do NUP17](https://www.gov.br/compras/pt-br/acesso-a-informacao/legislacao/portarias/portaria-interministerial-no-11-de-25-de-novembro-de-2019)
package/tsconfig.json CHANGED
@@ -7,6 +7,7 @@
7
7
  "moduleResolution": "node",
8
8
  "sourceMap": true,
9
9
  "outDir": "./dist",
10
+ "declaration": true,
10
11
  "noImplicitAny": true,
11
12
  "noImplicitReturns": true,
12
13
  "noImplicitThis": true,