@nr1e/commons 0.4.3 → 0.4.4

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.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Masks a card number showing the first 6 (BIN) and last 4 which is allowed by
3
+ * PCI. This function will never return the original string even if the card
4
+ * number is an invalid length.
5
+ *
6
+ * @param cardNumber - The card number to mask
7
+ */
8
+ export declare function maskCardNumber(cardNumber: string): string;
9
+ //# sourceMappingURL=card.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card.d.mts","sourceRoot":"","sources":["../../src/business/card.mts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,UAehD"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Masks a card number showing the first 6 (BIN) and last 4 which is allowed by
3
+ * PCI. This function will never return the original string even if the card
4
+ * number is an invalid length.
5
+ *
6
+ * @param cardNumber - The card number to mask
7
+ */
8
+ export function maskCardNumber(cardNumber) {
9
+ cardNumber = cardNumber.trim().replace(/\s+/g, '');
10
+ // If the card length is less than 8, we mask everything to be safe
11
+ if (cardNumber.length < 8) {
12
+ return ''.padEnd(cardNumber.length, '*');
13
+ }
14
+ // If the card length is less than 12 we return everything masked but the last 4
15
+ if (cardNumber.length < 12) {
16
+ return cardNumber.slice(-4).padStart(cardNumber.length, '*');
17
+ }
18
+ return (cardNumber.slice(0, 6) +
19
+ ''.padEnd(cardNumber.length - 10, '*') +
20
+ cardNumber.slice(-4));
21
+ }
22
+ //# sourceMappingURL=card.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card.mjs","sourceRoot":"","sources":["../../src/business/card.mts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,UAAkB;IAC/C,UAAU,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACnD,mEAAmE;IACnE,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC;IACD,gFAAgF;IAChF,IAAI,UAAU,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QAC3B,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,CACL,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;QACtB,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,EAAE,EAAE,GAAG,CAAC;QACtC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=card.test.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card.test.d.mts","sourceRoot":"","sources":["../../src/business/card.test.mts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { test, expect } from 'vitest';
2
+ import { maskCardNumber } from './card.mjs';
3
+ test('Test maskCardNumber', () => {
4
+ let masked = maskCardNumber('4111111111111111');
5
+ expect(masked).toEqual('411111******1111');
6
+ masked = maskCardNumber('4111 1111 1111 1111');
7
+ expect(masked).toEqual('411111******1111');
8
+ masked = maskCardNumber('3782 822463 10005');
9
+ expect(masked).toEqual('378282*****0005');
10
+ masked = maskCardNumber('1234567');
11
+ expect(masked).toEqual('*******');
12
+ masked = maskCardNumber('12345678');
13
+ expect(masked).toEqual('****5678');
14
+ masked = maskCardNumber('1234567890');
15
+ expect(masked).toEqual('******7890');
16
+ });
17
+ //# sourceMappingURL=card.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card.test.mjs","sourceRoot":"","sources":["../../src/business/card.test.mts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAE1C,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC/B,IAAI,MAAM,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAChD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC3C,MAAM,GAAG,cAAc,CAAC,qBAAqB,CAAC,CAAC;IAC/C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC3C,MAAM,GAAG,cAAc,CAAC,mBAAmB,CAAC,CAAC;IAC7C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC1C,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IACnC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAClC,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;IACpC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,MAAM,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;IACtC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC"}
@@ -1,2 +1,3 @@
1
+ export * from './card.mjs';
1
2
  export * from './us-state-to-code.mjs';
2
3
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/business/index.mts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/business/index.mts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC"}
@@ -1,2 +1,3 @@
1
+ export * from './card.mjs';
1
2
  export * from './us-state-to-code.mjs';
2
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/business/index.mts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/business/index.mts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nr1e/commons",
3
3
  "description": "Common utilities for TypeScript projects",
4
- "version": "0.4.3",
4
+ "version": "0.4.4",
5
5
  "type": "module",
6
6
  "author": "NR1E, Inc.",
7
7
  "publishConfig": {
@@ -21,7 +21,7 @@
21
21
  "eslint": "9.39.3",
22
22
  "prettier": "3.8.1",
23
23
  "typescript": "5.9.3",
24
- "typescript-eslint": "8.56.0",
24
+ "typescript-eslint": "8.56.1",
25
25
  "vitest": "4.0.18"
26
26
  },
27
27
  "dependencies": {