card-validator 8.1.1 → 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.
@@ -12,6 +12,6 @@ jobs:
12
12
  - name: Use Node.js
13
13
  uses: actions/setup-node@v1
14
14
  with:
15
- node-version: "14.x"
15
+ node-version: "18.x"
16
16
  - run: npm install
17
17
  - run: npm test
@@ -1,5 +1,5 @@
1
1
  import type { Verification } from "./types";
2
- declare type CreditCardType = {
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
- declare type CardNumberOptions = {
16
+ type CardNumberOptions = {
17
17
  maxLength?: number;
18
18
  luhnValidateUnionPay?: boolean;
19
19
  };
@@ -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/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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -1,4 +1,4 @@
1
- export declare type MonthAndYear = {
1
+ export type MonthAndYear = {
2
2
  month: string;
3
3
  year: string;
4
4
  };
@@ -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(),
@@ -1,5 +1,5 @@
1
1
  import type { Verification } from "./types";
2
- declare type PostalCodeOptions = {
2
+ type PostalCodeOptions = {
3
3
  minLength?: number;
4
4
  };
5
5
  export declare function postalCode(value: string | unknown, options?: PostalCodeOptions): Verification;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare type Verification = {
1
+ export type Verification = {
2
2
  isValid: boolean;
3
3
  isPotentiallyValid: boolean;
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "card-validator",
3
- "version": "8.1.1",
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,19 +20,23 @@
20
20
  "author": "Braintree <code@getbraintree.com> (https://www.braintreepayments.com/)",
21
21
  "license": "MIT",
22
22
  "devDependencies": {
23
- "@types/jest": "^26.0.23",
24
- "@types/node": "^15.0.2",
25
- "eslint": "^7.26.0",
26
- "eslint-config-braintree": "^5.0.0-typescript-prep-rc.18",
27
- "jest": "^26.6.3",
28
- "prettier": "^2.3.0",
29
- "ts-jest": "^26.5.6",
30
- "typescript": "^4.2.4"
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
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": {
@@ -263,7 +263,7 @@ describe("number validates", () => {
263
263
  expect(actual.isValid).toBe(expected.isValid);
264
264
  });
265
265
  });
266
- }
266
+ },
267
267
  );
268
268
 
269
269
  describe("UnionPay", () => {
@@ -68,6 +68,6 @@ describe("cardholderName", () => {
68
68
  it.each(tests)("parses %s to be %p", (parseMe, meta) => {
69
69
  expect(cardholderName(parseMe)).toEqual(meta);
70
70
  });
71
- }
71
+ },
72
72
  );
73
73
  });
@@ -1068,7 +1068,7 @@ describe("expirationDate validates", () => {
1068
1068
  "parses %s to be %p",
1069
1069
  (exp: string | number, meta: ExpirationDateVerification) => {
1070
1070
  expect(expirationDate(exp)).toEqual(meta);
1071
- }
1071
+ },
1072
1072
  );
1073
1073
  });
1074
1074
 
@@ -1287,7 +1287,7 @@ describe("expirationDate validates", () => {
1287
1287
  "parses %s to be %p",
1288
1288
  (exp, meta: ExpirationDateVerification) => {
1289
1289
  expect(expirationDate(exp)).toEqual(meta);
1290
- }
1290
+ },
1291
1291
  );
1292
1292
  });
1293
1293
 
