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 4.1.0 to 5.0.0

dist/js/app.built.js

8

CHANGELOG.md

@@ -0,1 +1,9 @@

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

@@ -2,0 +10,0 @@ =====

67

index.js

@@ -16,11 +16,23 @@ 'use strict';

var CVN = 'CVN';
var testOrder = [
VISA,
MASTERCARD,
AMERICAN_EXPRESS,
DINERS_CLUB,
DISCOVER,
JCB,
UNIONPAY,
MAESTRO
];
function clone(x) {
var pattern, dupe;
var prefixPattern, exactPattern, dupe;
if (!x) { return null; }
pattern = x.pattern.source;
prefixPattern = x.prefixPattern.source;
exactPattern = x.exactPattern.source;
dupe = JSON.parse(JSON.stringify(x));
dupe.pattern = pattern;
dupe.prefixPattern = prefixPattern;
dupe.exactPattern = exactPattern;

@@ -33,3 +45,4 @@ return dupe;

type: VISA,
pattern: /^4\d*$/,
prefixPattern: /^4$/,
exactPattern: /^4\d*$/,
gaps: [4, 8, 12],

@@ -46,3 +59,4 @@ lengths: [16],

type: MASTERCARD,
pattern: /^(5|5[1-5]\d*|2|22|222|222[1-9]\d*|2[3-6]\d*|27[0-1]\d*|2720\d*)$/,
prefixPattern: /^(5|5[1-5]|2|22|222|222[1-9]|2[3-6]|27[0-1]|2720)$/,
exactPattern: /^(5[1-5]|222[1-9]|2[3-6]|27[0-1]|2720)\d*$/,
gaps: [4, 8, 12],

@@ -59,3 +73,4 @@ lengths: [16],

type: AMERICAN_EXPRESS,
pattern: /^3([47]\d*)?$/,
prefixPattern: /^(3|34|37)$/,
exactPattern: /^3[47]\d*$/,
isAmex: true,

@@ -73,3 +88,4 @@ gaps: [4, 10],

type: DINERS_CLUB,
pattern: /^3((0([0-5]\d*)?)|[689]\d*)?$/,
prefixPattern: /^(3|3[0689]|30[0-5])$/,
exactPattern: /^3(0[0-5]|[689])\d*$/,
gaps: [4, 10],

@@ -86,3 +102,4 @@ lengths: [14],

type: DISCOVER,
pattern: /^6(0|01|011\d*|5\d*|4|4[4-9]\d*)?$/,
prefixPattern: /^(6|60|601|6011|65|64|64[4-9])$/,
exactPattern: /^(6011|65|64[4-9])\d*$/,
gaps: [4, 8, 12],

@@ -99,3 +116,4 @@ lengths: [16, 19],

type: JCB,
pattern: /^((2|21|213|2131\d*)|(1|18|180|1800\d*)|(3|35\d*))$/,
prefixPattern: /^(2|21|213|2131|1|18|180|1800|3|35)$/,
exactPattern: /^(2131|1800|35)\d*$/,
gaps: [4, 8, 12],

@@ -112,3 +130,4 @@ lengths: [16],

type: UNIONPAY,
pattern: /^6(2\d*)?$/,
prefixPattern: /^(6|62)$/,
exactPattern: /^62\d*$/,
gaps: [4, 8, 12],

@@ -125,3 +144,4 @@ lengths: [16, 17, 18, 19],

type: MAESTRO,
pattern: /^((5((0|[6-9])\d*)?)|(6|6[37]\d*))$/,
prefixPattern: /^(5|5[06-9]|6\d*)$/,
exactPattern: /^5[06-9]\d*$/,
gaps: [4, 8, 12],

@@ -136,20 +156,27 @@ lengths: [12, 13, 14, 15, 16, 17, 18, 19],

function creditCardType(cardNumber) {
var type, value;
var result = [];
var type, value, i;
var prefixResults = [];
var exactResults = [];
if (!(typeof cardNumber === 'string' || cardNumber instanceof String)) {
return result;
return [];
}
for (type in types) {
if (!types.hasOwnProperty(type)) { continue; }
for (i = 0; i < testOrder.length; i++) {
type = testOrder[i];
value = types[type];
if (cardNumber.length === 0 || value.pattern.test(cardNumber)) {
result.push(clone(value));
if (cardNumber.length === 0) {
prefixResults.push(clone(value));
continue;
}
if (value.exactPattern.test(cardNumber)) {
exactResults.push(clone(value));
} else if (value.prefixPattern.test(cardNumber)) {
prefixResults.push(clone(value));
}
}
return result;
return exactResults.length ? exactResults : prefixResults;
}

@@ -156,0 +183,0 @@

{
"name": "credit-card-type",
"version": "4.1.0",
"version": "5.0.0",
"description": "A library for determining credit card type",

@@ -30,3 +30,3 @@ "main": "index.js",

"gulp-watch": "^0.6.8",
"mocha": "^2.2.1",
"mocha": "^3.0.0",
"sinon": "^1.14.1",

@@ -33,0 +33,0 @@ "sinon-chai": "^2.7.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