card-validator 8.1.0 → 9.0.0
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/.github/CODEOWNERS +1 -0
- package/.github/workflows/ci.yml +17 -0
- package/README.md +1 -1
- package/dist/card-number.d.ts +2 -2
- package/dist/expiration-date.js +3 -3
- package/dist/expiration-year.js +3 -0
- package/dist/index.js +6 -2
- package/dist/lib/parse-date.d.ts +1 -1
- package/dist/lib/parse-date.js +2 -2
- package/dist/postal-code.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +15 -11
- package/src/__tests__/card-number.ts +1 -1
- package/src/__tests__/cardholder-name.ts +1 -1
- package/src/__tests__/cvv.ts +11 -15
- package/src/__tests__/expiration-date.ts +31 -4
- package/src/__tests__/expiration-year.ts +5 -1
- package/src/__tests__/lib/parse-date.ts +1 -1
- package/src/__tests__/postal-code.ts +1 -1
- package/src/card-number.ts +2 -2
- package/src/cardholder-name.ts +1 -1
- package/src/cvv.ts +2 -2
- package/src/expiration-date.ts +3 -3
- package/src/expiration-month.ts +2 -2
- package/src/expiration-year.ts +6 -2
- package/src/postal-code.ts +2 -2
- package/CHANGELOG.md +0 -152
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @braintree/team-sdk-js
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: "Unit Tests"
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
name: "Unit Tests on Ubuntu"
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v2
|
|
12
|
+
- name: Use Node.js
|
|
13
|
+
uses: actions/setup-node@v1
|
|
14
|
+
with:
|
|
15
|
+
node-version: "18.x"
|
|
16
|
+
- run: npm install
|
|
17
|
+
- run: npm test
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Credit Card Validator [](https://github.com/braintree/card-validator/actions?query=workflow%3A%22Unit+Tests%22) [](http://badge.fury.io/js/card-validator)
|
|
2
2
|
|
|
3
3
|
Credit Card Validator provides validation utilities for credit card data inputs. It is designed as a CommonJS module for use in Node.js, io.js, or the [browser](http://browserify.org/). It includes first class support for 'potential' validity so you can use it to present appropriate UI to your user as they type.
|
|
4
4
|
|
package/dist/card-number.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Verification } from "./types";
|
|
2
|
-
|
|
2
|
+
type CreditCardType = {
|
|
3
3
|
niceType: string;
|
|
4
4
|
type: string;
|
|
5
5
|
patterns: Array<number[] | number>;
|
|
@@ -13,7 +13,7 @@ declare type CreditCardType = {
|
|
|
13
13
|
export interface CardNumberVerification extends Verification {
|
|
14
14
|
card: CreditCardType | null;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
type CardNumberOptions = {
|
|
17
17
|
maxLength?: number;
|
|
18
18
|
luhnValidateUnionPay?: boolean;
|
|
19
19
|
};
|
package/dist/expiration-date.js
CHANGED
|
@@ -27,7 +27,7 @@ function expirationDate(value, maxElapsedYear) {
|
|
|
27
27
|
var date;
|
|
28
28
|
if (typeof value === "string") {
|
|
29
29
|
value = value.replace(/^(\d\d) (\d\d(\d\d)?)$/, "$1/$2");
|
|
30
|
-
date = parse_date_1.parseDate(String(value));
|
|
30
|
+
date = (0, parse_date_1.parseDate)(String(value));
|
|
31
31
|
}
|
|
32
32
|
else if (value !== null && typeof value === "object") {
|
|
33
33
|
var fullDate = __assign({}, value);
|
|
@@ -39,8 +39,8 @@ function expirationDate(value, maxElapsedYear) {
|
|
|
39
39
|
else {
|
|
40
40
|
return verification(false, false, null, null);
|
|
41
41
|
}
|
|
42
|
-
var monthValid = expiration_month_1.expirationMonth(date.month);
|
|
43
|
-
var yearValid = expiration_year_1.expirationYear(date.year, maxElapsedYear);
|
|
42
|
+
var monthValid = (0, expiration_month_1.expirationMonth)(date.month);
|
|
43
|
+
var yearValid = (0, expiration_year_1.expirationYear)(date.year, maxElapsedYear);
|
|
44
44
|
if (monthValid.isValid) {
|
|
45
45
|
if (yearValid.isCurrentYear) {
|
|
46
46
|
var isValidForThisYear = monthValid.isValidForThisYear;
|
package/dist/expiration-year.js
CHANGED
|
@@ -39,6 +39,9 @@ function expirationYear(value, maxElapsedYear) {
|
|
|
39
39
|
var twoDigitYear = Number(String(currentYear).substr(2, 2));
|
|
40
40
|
var valid = false;
|
|
41
41
|
if (len === 2) {
|
|
42
|
+
if (String(currentYear).substr(0, 2) === value) {
|
|
43
|
+
return verification(false, true);
|
|
44
|
+
}
|
|
42
45
|
isCurrentYear = twoDigitYear === numericValue;
|
|
43
46
|
valid =
|
|
44
47
|
numericValue >= twoDigitYear &&
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,7 +18,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
14
18
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
19
|
if (mod && mod.__esModule) return mod;
|
|
16
20
|
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
22
|
__setModuleDefault(result, mod);
|
|
19
23
|
return result;
|
|
20
24
|
};
|
package/dist/lib/parse-date.d.ts
CHANGED
package/dist/lib/parse-date.js
CHANGED
|
@@ -46,7 +46,7 @@ function getNumberOfMonthDigitsInDateString(dateString) {
|
|
|
46
46
|
*/
|
|
47
47
|
if (firstCharacter === 1) {
|
|
48
48
|
assumedYear = dateString.substr(1);
|
|
49
|
-
return expiration_year_1.expirationYear(assumedYear).isPotentiallyValid ? 1 : 2;
|
|
49
|
+
return (0, expiration_year_1.expirationYear)(assumedYear).isPotentiallyValid ? 1 : 2;
|
|
50
50
|
}
|
|
51
51
|
/*
|
|
52
52
|
If the length of the value is exactly 5 characters,
|
|
@@ -84,7 +84,7 @@ function parseDate(datestring) {
|
|
|
84
84
|
else if (/\s/.test(datestring)) {
|
|
85
85
|
date = datestring.split(/ +/g);
|
|
86
86
|
}
|
|
87
|
-
if (is_array_1.isArray(date)) {
|
|
87
|
+
if ((0, is_array_1.isArray)(date)) {
|
|
88
88
|
return {
|
|
89
89
|
month: date[0] || "",
|
|
90
90
|
year: date.slice(1).join(),
|
package/dist/postal-code.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "card-validator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "A library for validating credit card fields",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,23 +20,27 @@
|
|
|
20
20
|
"author": "Braintree <code@getbraintree.com> (https://www.braintreepayments.com/)",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@types/jest": "^
|
|
24
|
-
"@types/node": "^
|
|
25
|
-
"eslint": "^
|
|
26
|
-
"eslint
|
|
27
|
-
"
|
|
28
|
-
"prettier": "^
|
|
29
|
-
"
|
|
30
|
-
"
|
|
23
|
+
"@types/jest": "^29.5.3",
|
|
24
|
+
"@types/node": "^20.5.2",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
|
26
|
+
"eslint": "^8.47.0",
|
|
27
|
+
"eslint-config-braintree": "^6.0.0-typescript-prep-rc.2",
|
|
28
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
29
|
+
"jest": "^29.6.3",
|
|
30
|
+
"jest-environment-jsdom": "^29.6.3",
|
|
31
|
+
"prettier": "^3.0.2",
|
|
32
|
+
"ts-jest": "^29.1.1",
|
|
33
|
+
"typescript": "^5.1.6"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"credit-card-type": "^9.
|
|
36
|
+
"credit-card-type": "^9.1.0"
|
|
34
37
|
},
|
|
35
38
|
"jest": {
|
|
39
|
+
"testEnvironment": "jsdom",
|
|
36
40
|
"preset": "ts-jest",
|
|
37
41
|
"globals": {
|
|
38
42
|
"ts-jest": {
|
|
39
|
-
"
|
|
43
|
+
"tsconfig": "src/__tests__/tsconfig.json"
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
}
|
package/src/__tests__/cvv.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { cvv } from "../cvv";
|
|
2
|
-
import { Verification } from "../types";
|
|
3
2
|
|
|
4
3
|
describe("cvv", () => {
|
|
5
4
|
describe("values", () => {
|
|
@@ -58,20 +57,17 @@ describe("cvv", () => {
|
|
|
58
57
|
[{}, { isValid: false, isPotentiallyValid: false }],
|
|
59
58
|
],
|
|
60
59
|
],
|
|
61
|
-
]
|
|
62
|
-
"%s",
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
);
|
|
60
|
+
])("%s", (description, tests) => {
|
|
61
|
+
it.each(tests)("parses %s to be %p", (testCvv, meta, maxLength) => {
|
|
62
|
+
if (typeof maxLength === "function") {
|
|
63
|
+
// maxLength argument got converted to a done callback
|
|
64
|
+
expect(cvv(testCvv)).toEqual(meta);
|
|
65
|
+
maxLength();
|
|
66
|
+
} else {
|
|
67
|
+
expect(cvv(testCvv, maxLength)).toEqual(meta);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
75
71
|
});
|
|
76
72
|
|
|
77
73
|
describe("maxLength", () => {
|
|
@@ -3,6 +3,7 @@ import { expirationDate, ExpirationDateVerification } from "../expiration-date";
|
|
|
3
3
|
const date = new Date();
|
|
4
4
|
const currentYear = date.getFullYear();
|
|
5
5
|
const twoDigitYear = Number(String(currentYear).substr(2, 2));
|
|
6
|
+
const firstTwoDigitsOfCurrentYear = Number(String(currentYear).substr(0, 2));
|
|
6
7
|
const nextYear = currentYear + 1;
|
|
7
8
|
const currentMonth = date.getMonth() + 1;
|
|
8
9
|
const previousMonth = currentMonth - 1 || currentMonth;
|
|
@@ -383,6 +384,15 @@ describe("expirationDate validates", () => {
|
|
|
383
384
|
year: null,
|
|
384
385
|
},
|
|
385
386
|
],
|
|
387
|
+
[
|
|
388
|
+
`02/${firstTwoDigitsOfCurrentYear}`,
|
|
389
|
+
{
|
|
390
|
+
isValid: false,
|
|
391
|
+
isPotentiallyValid: true,
|
|
392
|
+
month: null,
|
|
393
|
+
year: null,
|
|
394
|
+
},
|
|
395
|
+
],
|
|
386
396
|
],
|
|
387
397
|
],
|
|
388
398
|
[
|
|
@@ -595,6 +605,10 @@ describe("expirationDate validates", () => {
|
|
|
595
605
|
"1 202",
|
|
596
606
|
{ isValid: false, isPotentiallyValid: true, month: null, year: null },
|
|
597
607
|
],
|
|
608
|
+
[
|
|
609
|
+
`1 ${firstTwoDigitsOfCurrentYear}`,
|
|
610
|
+
{ isValid: false, isPotentiallyValid: true, month: null, year: null },
|
|
611
|
+
],
|
|
598
612
|
[
|
|
599
613
|
"1 ",
|
|
600
614
|
{ isValid: false, isPotentiallyValid: true, month: null, year: null },
|
|
@@ -789,6 +803,10 @@ describe("expirationDate validates", () => {
|
|
|
789
803
|
year: null,
|
|
790
804
|
},
|
|
791
805
|
],
|
|
806
|
+
[
|
|
807
|
+
`02${firstTwoDigitsOfCurrentYear}`,
|
|
808
|
+
{ isValid: false, isPotentiallyValid: true, month: null, year: null },
|
|
809
|
+
],
|
|
792
810
|
],
|
|
793
811
|
],
|
|
794
812
|
[
|
|
@@ -1050,7 +1068,7 @@ describe("expirationDate validates", () => {
|
|
|
1050
1068
|
"parses %s to be %p",
|
|
1051
1069
|
(exp: string | number, meta: ExpirationDateVerification) => {
|
|
1052
1070
|
expect(expirationDate(exp)).toEqual(meta);
|
|
1053
|
-
}
|
|
1071
|
+
},
|
|
1054
1072
|
);
|
|
1055
1073
|
});
|
|
1056
1074
|
|
|
@@ -1216,6 +1234,15 @@ describe("expirationDate validates", () => {
|
|
|
1216
1234
|
year: null,
|
|
1217
1235
|
},
|
|
1218
1236
|
],
|
|
1237
|
+
[
|
|
1238
|
+
{ month: "02", year: "20" },
|
|
1239
|
+
{
|
|
1240
|
+
isValid: false,
|
|
1241
|
+
isPotentiallyValid: true,
|
|
1242
|
+
month: null,
|
|
1243
|
+
year: null,
|
|
1244
|
+
},
|
|
1245
|
+
],
|
|
1219
1246
|
[
|
|
1220
1247
|
{ month: "0", year: "199" },
|
|
1221
1248
|
{
|
|
@@ -1260,7 +1287,7 @@ describe("expirationDate validates", () => {
|
|
|
1260
1287
|
"parses %s to be %p",
|
|
1261
1288
|
(exp, meta: ExpirationDateVerification) => {
|
|
1262
1289
|
expect(expirationDate(exp)).toEqual(meta);
|
|
1263
|
-
}
|
|
1290
|
+
},
|
|
1264
1291
|
);
|
|
1265
1292
|
});
|
|
1266
1293
|
|
|
@@ -1282,7 +1309,7 @@ describe("expirationDate validates", () => {
|
|
|
1282
1309
|
|
|
1283
1310
|
it("accepts maxElapsedYear", () => {
|
|
1284
1311
|
expect(
|
|
1285
|
-
expirationDate(`${currentMonth} / ${yearsFromNow(20)}`, 20)
|
|
1312
|
+
expirationDate(`${currentMonth} / ${yearsFromNow(20)}`, 20),
|
|
1286
1313
|
).toEqual({
|
|
1287
1314
|
isValid: true,
|
|
1288
1315
|
isPotentiallyValid: true,
|
|
@@ -1290,7 +1317,7 @@ describe("expirationDate validates", () => {
|
|
|
1290
1317
|
year: yearsFromNow(20).toString(),
|
|
1291
1318
|
});
|
|
1292
1319
|
expect(
|
|
1293
|
-
expirationDate(`${currentMonth} / ${yearsFromNow(21)}`, 20)
|
|
1320
|
+
expirationDate(`${currentMonth} / ${yearsFromNow(21)}`, 20),
|
|
1294
1321
|
).toEqual({
|
|
1295
1322
|
isValid: false,
|
|
1296
1323
|
isPotentiallyValid: false,
|
|
@@ -74,6 +74,10 @@ describe("expirationYear", () => {
|
|
|
74
74
|
"123",
|
|
75
75
|
{ isValid: false, isPotentiallyValid: false, isCurrentYear: false },
|
|
76
76
|
],
|
|
77
|
+
[
|
|
78
|
+
"20",
|
|
79
|
+
{ isValid: false, isPotentiallyValid: true, isCurrentYear: false },
|
|
80
|
+
],
|
|
77
81
|
],
|
|
78
82
|
],
|
|
79
83
|
|
|
@@ -217,7 +221,7 @@ describe("expirationYear", () => {
|
|
|
217
221
|
it.each(tests)("parses %s to be %p", (exp, meta) => {
|
|
218
222
|
expect(expirationYear(exp)).toEqual(meta);
|
|
219
223
|
});
|
|
220
|
-
}
|
|
224
|
+
},
|
|
221
225
|
);
|
|
222
226
|
|
|
223
227
|
it("defaults maxElapsedYear is 19", () => {
|
package/src/card-number.ts
CHANGED
|
@@ -27,7 +27,7 @@ type CardNumberOptions = {
|
|
|
27
27
|
function verification(
|
|
28
28
|
card: CreditCardType | null,
|
|
29
29
|
isPotentiallyValid: boolean,
|
|
30
|
-
isValid: boolean
|
|
30
|
+
isValid: boolean,
|
|
31
31
|
): CardNumberVerification {
|
|
32
32
|
return {
|
|
33
33
|
card,
|
|
@@ -38,7 +38,7 @@ function verification(
|
|
|
38
38
|
|
|
39
39
|
export function cardNumber(
|
|
40
40
|
value: string | unknown,
|
|
41
|
-
options: CardNumberOptions = {}
|
|
41
|
+
options: CardNumberOptions = {},
|
|
42
42
|
): CardNumberVerification {
|
|
43
43
|
let isPotentiallyValid, isValid, maxLength;
|
|
44
44
|
|
package/src/cardholder-name.ts
CHANGED
package/src/cvv.ts
CHANGED
|
@@ -25,14 +25,14 @@ function max(array: number[]): number {
|
|
|
25
25
|
|
|
26
26
|
function verification(
|
|
27
27
|
isValid: boolean,
|
|
28
|
-
isPotentiallyValid: boolean
|
|
28
|
+
isPotentiallyValid: boolean,
|
|
29
29
|
): Verification {
|
|
30
30
|
return { isValid, isPotentiallyValid };
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function cvv(
|
|
34
34
|
value: string | unknown,
|
|
35
|
-
maxLength: number | number[] = DEFAULT_LENGTH
|
|
35
|
+
maxLength: number | number[] = DEFAULT_LENGTH,
|
|
36
36
|
): Verification {
|
|
37
37
|
maxLength = maxLength instanceof Array ? maxLength : [maxLength];
|
|
38
38
|
|
package/src/expiration-date.ts
CHANGED
|
@@ -13,7 +13,7 @@ function verification(
|
|
|
13
13
|
isValid: boolean,
|
|
14
14
|
isPotentiallyValid: boolean,
|
|
15
15
|
month: string | null,
|
|
16
|
-
year: string | null
|
|
16
|
+
year: string | null,
|
|
17
17
|
): ExpirationDateVerification {
|
|
18
18
|
return {
|
|
19
19
|
isValid,
|
|
@@ -25,7 +25,7 @@ function verification(
|
|
|
25
25
|
|
|
26
26
|
export function expirationDate(
|
|
27
27
|
value: string | Record<string, string | number> | unknown,
|
|
28
|
-
maxElapsedYear?: number
|
|
28
|
+
maxElapsedYear?: number,
|
|
29
29
|
): ExpirationDateVerification {
|
|
30
30
|
let date;
|
|
31
31
|
|
|
@@ -53,7 +53,7 @@ export function expirationDate(
|
|
|
53
53
|
isValidForThisYear,
|
|
54
54
|
isValidForThisYear,
|
|
55
55
|
date.month,
|
|
56
|
-
date.year
|
|
56
|
+
date.year,
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
|
package/src/expiration-month.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface ExpirationMonthVerification extends Verification {
|
|
|
7
7
|
function verification(
|
|
8
8
|
isValid: boolean,
|
|
9
9
|
isPotentiallyValid: boolean,
|
|
10
|
-
isValidForThisYear?: boolean
|
|
10
|
+
isValidForThisYear?: boolean,
|
|
11
11
|
): ExpirationMonthVerification {
|
|
12
12
|
return {
|
|
13
13
|
isValid,
|
|
@@ -17,7 +17,7 @@ function verification(
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function expirationMonth(
|
|
20
|
-
value: string | unknown
|
|
20
|
+
value: string | unknown,
|
|
21
21
|
): ExpirationMonthVerification {
|
|
22
22
|
const currentMonth = new Date().getMonth() + 1;
|
|
23
23
|
|
package/src/expiration-year.ts
CHANGED
|
@@ -9,7 +9,7 @@ const DEFAULT_VALID_NUMBER_OF_YEARS_IN_THE_FUTURE = 19;
|
|
|
9
9
|
function verification(
|
|
10
10
|
isValid: boolean,
|
|
11
11
|
isPotentiallyValid: boolean,
|
|
12
|
-
isCurrentYear?: boolean
|
|
12
|
+
isCurrentYear?: boolean,
|
|
13
13
|
): ExpirationYearVerification {
|
|
14
14
|
return {
|
|
15
15
|
isValid,
|
|
@@ -20,7 +20,7 @@ function verification(
|
|
|
20
20
|
|
|
21
21
|
export function expirationYear(
|
|
22
22
|
value: string | unknown,
|
|
23
|
-
maxElapsedYear = DEFAULT_VALID_NUMBER_OF_YEARS_IN_THE_FUTURE
|
|
23
|
+
maxElapsedYear = DEFAULT_VALID_NUMBER_OF_YEARS_IN_THE_FUTURE,
|
|
24
24
|
): ExpirationYearVerification {
|
|
25
25
|
let isCurrentYear;
|
|
26
26
|
|
|
@@ -59,6 +59,10 @@ export function expirationYear(
|
|
|
59
59
|
let valid = false;
|
|
60
60
|
|
|
61
61
|
if (len === 2) {
|
|
62
|
+
if (String(currentYear).substr(0, 2) === value) {
|
|
63
|
+
return verification(false, true);
|
|
64
|
+
}
|
|
65
|
+
|
|
62
66
|
isCurrentYear = twoDigitYear === numericValue;
|
|
63
67
|
valid =
|
|
64
68
|
numericValue >= twoDigitYear &&
|
package/src/postal-code.ts
CHANGED
|
@@ -8,14 +8,14 @@ const DEFAULT_MIN_POSTAL_CODE_LENGTH = 3;
|
|
|
8
8
|
|
|
9
9
|
function verification(
|
|
10
10
|
isValid: boolean,
|
|
11
|
-
isPotentiallyValid: boolean
|
|
11
|
+
isPotentiallyValid: boolean,
|
|
12
12
|
): Verification {
|
|
13
13
|
return { isValid, isPotentiallyValid };
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function postalCode(
|
|
17
17
|
value: string | unknown,
|
|
18
|
-
options: PostalCodeOptions = {}
|
|
18
|
+
options: PostalCodeOptions = {},
|
|
19
19
|
): Verification {
|
|
20
20
|
const minLength = options.minLength || DEFAULT_MIN_POSTAL_CODE_LENGTH;
|
|
21
21
|
|
package/CHANGELOG.md
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
# 8.1.0
|
|
2
|
-
|
|
3
|
-
- Add `cardholderName` verification method
|
|
4
|
-
|
|
5
|
-
# 8.0.0
|
|
6
|
-
|
|
7
|
-
_Breaking Changes_
|
|
8
|
-
|
|
9
|
-
- Use `export =` instead of `export default` for main export (use `"esModuleInterop": true` flag in your tsconfig to maintain the `default` module behavior)
|
|
10
|
-
|
|
11
|
-
# 7.1.0
|
|
12
|
-
|
|
13
|
-
- The cardValidator object is now available as the `default` import when using es modules (thanks @leomp12)
|
|
14
|
-
|
|
15
|
-
# 7.0.1
|
|
16
|
-
|
|
17
|
-
- Fixup export for credit-card-type for typescript projects (closes #79)
|
|
18
|
-
|
|
19
|
-
# 7.0.0
|
|
20
|
-
|
|
21
|
-
- Add typescript types
|
|
22
|
-
|
|
23
|
-
_Breaking Changes_
|
|
24
|
-
|
|
25
|
-
- Upgrade credit-card-type to v9.0.0
|
|
26
|
-
- Drop support for card numbers instantiated with `new String(number)`
|
|
27
|
-
|
|
28
|
-
# 6.2.0
|
|
29
|
-
|
|
30
|
-
- Adjust expiration date to accept dates formatted as `YYYY-MM` (the HTML autofill spec). Closes #69 (thanks @schuylr)
|
|
31
|
-
|
|
32
|
-
# 6.1.0
|
|
33
|
-
|
|
34
|
-
- Add option to set a `maxLength` for card number valiation
|
|
35
|
-
|
|
36
|
-
# 6.0.0
|
|
37
|
-
|
|
38
|
-
- Update credit-card-type to v8.0.0
|
|
39
|
-
|
|
40
|
-
_Breaking Changes_
|
|
41
|
-
|
|
42
|
-
- When adding or updating cards, this module no longer uses an `exactPattern` and `prefixPattern` model. Instead, it takes an array of patterns. See https://github.com/braintree/credit-card-type#pattern-detection for details.
|
|
43
|
-
|
|
44
|
-
# 5.1.0
|
|
45
|
-
|
|
46
|
-
- Add optional options object with `luhnValidateUnionPay` parameter to force luhn validity check of UnionPay cards
|
|
47
|
-
- Update tests to account for ELO cards
|
|
48
|
-
|
|
49
|
-
# 5.0.0
|
|
50
|
-
|
|
51
|
-
- Update `credit-card-type` to v7.0.0
|
|
52
|
-
|
|
53
|
-
_Breaking Changes_
|
|
54
|
-
|
|
55
|
-
- Mastercard enum changed from `master-card` to `mastercard`
|
|
56
|
-
|
|
57
|
-
# 4.3.0
|
|
58
|
-
|
|
59
|
-
- Support custom card brands
|
|
60
|
-
- Require minimum version of credit-card-type to be v6.2.0
|
|
61
|
-
|
|
62
|
-
# 4.2.0
|
|
63
|
-
|
|
64
|
-
- Allow `maxElapsedYear` to be configurable in `expirationYear` and `expirationDate` (thanks @wozaki)
|
|
65
|
-
|
|
66
|
-
# 4.1.1
|
|
67
|
-
|
|
68
|
-
- Update `credit-card-type` to v6.0.0
|
|
69
|
-
|
|
70
|
-
# 4.1.0
|
|
71
|
-
|
|
72
|
-
- Add options object for postal code validation to specify min length
|
|
73
|
-
|
|
74
|
-
# 4.0.0
|
|
75
|
-
|
|
76
|
-
- **Breaking change**: Remove `dist` files. You must use `npm` to use this module
|
|
77
|
-
- **Breaking change**: Remove support for primitive constructors like `new String()`
|
|
78
|
-
|
|
79
|
-
# 3.0.1
|
|
80
|
-
|
|
81
|
-
- Fix postal code validation to be valid if 3 or more characters
|
|
82
|
-
|
|
83
|
-
# 3.0.0
|
|
84
|
-
|
|
85
|
-
- correctly identify Maestro cards beginning with `6`
|
|
86
|
-
- **Breaking change**: The format of the `card` object returned has changed. `pattern` has been replaced by `prefixPattern` and `exactPattern`.
|
|
87
|
-
|
|
88
|
-
# 2.3.0
|
|
89
|
-
|
|
90
|
-
- valid.expirationDate can take an object with month and year fields or a string value
|
|
91
|
-
|
|
92
|
-
# 2.2.8
|
|
93
|
-
|
|
94
|
-
- Update `dist` to include version `4.0.3` of credit-card-type
|
|
95
|
-
|
|
96
|
-
# 2.2.7
|
|
97
|
-
|
|
98
|
-
- Including `dist` from `2.2.6`
|
|
99
|
-
|
|
100
|
-
# 2.2.6
|
|
101
|
-
|
|
102
|
-
- Fixes cases where card numbers were incorrectly reported as `isPotentiallyValid: false` when more digits could still be entered
|
|
103
|
-
|
|
104
|
-
- issue #20 and PR #21
|
|
105
|
-
|
|
106
|
-
# 2.2.5
|
|
107
|
-
|
|
108
|
-
- Fixes expiration date results when year is current year and month is invalid
|
|
109
|
-
- Update files in `dist/`
|
|
110
|
-
- Readme clarifications
|
|
111
|
-
|
|
112
|
-
# 2.2.4
|
|
113
|
-
|
|
114
|
-
- Fixes validation of space separated expiration dates
|
|
115
|
-
- Fixes potential validity of slashless expiration dates
|
|
116
|
-
- Fixes validation of expiration dates that are too long
|
|
117
|
-
|
|
118
|
-
# 2.2.3
|
|
119
|
-
|
|
120
|
-
- Fixes CVV validation to not always validate 3-digit values as `isValid: true`
|
|
121
|
-
|
|
122
|
-
# 2.2.2
|
|
123
|
-
|
|
124
|
-
- Fixes 3-digit expiration date handling, such as 220 being Feb, 2020
|
|
125
|
-
|
|
126
|
-
# 2.2.1
|
|
127
|
-
|
|
128
|
-
- Use one Lodash dependency
|
|
129
|
-
|
|
130
|
-
# 2.2.0
|
|
131
|
-
|
|
132
|
-
- CVV validator can accept an array of possible length values
|
|
133
|
-
|
|
134
|
-
# 2.1.0
|
|
135
|
-
|
|
136
|
-
- Contextually validate month based on current date.
|
|
137
|
-
|
|
138
|
-
# 2.0.2
|
|
139
|
-
|
|
140
|
-
- Update `credit-card-type` to 4.0.0
|
|
141
|
-
|
|
142
|
-
# 2.0.1
|
|
143
|
-
|
|
144
|
-
- The npm module now includes built files under `dist/`.
|
|
145
|
-
|
|
146
|
-
# 2.0.0
|
|
147
|
-
|
|
148
|
-
- The returned value for `card.length` is now an `Array` and called `card.lengths` to account for variable-length cards such as UnionPay.
|
|
149
|
-
|
|
150
|
-
# 1.0.0
|
|
151
|
-
|
|
152
|
-
- Initial release
|