@x-spacy/class-validator 1.4.3 → 1.4.5

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.
@@ -3,7 +3,7 @@ declare module '@x-spacy/class-validator' {
3
3
 
4
4
  export declare function isCPF(document: string): boolean;
5
5
 
6
- export declare function IsRG(document: string): boolean;
6
+ export declare function isRG(document: string): boolean;
7
7
 
8
8
  export declare function isCREF(document: string): boolean;
9
9
 
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ __exportStar(require("./decorators/IsDocument"), exports);
18
18
  __exportStar(require("./enums/DocumentTypeEnum"), exports);
19
19
  __exportStar(require("./services/IsCNPJ"), exports);
20
20
  __exportStar(require("./services/IsCPF"), exports);
21
+ __exportStar(require("./services/IsRG"), exports);
21
22
  __exportStar(require("./services/IsCREF"), exports);
22
23
  __exportStar(require("./services/IsCRM"), exports);
23
24
  __exportStar(require("./services/IsCRN"), exports);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isCNPJ = isCNPJ;
4
4
  function isCNPJ(document) {
5
+ document = document.replace(/[^0-9]/g, '');
5
6
  if (document.length !== 14) {
6
7
  return false;
7
8
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isCPF = isCPF;
4
4
  function isCPF(document) {
5
+ document = document.replace(/[^0-9]/g, '');
5
6
  if (document.length !== 11) {
6
7
  return false;
7
8
  }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsRG = IsRG;
4
+ function IsRG(document) {
5
+ document = document.replace(/[^0-9]/g, '');
6
+ if (document.length !== 9) {
7
+ return false;
8
+ }
9
+ const digits = document.substring(0, 8);
10
+ const firstVerifier = document.charAt(8);
11
+ if (!/^\d{8}$/.test(digits)) {
12
+ return false;
13
+ }
14
+ const weights = [2, 3, 4, 5, 6, 7, 8, 9];
15
+ let sum = 0;
16
+ for (let i = 0; i < 8; i++) {
17
+ const digit = parseInt(digits.charAt(7 - i), 10);
18
+ sum += digit * weights[i];
19
+ }
20
+ const remaining = sum % 11;
21
+ const calculatedVerifiedDigit = 11 - remaining;
22
+ let secondVerifier;
23
+ if (calculatedVerifiedDigit === 11) {
24
+ secondVerifier = '0';
25
+ }
26
+ else if (calculatedVerifiedDigit === 10) {
27
+ secondVerifier = 'X';
28
+ }
29
+ else {
30
+ secondVerifier = calculatedVerifiedDigit.toString();
31
+ }
32
+ return secondVerifier === firstVerifier;
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-spacy/class-validator",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "Validators extension for class-validator lib",
5
5
  "license": "MIT",
6
6
  "private": false,