@@ -1309,7 +1309,7 @@ describe("expirationDate validates", () => {
1309
1309
 
1310
1310
  it("accepts maxElapsedYear", () => {
1311
1311
  expect(
1312
- expirationDate(`${currentMonth} / ${yearsFromNow(20)}`, 20)
1312
+ expirationDate(`${currentMonth} / ${yearsFromNow(20)}`, 20),
1313
1313
  ).toEqual({
1314
1314
  isValid: true,
1315
1315
  isPotentiallyValid: true,
@@ -1317,7 +1317,7 @@ describe("expirationDate validates", () => {
1317
1317
  year: yearsFromNow(20).toString(),
1318
1318
  });
1319
1319
  expect(
1320
- expirationDate(`${currentMonth} / ${yearsFromNow(21)}`, 20)
1320
+ expirationDate(`${currentMonth} / ${yearsFromNow(21)}`, 20),
1321
1321
  ).toEqual({
1322
1322
  isValid: false,
1323
1323
  isPotentiallyValid: false,
@@ -221,7 +221,7 @@ describe("expirationYear", () => {
221
221
  it.each(tests)("parses %s to be %p", (exp, meta) => {
222
222
  expect(expirationYear(exp)).toEqual(meta);
223
223
  });
224
- }
224
+ },
225
225
  );
226
226
 
227
227
  it("defaults maxElapsedYear is 19", () => {
@@ -74,7 +74,7 @@ describe("parse-date", () => {
74
74
  it.each(tests)("parses %s to be %p", (parseMe, meta) => {
75
75
  expect(parseDate(parseMe)).toEqual(meta);
76
76
  });
77
- }
77
+ },
78
78
  );
79
79
 
80
80
  describe("datestrings starting with 10-12", () => {
@@ -55,7 +55,7 @@ describe("postalCode", () => {
55
55
  it.each(tests)("parses %s to be %p", (parseMe, meta) => {
56
56
  expect(postalCode(parseMe)).toEqual(meta);
57
57
  });
58
- }
58
+ },
59
59
  );
60
60
 
61
61
  describe("custom min length", () => {
@@ -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
 
@@ -5,7 +5,7 @@ const MAX_LENGTH = 255;
5
5
 
6
6
  function verification(
7
7
  isValid: boolean,
8
- isPotentiallyValid: boolean
8
+ isPotentiallyValid: boolean,
9
9
  ): Verification {
10
10
  return { isValid, isPotentiallyValid };
11
11
  }
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
 
@@ -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
 
@@ -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
 
@@ -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
 
@@ -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,156 +0,0 @@
1
- # 8.1.1
2
-
3
- - Fix issue where a potentially valid year would evaulate as invalid (#93)
4
-
5
- # 8.1.0
6
-
7
- - Add `cardholderName` verification method
8
-
9
- # 8.0.0
10
-
11
- _Breaking Changes_
12
-
13
- - Use `export =` instead of `export default` for main export (use `"esModuleInterop": true` flag in your tsconfig to maintain the `default` module behavior)
14
-
15
- # 7.1.0
16
-
17
- - The cardValidator object is now available as the `default` import when using es modules (thanks @leomp12)
18
-
19
- # 7.0.1
20
-
21
- - Fixup export for credit-card-type for typescript projects (closes #79)
22
-
23
- # 7.0.0
24
-
25
- - Add typescript types
26
-
27
- _Breaking Changes_
28
-
29
- - Upgrade credit-card-type to v9.0.0
30
- - Drop support for card numbers instantiated with `new String(number)`
31
-
32
- # 6.2.0
33
-
34
- - Adjust expiration date to accept dates formatted as `YYYY-MM` (the HTML autofill spec). Closes #69 (thanks @schuylr)
35
-
36
- # 6.1.0
37
-
38
- - Add option to set a `maxLength` for card number valiation
39
-
40
- # 6.0.0
41
-
42
- - Update credit-card-type to v8.0.0
43
-
44
- _Breaking Changes_
45
-
46
- - 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.
47
-
48
- # 5.1.0
49
-
50
- - Add optional options object with `luhnValidateUnionPay` parameter to force luhn validity check of UnionPay cards
51
- - Update tests to account for ELO cards
52
-
53
- # 5.0.0
54
-
55
- - Update `credit-card-type` to v7.0.0
56
-
57
- _Breaking Changes_
58
-
59
- - Mastercard enum changed from `master-card` to `mastercard`
60
-
61
- # 4.3.0
62
-
63
- - Support custom card brands
64
- - Require minimum version of credit-card-type to be v6.2.0
65
-
66
- # 4.2.0
67
-
68
- - Allow `maxElapsedYear` to be configurable in `expirationYear` and `expirationDate` (thanks @wozaki)
69
-
70
- # 4.1.1
71
-
72
- - Update `credit-card-type` to v6.0.0
73
-
74
- # 4.1.0
75
-
76
- - Add options object for postal code validation to specify min length
77
-
78
- # 4.0.0
79
-
80
- - **Breaking change**: Remove `dist` files. You must use `npm` to use this module
81
- - **Breaking change**: Remove support for primitive constructors like `new String()`
82
-
83
- # 3.0.1
84
-
85
- - Fix postal code validation to be valid if 3 or more characters
86
-
87
- # 3.0.0
88
-
89
- - correctly identify Maestro cards beginning with `6`
90
- - **Breaking change**: The format of the `card` object returned has changed. `pattern` has been replaced by `prefixPattern` and `exactPattern`.
91
-
92
- # 2.3.0
93
-
94
- - valid.expirationDate can take an object with month and year fields or a string value
95
-
96
- # 2.2.8
97
-
98
- - Update `dist` to include version `4.0.3` of credit-card-type
99
-
100
- # 2.2.7
101
-
102
- - Including `dist` from `2.2.6`
103
-
104
- # 2.2.6
105
-
106
- - Fixes cases where card numbers were incorrectly reported as `isPotentiallyValid: false` when more digits could still be entered
107
-
108
- - issue #20 and PR #21
109
-
110
- # 2.2.5
111
-
112
- - Fixes expiration date results when year is current year and month is invalid
113
- - Update files in `dist/`
114
- - Readme clarifications
115
-
116
- # 2.2.4
117
-
118
- - Fixes validation of space separated expiration dates
119
- - Fixes potential validity of slashless expiration dates
120
- - Fixes validation of expiration dates that are too long
121
-
122
- # 2.2.3
123
-
124
- - Fixes CVV validation to not always validate 3-digit values as `isValid: true`
125
-
126
- # 2.2.2
127
-
128
- - Fixes 3-digit expiration date handling, such as 220 being Feb, 2020
129
-
130
- # 2.2.1
131
-
132
- - Use one Lodash dependency
133
-
134
- # 2.2.0
135
-
136
- - CVV validator can accept an array of possible length values
137
-
138
- # 2.1.0
139
-
140
- - Contextually validate month based on current date.
141
-
142
- # 2.0.2
143
-
144
- - Update `credit-card-type` to 4.0.0
145
-
146
- # 2.0.1
147
-
148
- - The npm module now includes built files under `dist/`.
149
-
150
- # 2.0.0
151
-
152
- - The returned value for `card.length` is now an `Array` and called `card.lengths` to account for variable-length cards such as UnionPay.
153
-
154
- # 1.0.0
155
-
156
- - Initial release