creditcard.js 3.0.24 → 3.0.26

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/README.md CHANGED
@@ -15,24 +15,19 @@ creditcard.js is available as a NPM package. You can install through Yarn or NPM
15
15
  ### Yarn
16
16
 
17
17
  ```sh
18
- $ yarn add creditcard.js
18
+ yarn add creditcard.js
19
19
  ```
20
20
 
21
21
  ### NPM
22
22
 
23
23
  ```sh
24
- $ npm install creditcard.js
24
+ npm install creditcard.js
25
25
  ```
26
26
 
27
27
  ## Usage
28
28
 
29
29
  ```javascript
30
- import {
31
- isValid,
32
- isExpirationDateValid,
33
- isSecurityCodeValid,
34
- getCreditCardNameByNumber,
35
- } from 'creditcard.js';
30
+ import { isValid, isExpirationDateValid, isSecurityCodeValid, getCreditCardNameByNumber } from 'creditcard.js';
36
31
 
37
32
  isValid('4916108926268679'); // returns true
38
33
  isExpirationDateValid('02', '2020'); // returns true
@@ -92,7 +87,7 @@ Type: `string`
92
87
 
93
88
  ### `getCreditCardNameByNumber(number)` -> `string`
94
89
 
95
- Returns the credit card type from the card number. _(See the full list of [currently supported cards](#suportted-credit-card-types))_
90
+ Returns the credit card type from the card number. _(See the full list of [currently supported cards](#supported-credit-card-types))_
96
91
 
97
92
  **number**
98
93
 
@@ -101,7 +96,7 @@ Type: `string`
101
96
 
102
97
  ---
103
98
 
104
- ## Suportted credit card types
99
+ ## Supported credit card types
105
100
 
106
101
  - American Express
107
102
  - Aura
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @name creditcard.js 3.0.23
2
+ * @name creditcard.js 3.0.25
3
3
  * @license MIT
4
4
  * @author ContaAzul (contaazul.com)
5
5
  */
@@ -71,42 +71,33 @@ var isValid = function isValid(number) {
71
71
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
72
72
  var cards = options.cards;
73
73
  var rawNumber = removeNonNumbersCaracteres(number);
74
-
75
74
  if (hasSomeInvalidDigit(number) || !hasCorrectLength(rawNumber)) {
76
75
  return false;
77
76
  }
78
-
79
77
  var sum = sumNumber(rawNumber);
80
78
  return checkSum(sum) && validateCardsWhenRequired(number, cards);
81
79
  };
82
-
83
80
  function validateCardsWhenRequired(number, cards) {
84
81
  return !cards || !cards.length || validateCards(number, cards);
85
82
  }
86
-
87
83
  function validateCards(number, cards) {
88
84
  return areCardsSupported(cards) && cards.map(function (c) {
89
85
  return c.toLowerCase();
90
86
  }).includes(getCreditCardNameByNumber(number).toLowerCase());
91
87
  }
92
-
93
88
  function hasCorrectLength(number) {
94
89
  return number && number.length <= 19;
95
90
  }
96
-
97
91
  function removeNonNumbersCaracteres(number) {
98
92
  return number.replace(/\D/g, '');
99
93
  }
100
-
101
94
  function hasSomeInvalidDigit(creditcardNumber) {
102
95
  var invalidDigits = new RegExp('[^0-9- ]');
103
96
  return invalidDigits.test(creditcardNumber);
104
97
  }
105
-
106
98
  function checkSum(sum) {
107
99
  return sum > 0 && sum % 10 === 0;
108
100
  }
109
-
110
101
  function areCardsSupported(passedCards) {
111
102
  var supportedCards = CARDS.map(function (c) {
112
103
  return c.name.toLowerCase();
@@ -115,7 +106,6 @@ function areCardsSupported(passedCards) {
115
106
  return supportedCards.includes(c.toLowerCase());
116
107
  });
117
108
  }
118
-
119
109
  function findCreditCardObjectByNumber(number) {
120
110
  if (!number) return {};
121
111
  var numberOnly = number.replace(/[^\d]/g, '');
@@ -123,35 +113,28 @@ function findCreditCardObjectByNumber(number) {
123
113
  return card.bins.test(numberOnly) && card;
124
114
  }) || {};
125
115
  }
126
-
127
116
  function getCreditCardCodeLengthByNumber(number) {
128
117
  return findCreditCardObjectByNumber(number).codeLength || DEFAULT_CODE_LENGTH;
129
118
  }
130
-
131
119
  function isValidMonth(month) {
132
120
  return !isNaN(month) && month >= 1 && month <= 12;
133
121
  }
134
-
135
122
  function isValidYear(year) {
136
123
  return !isNaN(year) && isValidFullYear(formatFullYear(year));
137
124
  }
138
-
139
125
  function formatFullYear(year) {
140
126
  if (year.length === 2) return dateRange(year);
141
127
  return year.length === 4 ? year : 0;
142
128
  }
143
-
144
129
  function dateRange() {
145
130
  var increaseYear = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
146
131
  var year = parseInt(increaseYear);
147
132
  var today = new Date();
148
133
  return Math.floor(today.getFullYear() / MILLENNIUM) * MILLENNIUM + year;
149
134
  }
150
-
151
135
  function isValidFullYear(year) {
152
136
  return year >= dateRange() && year <= dateRange(MILLENNIUM);
153
137
  }
154
-
155
138
  function isFutureOrPresentDate(month, year) {
156
139
  var fullYear = formatFullYear(year);
157
140
  var currentDate = new Date();
@@ -160,18 +143,15 @@ function isFutureOrPresentDate(month, year) {
160
143
  expirationDate.setFullYear(fullYear, month - 1, 1);
161
144
  return currentDate <= expirationDate;
162
145
  }
163
-
164
146
  function sumNumber(number) {
165
147
  var computed = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];
166
148
  var sum = 0;
167
149
  var digit = 0;
168
150
  var i = number.length;
169
151
  var even = true;
170
-
171
152
  while (i--) {
172
153
  digit = Number(number[i]);
173
154
  sum += (even = !even) ? computed[digit] : digit;
174
155
  }
175
-
176
156
  return sum;
177
157
  }exports.getCreditCardNameByNumber=getCreditCardNameByNumber;exports.isExpirationDateValid=isExpirationDateValid;exports.isSecurityCodeValid=isSecurityCodeValid;exports.isValid=isValid;Object.defineProperty(exports,'__esModule',{value:true});})));
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @name creditcard.js 3.0.23
2
+ * @name creditcard.js 3.0.25
3
3
  * @license MIT
4
4
  * @author ContaAzul (contaazul.com)
5
5
  */
package/package.json CHANGED
@@ -1,35 +1,38 @@
1
1
  {
2
2
  "name": "creditcard.js",
3
- "version": "3.0.24",
3
+ "version": "3.0.26",
4
4
  "description": "A simple library for credit-card validation in JavaScript",
5
5
  "main": "dist/creditcard.js",
6
- "repository": "ContaAzul/creditcard.js",
7
- "author": "@ContaAzul",
8
6
  "files": [
9
7
  "dist"
10
8
  ],
11
9
  "scripts": {
10
+ "preinstall": "yarn dlx only-allow yarn",
11
+ "postinstall": "yarn simple-git-hooks",
12
12
  "build": "yarn build:production",
13
13
  "build:watch": "rollup -c -w",
14
14
  "build:production": "rollup -c",
15
15
  "format": "prettier --write './src/**/*.js'",
16
16
  "lint": "eslint src",
17
+ "lint:fix": "yarn lint --fix",
17
18
  "test": "jest",
18
19
  "test:watch": "yarn test -- --watch",
19
20
  "cov": "jest --coverage",
20
21
  "cov:serve": "yarn cov && static-server .coverage/lcov-report --port 3000 --no-nocache",
21
22
  "cov:publish": "yarn cov && cat ./.coverage/lcov.info | coveralls",
22
- "release": "release-it --config release-it.config.js"
23
+ "release": "release-it --config release-it.config.js",
24
+ "release:preview": "yarn release --ci --dry-run"
23
25
  },
24
- "husky": {
25
- "hooks": {
26
- "pre-commit": "lint-staged",
27
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
28
- }
26
+ "simple-git-hooks": {
27
+ "commit-msg": "yarn commitlint --edit $1",
28
+ "pre-commit": "yarn lint-staged"
29
29
  },
30
30
  "lint-staged": {
31
- "*.{js,vue}": [
32
- "yarn lint"
31
+ "*.js": [
32
+ "yarn lint:fix"
33
+ ],
34
+ "*.{json,md,yml}": [
35
+ "prettier --write"
33
36
  ]
34
37
  },
35
38
  "keywords": [
@@ -39,34 +42,55 @@
39
42
  "validator"
40
43
  ],
41
44
  "devDependencies": {
42
- "@babel/core": "^7.12.10",
43
- "@babel/preset-env": "^7.12.11",
44
- "@commitlint/cli": "^12.1.4",
45
- "@commitlint/config-conventional": "^12.1.4",
46
- "@commitlint/format": "^12.1.4",
47
- "@release-it/conventional-changelog": "^3.3.0",
48
- "babel-jest": "^26.6.3",
49
- "conventional-changelog": "^3.1.24",
50
- "conventional-changelog-conventionalcommits": "^4.6.1",
51
- "coveralls": "^3.1.0",
52
- "eslint": "^7.17.0",
53
- "eslint-config-prettier": "^7.1.0",
54
- "eslint-config-standard": "^16.0.2",
55
- "eslint-plugin-prettier": "^3.3.1",
45
+ "@babel/core": "^7.20.12",
46
+ "@babel/preset-env": "^7.20.2",
47
+ "@commitlint/cli": "^17.4.4",
48
+ "@commitlint/config-conventional": "^17.4.4",
49
+ "@commitlint/format": "^17.4.4",
50
+ "@release-it/conventional-changelog": "^4.3.0",
51
+ "babel-jest": "^29.4.3",
52
+ "conventional-changelog": "^3.1.25",
53
+ "conventional-changelog-conventionalcommits": "^4.6.3",
54
+ "coveralls": "^3.1.1",
55
+ "eslint": "^8.34.0",
56
+ "eslint-config-prettier": "^8.6.0",
57
+ "eslint-config-standard": "^17.0.0",
58
+ "eslint-plugin-import": "^2.27.5",
59
+ "eslint-plugin-n": "^15.6.1",
60
+ "eslint-plugin-prettier": "^4.2.1",
61
+ "eslint-plugin-promise": "^6.1.1",
56
62
  "eslint-plugin-standard": "^5.0.0",
57
- "husky": "^4.2.2",
58
- "jest": "^26.6.3",
59
- "lint-staged": "^9.5.0",
60
- "prettier": "^2.2.1",
61
- "release-it": "^14.11.6",
63
+ "jest": "^29.4.3",
64
+ "lint-staged": "^13.1.2",
65
+ "prettier": "^2.8.4",
66
+ "release-it": "^14.14.3",
62
67
  "rollup": "^2.36.1",
63
68
  "rollup-plugin-babel": "^4.4.0",
64
69
  "rollup-plugin-terser": "^7.0.2",
70
+ "simple-git-hooks": "^2.8.1",
65
71
  "static-server": "^2.2.1"
66
72
  },
67
73
  "publishConfig": {
68
74
  "access": "public",
69
75
  "registry": "https://registry.npmjs.org/"
70
76
  },
77
+ "packageManager": "yarn@3.4.1",
78
+ "engines": {
79
+ "node": ">=18.x",
80
+ "yarn": ">=3.x"
81
+ },
82
+ "homepage": "https://github.com/ContaAzul/creditcard.js",
83
+ "author": {
84
+ "name": "ContaAzul",
85
+ "email": "domphysis@contaazul.com",
86
+ "url": "https://github.com/ContaAzul/creditcard.js"
87
+ },
88
+ "repository": {
89
+ "type": "git",
90
+ "url": "git+https://github.com/ContaAzul/creditcard.js.git"
91
+ },
92
+ "bugs": {
93
+ "url": "https://github.com/ContaAzul/creditcard.js/issues"
94
+ },
71
95
  "license": "MIT"
72
96
  }
package/CHANGELOG.md DELETED
@@ -1,83 +0,0 @@
1
- ## 0.1.2 (January 26, 2016)
2
-
3
- ### First Release
4
- * First commit with version.
5
- ([@fernahh](https://github.com/fernahh))
6
- * Update README.
7
- ([@fernahh](https://github.com/fernahh))
8
- * Update log size.
9
- ([@matheuspoleza](https://github.com/matheuspoleza))
10
- * Fixed main npm script.
11
- ([@fernahh](https://github.com/fernahh))
12
- * Add project logo.
13
- ([@matheuspoleza](https://github.com/matheuspoleza))
14
- * Update README
15
- ([@caarlos0](https://github.com/caarlos0))
16
- * Fixed CI badge
17
- ([@caarlos0](https://github.com/caarlos0))
18
- * Improved README english
19
- ([@caarlos0](https://github.com/caarlos0))
20
- * Change to public for bower repository
21
- ([@fernahh](https://github.com/fernahh))
22
- * Fixed travis build script.
23
- ([@matheuspoleza](https://github.com/matheuspoleza))
24
- * Add grunt to the project and update npm scripts.
25
- ([@matheuspoleza](https://github.com/matheuspoleza))
26
- * Add preinstall task.
27
- ([@matheuspoleza](https://github.com/matheuspoleza))
28
- * Change author project.
29
- ([@matheuspoleza](https://github.com/matheuspoleza))
30
- * Add information about browser support.
31
- ([@fernahh](https://github.com/fernahh))
32
- * Add information about browser support.
33
- ([@fernahh](https://github.com/fernahh))
34
- * Add travis build status.
35
- ([@fernahh](https://github.com/fernahh))
36
- * Add travis manifest.
37
- ([@fernahh](https://github.com/fernahh))
38
- * Add `rimraf` and update clean task.
39
- ([@fernahh](https://github.com/fernahh))
40
- * Remove `Bin` regex.
41
- ([@fernahh](https://github.com/fernahh))
42
- * Change `.ignore` and configuration files to publish package.
43
- ([@fernahh](https://github.com/fernahh))
44
- * Refactor of npm scripts.
45
- ([@fernahh](https://github.com/fernahh))
46
- * Create tasks to build nodejs module.
47
- ([@fernahh](https://github.com/fernahh))
48
- * Change package description.
49
- ([@fernahh](https://github.com/fernahh))
50
- * Create Readme.
51
- ([@fernahh](https://github.com/fernahh))
52
- * Add test watcher.
53
- ([@fernahh](https://github.com/fernahh))
54
- * Add editor config.
55
- ([@fernahh](https://github.com/fernahh))
56
- * Add author information.
57
- ([@fernahh](https://github.com/fernahh))
58
- * Create use case example.
59
- ([@fernahh](https://github.com/fernahh))
60
- * Add lint to tests.
61
- ([@fernahh](https://github.com/fernahh))
62
- * Change build scripts and update of ecmascript syntax at credit card class.
63
- ([@fernahh](https://github.com/fernahh))
64
- * Change npm scripts and add eslint to the project.
65
- ([@fernahh](https://github.com/fernahh))
66
- * Change npm scripts.
67
- ([@fernahh](https://github.com/fernahh))
68
- * Refactor of all credit card class.
69
- ([@fernahh](https://github.com/fernahh))
70
- * Create tests for all credit card brands.
71
- ([@fernahh](https://github.com/fernahh))
72
- * Create expire date validation method. Function name: `validateExpireDate()`.
73
- ([@fernahh](https://github.com/fernahh))
74
- * Remove security code validation from regex.
75
- ([@fernahh](https://github.com/fernahh))
76
- * Create security code validation method. Function name: `validateSecuryCide()`.
77
- ([@fernahh](https://github.com/fernahh))
78
- * Create credit card validation method. Function name `validate()`.
79
- ([@fernahh](https://github.com/fernahh))
80
- * Implemented Luhn algorithm. ([@fernahh](https://github.com/fernahh))
81
- * Create expect methods. ([@fernahh](https://github.com/fernahh))
82
- * Formatted credit card names. ([@fernahh](https://github.com/fernahh))
83
- * Initial commit, with CreditCard function and tests. ([@fernahh](https://github.com/fernahh))