From f58b1c82bd449176afe196dc2e4989a2ff697496 Mon Sep 17 00:00:00 2001 From: Cassio Cardoso Date: Sat, 2 May 2020 09:55:25 +0200 Subject: [PATCH 1/3] add Dankort support --- README.md | 11 ++++++++--- __tests__/index.js | 18 ++++++++++++------ index.js | 6 ++++-- lib/card-types.js | 16 +++++++++++++++- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 69068b3e..1976c0cf 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ console.log(ambiguousCards[2].niceType); // 'Maestro' | Key | Type | Description | | ---------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `niceType` | `String` | A pretty printed representation of the card brand.
- `Visa`
- `Mastercard`
- `American Express`
- `Diners Club`
- `Discover`
- `JCB`
- `UnionPay`
- `Maestro`
- `Mir`
- `Elo`
- `Hiper`
- `Hipercard` | -| `type` | `String` | A code-friendly presentation of the card brand (useful to class names in CSS). Please refer to Card Type "Constants" below for the list of possible values.
- `visa`
- `mastercard`
- `american-express`
- `diners-club`
- `discover`
- `jcb`
- `unionpay`
- `maestro`
- `mir`
- `elo`
- `hiper`
- `hipercard` | +| `niceType` | `String` | A pretty printed representation of the card brand.
- `Visa`
- `Mastercard`
- `American Express`
- `Diners Club`
- `Discover`
- `JCB`
- `UnionPay`
- `Maestro`
- `Mir`
- `Elo`
- `Hiper`
- `Hipercard`
- `Dankort` | +| `type` | `String` | A code-friendly presentation of the card brand (useful to class names in CSS). Please refer to Card Type "Constants" below for the list of possible values.
- `visa`
- `mastercard`
- `american-express`
- `diners-club`
- `discover`
- `jcb`
- `unionpay`
- `maestro`
- `mir`
- `elo`
- `hiper`
- `hipercard`
- `dankort` | | `gaps` | `Array` | The expected indeces of gaps in a string representation of the card number. For example, in a Visa card, `4111 1111 1111 1111`, there are expected spaces in the 4th, 8th, and 12th positions. This is useful in setting your own formatting rules. | | `lengths` | `Array` | The expected lengths of the card number as an array of strings (excluding spaces and `/` characters). | | `code` | `Object` | The information regarding the security code for the determined card. Learn more about the [code object](#code) below. | @@ -58,6 +58,7 @@ If no card types are found, this returns an empty array. Named variables are provided for each of the supported card types: - `AMERICAN_EXPRESS` +- `DANKORT` - `DINERS_CLUB` - `DISCOVER` - `ELO` @@ -88,6 +89,7 @@ Card brands provide different nomenclature for their security codes as well as v | `Elo` | `CVE` | 3 | | `Hiper` | `CVC` | 3 | | `Hipercard` | `CVC` | 4 | +| `Dankort` | `CVC` | 3 | A full response for a `Visa` card will look like this: @@ -146,6 +148,8 @@ card is _either_ a Visa or an Elo card. Once the card number becomes `401178`, the modules sees that an exact match for the ELO bin has been made, and the module reports that the card can only be an Elo card. +The above rule is also applied for identifying Dankort cards, which starts with `5019`. + #### Adding Card Types You can add additional card brands not supportted by the the module with `addCard`. Pass in the configuration object. @@ -195,7 +199,8 @@ Adding new cards puts them at the bottom of the priority for testing. Priority i creditCardType.types.ELO, creditCardType.types.MIR, creditCardType.types.HIPER, - creditCardType.types.HIPERCARD + creditCardType.types.HIPERCARD, + creditCardType.types.DANKORT ]; ``` diff --git a/__tests__/index.js b/__tests__/index.js index 3b6630b0..5c1476b7 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -155,7 +155,9 @@ describe('creditCardType', () => { ['637609', 'hiper'], ['637599', 'hiper'], ['637612', 'hiper'], - ['637568', 'hiper'] + ['637568', 'hiper'], + + ['5019', 'dankort'] ])('Matches %s to brand %s', (number, type) => { const actual = creditCardType(number); @@ -183,13 +185,15 @@ describe('creditCardType', () => { 'elo', 'mir', 'hiper', - 'hipercard' + 'hipercard', + 'dankort' ] ], ['2', ['mastercard', 'jcb', 'mir']], ['3', ['american-express', 'diners-club', 'jcb']], - ['5', ['mastercard', 'maestro', 'elo']], - ['50', ['maestro', 'elo']], + ['5', ['mastercard', 'maestro', 'elo', 'dankort']], + ['50', ['maestro', 'elo', 'dankort']], + ['501', ['maestro', 'dankort']], ['6', ['discover', 'unionpay', 'maestro', 'elo', 'hiper', 'hipercard']], ['60', ['discover', 'maestro', 'hipercard']], ['601', ['discover', 'maestro']], @@ -262,7 +266,8 @@ describe('creditCardType', () => { ['Diners Club', '30569309025904', {size: 3, name: 'CVV'}], ['UnionPay', '6220558812340000', {size: 3, name: 'CVN'}], ['Maestro', '6304000000000000', {size: 3, name: 'CVC'}], - ['Mir', '2200000000000000', {size: 3, name: 'CVP2'}] + ['Mir', '2200000000000000', {size: 3, name: 'CVP2'}], + ['Dankort', '501912345678', {size: 3, name: 'CVC'}] ])('returns security codes for %s', (brand, number, code) => { const parsedCode = creditCardType(number)[0].code; @@ -280,7 +285,8 @@ describe('creditCardType', () => { ['Visa', '4', {type: 'visa', lengths: [16, 18, 19]}], ['Mastercard', '54', {type: 'mastercard', lengths: [16]}], ['JCB', '35', {type: 'jcb', lengths: [16, 17, 18, 19]}], - ['Mir', '220', {type: 'mir', lengths: [16, 17, 18, 19]}] + ['Mir', '220', {type: 'mir', lengths: [16, 17, 18, 19]}], + ['Dankort', '5019', {type: 'dankort', lengths: [16]}] ])('returns lengths for %s', (brand, number, meta) => { const cardType = creditCardType(number)[0]; diff --git a/index.js b/index.js index f3b5c28a..c5c2b1ec 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,8 @@ var cardNames = { ELO: 'elo', MIR: 'mir', HIPER: 'hiper', - HIPERCARD: 'hipercard' + HIPERCARD: 'hipercard', + DANKORT: 'dankort' }; var ORIGINAL_TEST_ORDER = [ @@ -36,7 +37,8 @@ var ORIGINAL_TEST_ORDER = [ cardNames.ELO, cardNames.MIR, cardNames.HIPER, - cardNames.HIPERCARD + cardNames.HIPERCARD, + cardNames.DANKORT ]; testOrder = clone(ORIGINAL_TEST_ORDER); diff --git a/lib/card-types.js b/lib/card-types.js index 03480d41..d9b735a9 100644 --- a/lib/card-types.js +++ b/lib/card-types.js @@ -134,7 +134,8 @@ var cardTypes = { type: 'maestro', patterns: [ 493698, - [500000, 506698], + [5000, 5018], + [502000, 506698], [506779, 508999], [56, 59], 63, @@ -227,6 +228,19 @@ var cardTypes = { name: 'CVC', size: 3 } + }, + dankort: { + niceType: 'Dankort', + type: 'dankort', + patterns: [ + 5019 + ], + gaps: [4, 8, 12], + lengths: [16], + code: { + name: 'CVC', + size: 3 + } } }; From bf247a9c614151de8b5217620baeb225db6e7743 Mon Sep 17 00:00:00 2001 From: Cassio Cardoso Date: Tue, 5 May 2020 09:21:10 +0200 Subject: [PATCH 2/3] Update README.md Co-authored-by: Aki --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1976c0cf..776bfa7d 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ card is _either_ a Visa or an Elo card. Once the card number becomes `401178`, the modules sees that an exact match for the ELO bin has been made, and the module reports that the card can only be an Elo card. -The above rule is also applied for identifying Dankort cards, which starts with `5019`. +The above rule is also applied for identifying Dankort cards, which start with `5019`. #### Adding Card Types From 4d91c1181ef6622fd343cc4565d8dd89a51633d7 Mon Sep 17 00:00:00 2001 From: Cassio Cardoso Date: Tue, 5 May 2020 09:21:21 +0200 Subject: [PATCH 3/3] Update README.md Co-authored-by: Aki --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 776bfa7d..87f0df42 100644 --- a/README.md +++ b/README.md @@ -199,8 +199,8 @@ Adding new cards puts them at the bottom of the priority for testing. Priority i creditCardType.types.ELO, creditCardType.types.MIR, creditCardType.types.HIPER, - creditCardType.types.HIPERCARD, - creditCardType.types.DANKORT + creditCardType.types.HIPERCARD, + creditCardType.types.DANKORT ]; ```