@open-tender/utils 0.5.34 → 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];
|
package/dist/cjs/utils/cards.js
CHANGED
|
@@ -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)
|
|
@@ -88,7 +95,7 @@ const formatCardField = (field, value) => {
|
|
|
88
95
|
case 'cvv':
|
|
89
96
|
return cleanValue.slice(0, 4);
|
|
90
97
|
case 'zip':
|
|
91
|
-
return
|
|
98
|
+
return (0, exports.makeAlphaNumeric)(cleanValue);
|
|
92
99
|
default:
|
|
93
100
|
return cleanValue;
|
|
94
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];
|
package/dist/esm/utils/cards.js
CHANGED
|
@@ -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)
|
|
@@ -82,7 +88,7 @@ export const formatCardField = (field, value) => {
|
|
|
82
88
|
case 'cvv':
|
|
83
89
|
return cleanValue.slice(0, 4);
|
|
84
90
|
case 'zip':
|
|
85
|
-
return cleanValue
|
|
91
|
+
return makeAlphaNumeric(cleanValue);
|
|
86
92
|
default:
|
|
87
93
|
return cleanValue;
|
|
88
94
|
}
|
package/package.json
CHANGED