@arkyn/server 1.3.74 → 1.3.76
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.
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/package.json +1 -1
- package/src/index.ts +0 -1
- package/src/helpers/validateCPF.ts +0 -38
package/dist/index.d.ts
CHANGED
|
@@ -8,5 +8,4 @@ export { UnprocessableEntityError } from "./httpBadResponses/unprocessableEntity
|
|
|
8
8
|
export { formParse } from "./helpers/formParse";
|
|
9
9
|
export { getScopedParams } from "./helpers/getScopedParams";
|
|
10
10
|
export { globalErrorHandler } from "./helpers/globalErrorHandler";
|
|
11
|
-
export { validateCPF } from "./helpers/validateCPF";
|
|
12
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAGlF,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAGlF,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,4 +10,3 @@ export { UnprocessableEntityError } from "./httpBadResponses/unprocessableEntity
|
|
|
10
10
|
export { formParse } from "./helpers/formParse";
|
|
11
11
|
export { getScopedParams } from "./helpers/getScopedParams";
|
|
12
12
|
export { globalErrorHandler } from "./helpers/globalErrorHandler";
|
|
13
|
-
export { validateCPF } from "./helpers/validateCPF";
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,4 +11,3 @@ export { UnprocessableEntityError } from "./httpBadResponses/unprocessableEntity
|
|
|
11
11
|
export { formParse } from "./helpers/formParse";
|
|
12
12
|
export { getScopedParams } from "./helpers/getScopedParams";
|
|
13
13
|
export { globalErrorHandler } from "./helpers/globalErrorHandler";
|
|
14
|
-
export { validateCPF } from "./helpers/validateCPF";
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
function removeNonDigits(cpf: string) {
|
|
2
|
-
return cpf.replace(/\D/g, "");
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function isInvalidLength(cpf: string) {
|
|
6
|
-
const CPF_LENGTH = 11;
|
|
7
|
-
return cpf.length !== CPF_LENGTH;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function hasAllDigitsEqual(cpf: string) {
|
|
11
|
-
const [firstCpfDigit] = cpf;
|
|
12
|
-
return [...cpf].every((digit) => digit === firstCpfDigit);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function calculateDigit(cpf: string, factor: number) {
|
|
16
|
-
let total = 0;
|
|
17
|
-
for (const digit of cpf) {
|
|
18
|
-
if (factor > 1) total += parseInt(digit) * factor--;
|
|
19
|
-
}
|
|
20
|
-
const rest = total % 11;
|
|
21
|
-
return rest < 2 ? 0 : 11 - rest;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function extractDigit(cpf: string) {
|
|
25
|
-
return cpf.slice(9);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function validateCPF(rawCpf: string) {
|
|
29
|
-
if (!rawCpf) return false;
|
|
30
|
-
const cpf = removeNonDigits(rawCpf);
|
|
31
|
-
if (isInvalidLength(cpf)) return false;
|
|
32
|
-
if (hasAllDigitsEqual(cpf)) return false;
|
|
33
|
-
const digit1 = calculateDigit(cpf, 10);
|
|
34
|
-
const digit2 = calculateDigit(cpf, 11);
|
|
35
|
-
return extractDigit(cpf) === `${digit1}${digit2}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { validateCPF };
|