@escapenavigator/utils 2.0.43 → 2.0.45

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 CHANGED
@@ -22,16 +22,17 @@ export * from './image-url';
22
22
  export * from './is-axios-error';
23
23
  export * from './is-network-error';
24
24
  export * from './is-stale-chunk-error';
25
+ export * from './is-valid-pt-nif';
25
26
  export * from './phone';
26
27
  export * from './pick';
27
28
  export * from './promocode-error-codes';
28
29
  export * from './promocode-nominal-rules';
29
30
  export * from './redirect';
30
31
  export * from './resolve-calendar-location-id';
32
+ export * from './role-bonus-permissions';
31
33
  export * from './role-chat-permissions';
32
34
  export * from './role-comment-permissions';
33
35
  export * from './role-export-permissions';
34
- export * from './role-bonus-permissions';
35
36
  export * from './role-refund-permissions';
36
37
  export * from './serialize-record';
37
38
  export * from './serialize-slot';
package/dist/index.js CHANGED
@@ -38,16 +38,17 @@ __exportStar(require("./image-url"), exports);
38
38
  __exportStar(require("./is-axios-error"), exports);
39
39
  __exportStar(require("./is-network-error"), exports);
40
40
  __exportStar(require("./is-stale-chunk-error"), exports);
41
+ __exportStar(require("./is-valid-pt-nif"), exports);
41
42
  __exportStar(require("./phone"), exports);
42
43
  __exportStar(require("./pick"), exports);
43
44
  __exportStar(require("./promocode-error-codes"), exports);
44
45
  __exportStar(require("./promocode-nominal-rules"), exports);
45
46
  __exportStar(require("./redirect"), exports);
46
47
  __exportStar(require("./resolve-calendar-location-id"), exports);
48
+ __exportStar(require("./role-bonus-permissions"), exports);
47
49
  __exportStar(require("./role-chat-permissions"), exports);
48
50
  __exportStar(require("./role-comment-permissions"), exports);
49
51
  __exportStar(require("./role-export-permissions"), exports);
50
- __exportStar(require("./role-bonus-permissions"), exports);
51
52
  __exportStar(require("./role-refund-permissions"), exports);
52
53
  __exportStar(require("./serialize-record"), exports);
53
54
  __exportStar(require("./serialize-slot"), exports);
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Portuguese NIF checksum (9 digits).
3
+ * Used for company bookings that must appear on a fatura.
4
+ */
5
+ export declare const isValidPtNif: (value?: string | null) => boolean;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidPtNif = void 0;
4
+ /**
5
+ * Portuguese NIF checksum (9 digits).
6
+ * Used for company bookings that must appear on a fatura.
7
+ */
8
+ const isValidPtNif = (value) => {
9
+ const nif = (value || '').replace(/\s+/g, '');
10
+ if (!/^\d{9}$/.test(nif))
11
+ return false;
12
+ const digits = nif.split('').map(Number);
13
+ const sum = digits.slice(0, 8).reduce((acc, digit, index) => acc + digit * (9 - index), 0);
14
+ const check = 11 - (sum % 11);
15
+ const expected = check >= 10 ? 0 : check;
16
+ return digits[8] === expected;
17
+ };
18
+ exports.isValidPtNif = isValidPtNif;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_valid_pt_nif_1 = require("./is-valid-pt-nif");
4
+ describe('isValidPtNif', () => {
5
+ it('принимает валидный NIF и контрольную сумму Consumidor final', () => {
6
+ expect((0, is_valid_pt_nif_1.isValidPtNif)('123456789')).toBe(true);
7
+ expect((0, is_valid_pt_nif_1.isValidPtNif)('999999990')).toBe(true);
8
+ });
9
+ it('игнорирует пробелы', () => {
10
+ expect((0, is_valid_pt_nif_1.isValidPtNif)('123 456 789')).toBe(true);
11
+ });
12
+ it('отклоняет неверную контрольную сумму и мусор', () => {
13
+ expect((0, is_valid_pt_nif_1.isValidPtNif)('123456780')).toBe(false);
14
+ expect((0, is_valid_pt_nif_1.isValidPtNif)('12345678')).toBe(false);
15
+ expect((0, is_valid_pt_nif_1.isValidPtNif)('1234567890')).toBe(false);
16
+ expect((0, is_valid_pt_nif_1.isValidPtNif)('abcdefghi')).toBe(false);
17
+ expect((0, is_valid_pt_nif_1.isValidPtNif)('')).toBe(false);
18
+ expect((0, is_valid_pt_nif_1.isValidPtNif)(null)).toBe(false);
19
+ expect((0, is_valid_pt_nif_1.isValidPtNif)(undefined)).toBe(false);
20
+ });
21
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escapenavigator/utils",
3
- "version": "2.0.43",
3
+ "version": "2.0.45",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,7 +14,7 @@
14
14
  "test": "jest"
15
15
  },
16
16
  "dependencies": {
17
- "@escapenavigator/types": "^2.0.41",
17
+ "@escapenavigator/types": "^2.0.43",
18
18
  "axios": "^0.21.4",
19
19
  "class-transformer": "^0.5.1",
20
20
  "class-validator": "^0.13.2",
@@ -29,5 +29,5 @@
29
29
  "ts-jest": "^29.1.1",
30
30
  "typescript": "^5.6"
31
31
  },
32
- "gitHead": "172991f54640cc07919daa4ef4b27efc8951a17e"
32
+ "gitHead": "b5ab364dee021328bca9464dc4f9bd56774bcb52"
33
33
  }