Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

credit-card-type

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

credit-card-type - npm Package Compare versions

Comparing version 8.3.0 to 9.0.0

.prettierignore

95

CHANGELOG.md

@@ -1,13 +0,19 @@

8.3.0
=====
# 9.0.0
- Add typescript types
_Breaking Changes_
- Drop Bower Support
- Drop support for card numbers instantiated with `new String(number)`
# 8.3.0
- Add support for series 8 UnionPay cards (fixes #95 thanks @leebradley)
8.2.0
=====
# 8.2.0
- Add 14 and 15 length configuration to UnionPay cards
8.1.0
=====
# 8.1.0

@@ -17,13 +23,11 @@ - Add support for Hiper cards

8.0.0
=====
# 8.0.0
- Improve pattern recognition for card types
*Breaking Changes*
_Breaking Changes_
- 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.
7.1.0
=====
# 7.1.0

@@ -33,37 +37,31 @@ - Add support for `Elo` card type

7.0.0
=====
# 7.0.0
- Updates "master-card" enum to "mastercard"
6.3.0
=====
# 6.3.0
- Add support for `MIR` card type (thanks @antongolub)
6.2.0
=====
# 6.2.0
- Allow custom card brands to be added
6.1.1
=====
# 6.1.1
- Correct Mastercard bin range for series 2 bins
6.1.0
=====
# 6.1.0
- Add support for JCB cards of length 17, 18, and 19 (#54, thanks @zeh)
6.0.0
=====
# 6.0.0
- Update mastercard niceType property to `Mastercard` to match new brand guidelines
__Breaking Changes__
**Breaking Changes**
- Remove internal properties `prefixPattern` and `exactPattern` from returned object
5.0.4
=====
# 5.0.4

@@ -73,58 +71,48 @@ - Correct Discover to respect lengths for international cards

5.0.3
=====
# 5.0.3
- Fix prefix pattern for MasterCard numbers starting with `27`
5.0.2
=====
# 5.0.2
- Fix checking for UnionPay ranges
5.0.1
=====
# 5.0.1
- Visa cards can now be 16, 18, or 19 digits.
5.0.0
=====
# 5.0.0
- Card matching has been replaced with a two-tier process. This simplifies the matching process for ambiguous numbers.
- Partial BIN matches (`prefixPattern`) are accumulated separately from exact BIN matches (`exactPattern`).
- If there were any exact BIN matches, those matches are returned.
- If there are no exact BIN matches, all partial matches are returned.
4.1.0
=====
- Partial BIN matches (`prefixPattern`) are accumulated separately from exact BIN matches (`exactPattern`).
- If there were any exact BIN matches, those matches are returned.
- If there are no exact BIN matches, all partial matches are returned.
# 4.1.0
- Add `getTypeInfo` and `types` exports for getting type information such as number spacing given a type string such as `visa`.
4.0.3
=====
# 4.0.3
- Remove behavior where some UnionPay cards displayed Discover and UnionPay as possible card types
4.0.2
=====
# 4.0.2
- Add support for series 2 MasterCard bins (ranging from 222100 to 272099)
- Add support for series 2 MasterCard bins (ranging from 222100 to 272099)
- Removes dependency on Lodash
4.0.1
=====
# 4.0.1
- Switch to one version of Lodash
4.0.0
=====
# 4.0.0
- Further resolve ambiguity issues with various cards; return an array of potential card types instead of a single type
3.0.0
=====
# 3.0.0
- Resolve ambiguity issues with Maestro and Discover cards
2.0.0
=====
# 2.0.0

@@ -134,5 +122,4 @@ - Add support for Maestro and UnionPay

1.0.0
=====
# 1.0.0
- Initial Release
{
"name": "credit-card-type",
"version": "8.3.0",
"version": "9.0.0",
"description": "A library for determining credit card type",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "mocha test/**/*.js",
"build": "npm run lint && gulp build"
"lint": "eslint --ext js,ts .",
"posttest": "npm run lint",
"test": "jest",
"prepublishOnly": "npm run build",
"prebuild": "prettier --write .",
"build": "tsc --declaration"
},

@@ -20,15 +23,17 @@ "repository": {

"devDependencies": {
"browserify": "^16.5.0",
"chai": "^4.2.0",
"del": "^5.1.0",
"eslint": "^6.3.0",
"eslint-config-braintree": "^4.0.0",
"gulp": "^4.0.2",
"gulp-rename": "^1.2.0",
"gulp-size": "^3.0.0",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "^3.0.2",
"mocha": "^6.2.0",
"vinyl-source-stream": "^2.0.0"
"@types/jest": "^25.2.1",
"eslint": "^6.8.0",
"eslint-config-braintree": "5.0.0-typescript-prep-rc.17",
"jest": "^25.3.0",
"prettier": "^2.0.4",
"ts-jest": "^25.3.1",
"typescript": "^3.8.3"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testPathIgnorePatterns": [
"<rootDir>/src/__tests__/helper.ts"
]
}
}

@@ -1,3 +0,2 @@

Credit Card Type [![Build Status](https://travis-ci.org/braintree/credit-card-type.svg)](https://travis-ci.org/braintree/credit-card-type) [![npm version](https://badge.fury.io/js/credit-card-type.svg)](http://badge.fury.io/js/credit-card-type) [![Bower](https://badge.fury.io/bo/credit-card-type.svg)](http://badge.fury.io/bo/credit-card-type)
================
# Credit Card Type [![Build Status](https://travis-ci.org/braintree/credit-card-type.svg)](https://travis-ci.org/braintree/credit-card-type) [![npm version](https://badge.fury.io/js/credit-card-type.svg)](http://badge.fury.io/js/credit-card-type) [![Bower](https://badge.fury.io/bo/credit-card-type.svg)](http://badge.fury.io/bo/credit-card-type)

@@ -9,2 +8,3 @@ Credit Card Type provides a useful utility method for determining a credit card type from both fully qualified and partial numbers. This is not a validation library but rather a smaller component to help you build your own validation or UI library.

## Download
To install via npm:

@@ -16,21 +16,15 @@

To install via Bower:
```bash
bower install credit-card-type
```
## Example
```javascript
var creditCardType = require('credit-card-type');
var creditCardType = require("credit-card-type");
var visaCards = creditCardType('4111');
console.log(visaCards[0].type); // 'visa'
var visaCards = creditCardType("4111");
console.log(visaCards[0].type); // 'visa'
var ambiguousCards = creditCardType('6');
console.log(ambiguousCards.length); // 3
console.log(ambiguousCards[0].niceType); // 'Discover'
console.log(ambiguousCards[1].niceType); // 'UnionPay'
console.log(ambiguousCards[2].niceType); // 'Maestro'
var ambiguousCards = creditCardType("6");
console.log(ambiguousCards.length); // 3
console.log(ambiguousCards[0].niceType); // 'Discover'
console.log(ambiguousCards[1].niceType); // 'UnionPay'
console.log(ambiguousCards[2].niceType); // 'Maestro'
```

@@ -45,6 +39,6 @@

| Key | Type | Description |
|------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ---------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `niceType` | `String` | A pretty printed representation of the card brand.<br/>- `Visa`<br />- `Mastercard`<br />- `American Express`<br />- `Diners Club`<br />- `Discover`<br />- `JCB`<br />- `UnionPay`<br />- `Maestro`<br />- `Mir`<br />- `Elo`<br />- `Hiper`<br />- `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.<br/>- `visa`<br />- `mastercard`<br />- `american-express`<br />- `diners-club`<br />- `discover`<br />- `jcb`<br />- `unionpay`<br />- `maestro`<br />- `mir`<br /> - `elo`<br /> - `hiper`<br /> - `hipercard` |
| `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. |
| `gaps` | `Array` | The expected indices 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). |

@@ -63,14 +57,14 @@ | `code` | `Object` | The information regarding the security code for the determined card. Learn more about the [code object](#code) below. |

* `AMERICAN_EXPRESS`
* `DINERS_CLUB`
* `DISCOVER`
* `ELO`
* `HIPERCARD`
* `HIPER`
* `JCB`
* `MAESTRO`
* `MASTERCARD`
* `MIR`
* `UNIONPAY`
* `VISA`
- `AMERICAN_EXPRESS`
- `DINERS_CLUB`
- `DISCOVER`
- `ELO`
- `HIPERCARD`
- `HIPER`
- `JCB`
- `MAESTRO`
- `MASTERCARD`
- `MIR`
- `UNIONPAY`
- `VISA`

@@ -81,26 +75,26 @@ #### `code`

| Brand | Name | Size |
|--------------------|-------|------|
| `Visa` | `CVV` | 3 |
| `Mastercard` | `CVC` | 3 |
| `American Express` | `CID` | 4 |
| `Diners Club` | `CVV` | 3 |
| `Discover` | `CID` | 3 |
| `JCB` | `CVV` | 3 |
| `UnionPay` | `CVN` | 3 |
| `Maestro` | `CVC` | 3 |
| Brand | Name | Size |
| ------------------ | ------ | ---- |
| `Visa` | `CVV` | 3 |
| `Mastercard` | `CVC` | 3 |
| `American Express` | `CID` | 4 |
| `Diners Club` | `CVV` | 3 |
| `Discover` | `CID` | 3 |
| `JCB` | `CVV` | 3 |
| `UnionPay` | `CVN` | 3 |
| `Maestro` | `CVC` | 3 |
| `Mir` | `CVP2` | 3 |
| `Elo` | `CVE` | 3 |
| `Hiper` | `CVC` | 3 |
| `Hipercard` | `CVC` | 4 |
| `Elo` | `CVE` | 3 |
| `Hiper` | `CVC` | 3 |
| `Hipercard` | `CVC` | 4 |
A full response for a `Visa` card will look like this:
```javascript
```json
{
niceType: 'Visa',
type: 'visa',
gaps: [ 4, 8, 12 ],
lengths: [16],
code: { name: 'CVV', size: 3 }
"niceType": "Visa",
"type": "visa",
"gaps": [4, 8, 12],
"lengths": [16],
"code": { "name": "CVV", "size": 3 }
}

@@ -114,5 +108,5 @@ ```

```javascript
var creditCardType = require('credit-card-type');
var getTypeInfo = require('credit-card-type').getTypeInfo;
var CardType = require('credit-card-type').types;
var creditCardType = require("credit-card-type");
var getTypeInfo = require("credit-card-type").getTypeInfo;
var CardType = require("credit-card-type").types;
```

@@ -123,3 +117,6 @@

```javascript
import creditCardType, { getTypeInfo, types as CardType } from 'credit-card-type';
import creditCardType, {
getTypeInfo,
types as CardType,
} from "credit-card-type";
```

@@ -130,4 +127,4 @@

```javascript
creditCardType(cardNumber).filter(function(card) {
return card.type == CardType.MASTERCARD || card.type == CardType.VISA;
creditCardType(cardNumber).filter(function (card) {
return card.type === CardType.MASTERCARD || card.type === CardType.VISA;
});

@@ -156,18 +153,15 @@ ```

You can add additional card brands not supportted by the the module with `addCard`. Pass in the configuration object.
You can add additional card brands not supported by the module with `addCard`. Pass in the configuration object.
```javascript
creditCardType.addCard({
niceType: 'NewCard',
type: 'new-card',
patterns: [
2345,
2376
],
niceType: "NewCard",
type: "new-card",
patterns: [2345, 2376],
gaps: [4, 8, 12],
lengths: [16],
code: {
name: 'CVV',
size: 3
}
name: "CVV",
size: 3,
},
});

@@ -180,14 +174,11 @@ ```

creditCardType.addCard({
niceType: 'Visa with Custom Nice Type',
niceType: "Visa with Custom Nice Type",
type: creditCardType.types.VISA,
patterns: [
41111,
[44, 47]
],
patterns: [41111, [44, 47]],
gaps: [4, 8, 12],
lengths: [13, 16, 19], // add support for old, deprecated 13 digit visas
code: {
name: 'CVV',
size: 3
}
name: "CVV",
size: 3,
},
});

@@ -211,4 +202,4 @@ ```

creditCardType.types.HIPER,
creditCardType.types.HIPERCARD
]
creditCardType.types.HIPERCARD,
];
```

@@ -219,4 +210,4 @@

```javascript
creditCardType.changeOrder('my-new-card', 0); // give custom card type the highest priority
creditCardType.changeOrder('my-new-card', 3); // give it a priority at position 3 in the test order array
creditCardType.changeOrder("my-new-card", 0); // give custom card type the highest priority
creditCardType.changeOrder("my-new-card", 3); // give it a priority at position 3 in the test order array
```

@@ -242,4 +233,4 @@

creditCardType.updateCard(creditCardType.types.VISA, {
niceType: 'Fancy Visa',
lengths: [11, 16]
niceType: "Fancy Visa",
lengths: [11, 16],
});

@@ -254,4 +245,4 @@

// unchanged properties
visa.gaps // [4, 8, 12]
visa.code.name // 'CVV'
visa.gaps; // [4, 8, 12]
visa.code.name; // 'CVV'
```

@@ -281,3 +272,3 @@

return components.join(' ');
return components.join(" ");
}

@@ -288,3 +279,3 @@

prettyCardNumber('xxxxxxxxxx343', CardType.AMERICAN_EXPRESS); // 'xxxx xxxxxx 343'
prettyCardNumber("xxxxxxxxxx343", CardType.AMERICAN_EXPRESS); // 'xxxx xxxxxx 343'
```

@@ -291,0 +282,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc