@open-tender/utils 0.5.74 → 0.5.75
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/cjs/__tests__/utils/cards.test.d.ts +1 -0
- package/dist/cjs/__tests__/utils/cards.test.js +28 -0
- package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +1 -1
- package/dist/cjs/hooks/useGiftCardAssignForm.js +2 -2
- package/dist/cjs/utils/cards.d.ts +1 -0
- package/dist/cjs/utils/cards.js +6 -1
- package/dist/esm/__tests__/utils/cards.test.d.ts +1 -0
- package/dist/esm/__tests__/utils/cards.test.js +26 -0
- package/dist/esm/hooks/useGiftCardAssignForm.d.ts +1 -1
- package/dist/esm/hooks/useGiftCardAssignForm.js +3 -3
- package/dist/esm/utils/cards.d.ts +1 -0
- package/dist/esm/utils/cards.js +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../../utils");
|
|
4
|
+
describe('parseGiftCardNumber', () => {
|
|
5
|
+
it('keeps leading zeros and returns a string', () => {
|
|
6
|
+
expect((0, utils_1.parseGiftCardNumber)('0123456789')).toBe('0123456789');
|
|
7
|
+
expect((0, utils_1.parseGiftCardNumber)('0')).toBe('0');
|
|
8
|
+
});
|
|
9
|
+
it('trims surrounding whitespace', () => {
|
|
10
|
+
expect((0, utils_1.parseGiftCardNumber)(' 6012345678 ')).toBe('6012345678');
|
|
11
|
+
});
|
|
12
|
+
it('accepts up to 24 digits', () => {
|
|
13
|
+
expect((0, utils_1.parseGiftCardNumber)('9'.repeat(24))).toBe('9'.repeat(24));
|
|
14
|
+
});
|
|
15
|
+
it('rejects empty, non-numeric and over-length values', () => {
|
|
16
|
+
const invalid = [
|
|
17
|
+
'',
|
|
18
|
+
' ',
|
|
19
|
+
'12ab',
|
|
20
|
+
'ab12',
|
|
21
|
+
'1 2',
|
|
22
|
+
'-1',
|
|
23
|
+
'1.5',
|
|
24
|
+
'9'.repeat(25)
|
|
25
|
+
];
|
|
26
|
+
invalid.forEach(value => expect((0, utils_1.parseGiftCardNumber)(value)).toBeNull());
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useGiftCardAssignForm: (loading: RequestStatus, error: RequestError, assign: (card_number:
|
|
3
|
+
export declare const useGiftCardAssignForm: (loading: RequestStatus, error: RequestError, assign: (card_number: string, callback: () => void) => void, callback: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: FormFields;
|
|
@@ -32,8 +32,8 @@ const useGiftCardAssignForm = (loading, error, assign, callback) => {
|
|
|
32
32
|
const handleSubmit = (evt) => {
|
|
33
33
|
var _a, _b, _c, _d;
|
|
34
34
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
35
|
-
const card_number =
|
|
36
|
-
if (
|
|
35
|
+
const card_number = (0, utils_1.parseGiftCardNumber)(data.card_number);
|
|
36
|
+
if (card_number === null) {
|
|
37
37
|
setErrors({ card_number: 'Card numbers must be all digits' });
|
|
38
38
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
39
39
|
}
|
|
@@ -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 parseGiftCardNumber: (value: string) => string | null;
|
|
17
18
|
export declare const makeAlphaNumeric: (str: string) => string;
|
|
18
19
|
export declare const makeAcctNumber: (str: string, cardType: CardType) => string;
|
|
19
20
|
export declare const formatCardField: (field: keyof CreditCardData, value: string) => string;
|
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.makeAlphaNumeric = exports.makeNumeric = exports.getCardType = exports.cardNumbersRegex = exports.cardNames = void 0;
|
|
3
|
+
exports.validateCreditCard = exports.formatCard = exports.formatCardField = exports.makeAcctNumber = exports.makeAlphaNumeric = exports.parseGiftCardNumber = 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,11 @@ const makeNumeric = (str) => {
|
|
|
48
48
|
return strMatches.join('').replace(/\s/g, '');
|
|
49
49
|
};
|
|
50
50
|
exports.makeNumeric = makeNumeric;
|
|
51
|
+
const parseGiftCardNumber = (value) => {
|
|
52
|
+
const cardNumber = value.trim();
|
|
53
|
+
return /^\d{1,24}$/.test(cardNumber) ? cardNumber : null;
|
|
54
|
+
};
|
|
55
|
+
exports.parseGiftCardNumber = parseGiftCardNumber;
|
|
51
56
|
const makeAlphaNumeric = (str) => {
|
|
52
57
|
const strMatches = str.match(/[a-zA-Z0-9]+/g); // limit to alphanumeric input, returns an array
|
|
53
58
|
if (!strMatches)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parseGiftCardNumber } from '../../utils';
|
|
2
|
+
describe('parseGiftCardNumber', () => {
|
|
3
|
+
it('keeps leading zeros and returns a string', () => {
|
|
4
|
+
expect(parseGiftCardNumber('0123456789')).toBe('0123456789');
|
|
5
|
+
expect(parseGiftCardNumber('0')).toBe('0');
|
|
6
|
+
});
|
|
7
|
+
it('trims surrounding whitespace', () => {
|
|
8
|
+
expect(parseGiftCardNumber(' 6012345678 ')).toBe('6012345678');
|
|
9
|
+
});
|
|
10
|
+
it('accepts up to 24 digits', () => {
|
|
11
|
+
expect(parseGiftCardNumber('9'.repeat(24))).toBe('9'.repeat(24));
|
|
12
|
+
});
|
|
13
|
+
it('rejects empty, non-numeric and over-length values', () => {
|
|
14
|
+
const invalid = [
|
|
15
|
+
'',
|
|
16
|
+
' ',
|
|
17
|
+
'12ab',
|
|
18
|
+
'ab12',
|
|
19
|
+
'1 2',
|
|
20
|
+
'-1',
|
|
21
|
+
'1.5',
|
|
22
|
+
'9'.repeat(25)
|
|
23
|
+
];
|
|
24
|
+
invalid.forEach(value => expect(parseGiftCardNumber(value)).toBeNull());
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useGiftCardAssignForm: (loading: RequestStatus, error: RequestError, assign: (card_number:
|
|
3
|
+
export declare const useGiftCardAssignForm: (loading: RequestStatus, error: RequestError, assign: (card_number: string, callback: () => void) => void, callback: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: FormFields;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
|
-
import { makeFormErrors } from '../utils';
|
|
2
|
+
import { makeFormErrors, parseGiftCardNumber } from '../utils';
|
|
3
3
|
export const useGiftCardAssignForm = (loading, error, assign, callback) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const inputRef = useRef(null);
|
|
@@ -29,8 +29,8 @@ export const useGiftCardAssignForm = (loading, error, assign, callback) => {
|
|
|
29
29
|
const handleSubmit = (evt) => {
|
|
30
30
|
var _a, _b, _c, _d;
|
|
31
31
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
32
|
-
const card_number =
|
|
33
|
-
if (
|
|
32
|
+
const card_number = parseGiftCardNumber(data.card_number);
|
|
33
|
+
if (card_number === null) {
|
|
34
34
|
setErrors({ card_number: 'Card numbers must be all digits' });
|
|
35
35
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
36
36
|
}
|
|
@@ -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 parseGiftCardNumber: (value: string) => string | null;
|
|
17
18
|
export declare const makeAlphaNumeric: (str: string) => string;
|
|
18
19
|
export declare const makeAcctNumber: (str: string, cardType: CardType) => string;
|
|
19
20
|
export declare const formatCardField: (field: keyof CreditCardData, value: string) => string;
|
package/dist/esm/utils/cards.js
CHANGED
|
@@ -43,6 +43,10 @@ export const makeNumeric = (str) => {
|
|
|
43
43
|
return '';
|
|
44
44
|
return strMatches.join('').replace(/\s/g, '');
|
|
45
45
|
};
|
|
46
|
+
export const parseGiftCardNumber = (value) => {
|
|
47
|
+
const cardNumber = value.trim();
|
|
48
|
+
return /^\d{1,24}$/.test(cardNumber) ? cardNumber : null;
|
|
49
|
+
};
|
|
46
50
|
export const makeAlphaNumeric = (str) => {
|
|
47
51
|
const strMatches = str.match(/[a-zA-Z0-9]+/g); // limit to alphanumeric input, returns an array
|
|
48
52
|
if (!strMatches)
|
package/package.json
CHANGED