@open-tender/utils 0.5.33 → 0.5.35

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.
@@ -14,6 +14,7 @@ export declare const cardNumbersRegex: {
14
14
  };
15
15
  export declare const getCardType: (cardNumber: string) => CardType;
16
16
  export declare const makeNumeric: (str: string) => string;
17
+ export declare const makeAlphaNumeric: (str: string) => string;
17
18
  export declare const makeAcctNumber: (str: string, cardType: CardType) => string;
18
19
  export declare const formatCardField: (field: keyof CreditCardData, value: string) => string;
19
20
  export declare const formatCard: (card: CreditCardData | null) => [CreditCardData | null, CardType | null];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateCreditCard = exports.formatCard = exports.formatCardField = exports.makeAcctNumber = exports.makeNumeric = exports.getCardType = exports.cardNumbersRegex = exports.cardNames = void 0;
3
+ exports.validateCreditCard = exports.formatCard = exports.formatCardField = exports.makeAcctNumber = exports.makeAlphaNumeric = exports.makeNumeric = exports.getCardType = exports.cardNumbersRegex = exports.cardNames = void 0;
4
4
  const helpers_1 = require("./helpers");
5
5
  exports.cardNames = {
6
6
  VISA: 'Visa',
@@ -48,6 +48,13 @@ const makeNumeric = (str) => {
48
48
  return strMatches.join('').replace(/\s/g, '');
49
49
  };
50
50
  exports.makeNumeric = makeNumeric;
51
+ const makeAlphaNumeric = (str) => {
52
+ const strMatches = str.match(/[a-zA-Z0-9]+/g); // limit to alphanumeric input, returns an array
53
+ if (!strMatches)
54
+ return '';
55
+ return strMatches.join('').replace(/\s/g, '');
56
+ };
57
+ exports.makeAlphaNumeric = makeAlphaNumeric;
51
58
  const makeAcctNumber = (str, cardType) => {
52
59
  const strMatches = str.match(/\d+/g); // limit to numerical input, returns an array
53
60
  if (!strMatches)
@@ -87,6 +94,8 @@ const formatCardField = (field, value) => {
87
94
  }
88
95
  case 'cvv':
89
96
  return cleanValue.slice(0, 4);
97
+ case 'zip':
98
+ return (0, exports.makeAlphaNumeric)(cleanValue);
90
99
  default:
91
100
  return cleanValue;
92
101
  }
@@ -14,6 +14,7 @@ export declare const cardNumbersRegex: {
14
14
  };
15
15
  export declare const getCardType: (cardNumber: string) => CardType;
16
16
  export declare const makeNumeric: (str: string) => string;
17
+ export declare const makeAlphaNumeric: (str: string) => string;
17
18
  export declare const makeAcctNumber: (str: string, cardType: CardType) => string;
18
19
  export declare const formatCardField: (field: keyof CreditCardData, value: string) => string;
19
20
  export declare const formatCard: (card: CreditCardData | null) => [CreditCardData | null, CardType | null];
@@ -43,6 +43,12 @@ export const makeNumeric = (str) => {
43
43
  return '';
44
44
  return strMatches.join('').replace(/\s/g, '');
45
45
  };
46
+ export const makeAlphaNumeric = (str) => {
47
+ const strMatches = str.match(/[a-zA-Z0-9]+/g); // limit to alphanumeric input, returns an array
48
+ if (!strMatches)
49
+ return '';
50
+ return strMatches.join('').replace(/\s/g, '');
51
+ };
46
52
  export const makeAcctNumber = (str, cardType) => {
47
53
  const strMatches = str.match(/\d+/g); // limit to numerical input, returns an array
48
54
  if (!strMatches)
@@ -81,6 +87,8 @@ export const formatCardField = (field, value) => {
81
87
  }
82
88
  case 'cvv':
83
89
  return cleanValue.slice(0, 4);
90
+ case 'zip':
91
+ return makeAlphaNumeric(cleanValue);
84
92
  default:
85
93
  return cleanValue;
86
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.5.33",
3
+ "version": "0.5.35",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",