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 7.0.0 to 7.1.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

7.1.0
=====
- Add support for `Elo` card type
- Adds `updateCard` method (#77)
7.0.0

@@ -2,0 +8,0 @@ =====

246

dist/js/app.built.js

@@ -12,2 +12,3 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.creditCardType=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

var DISCOVER = 'discover';
var ELO = 'elo';
var JCB = 'jcb';

@@ -22,2 +23,3 @@ var UNIONPAY = 'unionpay';

var CVP2 = 'CVP2';
var CVE = 'CVE';
var ORIGINAL_TEST_ORDER = [

@@ -32,14 +34,23 @@ VISA,

MAESTRO,
ELO,
MIR
];
function clone(originalObject) {
var dupe;
function clone(originalObject, persistPatterns) {
var dupe, prefixPattern, exactPattern;
if (!originalObject) { return null; }
prefixPattern = originalObject.prefixPattern;
exactPattern = originalObject.exactPattern;
dupe = JSON.parse(JSON.stringify(originalObject));
delete dupe.prefixPattern;
delete dupe.exactPattern;
if (persistPatterns) {
dupe.prefixPattern = prefixPattern;
dupe.exactPattern = exactPattern;
} else {
delete dupe.prefixPattern;
delete dupe.exactPattern;
}
return dupe;

@@ -53,4 +64,9 @@ }

type: VISA,
prefixPattern: /^4$/,
exactPattern: /^4\d*$/,
prefixPattern: /^4/,
exactPattern: new RegExp('^' +
'4' +
'(?!' +
'31274|51416|57393|0117[89]|38935|5763[12]' + // Elo cards
')\\d{5,}' +
'$'),
gaps: [4, 8, 12],

@@ -107,4 +123,33 @@ lengths: [16, 18, 19],

type: DISCOVER,
prefixPattern: /^(6|60|601|6011|65|64|64[4-9])$/,
exactPattern: /^(6011|65|64[4-9])\d*$/,
prefixPattern: /^(6|60|601|6011|65|65\d{1,4}|64|64[4-9])$/,
exactPattern: new RegExp('^(' +
'6011' +
'|' +
'65' +
'(?!' + // Elo cards
'003[1-3]' +
'|' +
'003[5-9]|004\\d|005[0-1]' +
'|' +
'040[5-9]|04[1-3]\\d' +
'|' +
'048[5-9]|049\\d|05[0-2]\\d|053[0-8]' +
'|' +
'054[1-9]|05[5-8]\\d|059[0-8]' +
'|' +
'070\\d|071[0-8]' +
'|' +
'072[0-7]' +
'|' +
'090[1-9]|09[1-6]\\d|097[0-8]' +
'|' +
'165[2-9]|16[6-7]\\d' +
'|' +
'50[0-1]\\d' +
'|' +
'502[1-9]|50[3-4]\\d|505[0-8]' +
')\\d{4}' +
'|' +
'64[4-9]' +
')\\d*$'),
gaps: [4, 8, 12],

@@ -134,4 +179,26 @@ lengths: [16, 19],

type: UNIONPAY,
prefixPattern: /^((6|62|62\d|(621(?!83|88|98|99))|622(?!06)|627[02,06,07]|628(?!0|1)|629[1,2])|622018)$/,
exactPattern: /^(((620|(621(?!83|88|98|99))|622(?!06|018)|62[3-6]|627[02,06,07]|628(?!0|1)|629[1,2]))\d*|622018\d{12})$/,
prefixPattern: /^((6|62|62\d|(621(?!83|88|98|99))|622(?!06)|627[0267]\d?|628(?!0|1)|629[1,2])|622018)$/,
exactPattern: new RegExp('^(' +
'(' +
'620' +
'|' +
'(621(?!83|88|98|99))' +
'|' +
'622(?!06|018)' +
'|' +
'62[3-6]' +
'|' +
'627[026]' +
'|' +
'6277(?!80)\\d{2}' + // Elo card
'|' +
'628(?!0|1)' +
'|' +
'629[12]' +
')\\d*' +
'|' +
'622018\\d{12}' +
')$'),
gaps: [4, 8, 12],

@@ -149,3 +216,22 @@ lengths: [16, 17, 18, 19],

prefixPattern: /^(5|5[06-9]|6\d*)$/,
exactPattern: /^(5[06-9]|6[37])\d*$/,
exactPattern: new RegExp('^(' +
'5[6-9]' +
'|' +
'50' +
'(?!' + // Elo card ranges
'6699|067[0-6][0-9]' +
'|' +
'677[0-8]' +
'|' +
'9[0-9][0-9][0-9]' +
')\\d{4}' +
'|' +
'67' +
'|' +
'63' +
'(?!' + // More Elo card ranges
'6297|6368' +
')\\d{4}' +
')\\d*$'
),
gaps: [4, 8, 12],

@@ -159,2 +245,116 @@ lengths: [12, 13, 14, 15, 16, 17, 18, 19],

types[ELO] = {
niceType: 'Elo',
type: ELO,
prefixPattern: new RegExp('^(' +
'[4-6]' +
'|' +
'4[035]|4[035]1' +
'|' +
'4011|40117|40117[89]' +
'|' +
'4312|43127|431274' +
'|' +
'438|4389|43893|438935' +
'|' +
'4514|45141|451416' +
'|' +
'457|457[36]|45739|45763|457393|45763[12]' +
'|' +
'50|50[69]' +
'|' +
'506[6-7]|50669|5067[0-7]|5067[0-6][0-9]|50677[0-8]' +
'|' +
'509[0-9]|509[0-9][0-9]|509[0-9][0-9][0-9]' +
'|' +
'6[235]|627|636|65[015]' +
'|' +
'6277|62778|627780' +
'|' +
'636[23]|63629|636297|63636|636368' +
'|' +
'650[0479]' +
'|' +
'6500[3-5]|65003[1-3]|65003[5-9]|65004[0-9]65005[01]' +
'|' +
'6504[0-3]|65040[5-9]|65041[0-9]' +
'|' +
'6505[4-9]|65054[1-9]|6505[5-8][0-9]|65059[0-8]' +
'|' +
'6507[0-2]|65070[0-9]|65071[0-8]|65072[0-7]' +
'|' +
'6509[0-7]|65090[1-9]|6509[1-6][0-9]|65097[0-8]' +
'|' +
'6516|6516[5-7]|65165[2-9]|6516[6-7][0-9]' +
'|' +
'6550|6550[0-5]|6550[01][0-9]|65502[1-9]|6550[3-4][0-9]|65505[0-8]' +
')$'),
exactPattern: new RegExp('^(' +
// Elo only ranges
'4(31274|51416|57393)' +
'|' +
'50(' +
'4175' +
'|' +
'6699|67[0-6][0-9]|677[0-8]' + // 506699-506778
'|' +
'9[0-9][0-9][0-9]' + // 509000-509999
')' +
'|' +
'627780' +
'|' +
'636(297|368)' +
'|' +
// Dual Branded with Visa
'4(0117[89]|38935|5763[12])' +
'|' +
// Dual Branded with Discover
'65(' +
'003[1-3]' + // 650031-650033
'|' +
'003[5-9]|004\\d|005[0-1]' + // 650035-650051
'|' +
'040[5-9]|04[1-3]\\d' + // 650405-650439
'|' +
'048[5-9]|049\\d|05[0-2]\\d|053[0-8]' + // 650485-650538
'|' +
'054[1-9]|05[5-8]\\d|059[0-8]' + // 650541-650598
'|' +
'070[0-9]|071[0-8]' + // 650700-650718
'|' +
'072[0-7]' + // 650720-650727
'|' +
'090[1-9]|09[1-6][0-9]|097[0-8]' + // 650901-650978
'|' +
'165[2-9]|16[6-7][0-9]' + // 651652-651679
'|' +
'50[0-1][0-9]' + // 655000-655019
'|' +
'502[1-9]|50[3-4][0-9]|505[0-8]' + // 655021-655058
')' +
')\\d*$'),
gaps: [4, 8, 12],
lengths: [16],
code: {
name: CVE,
size: 3
}
};
types[MIR] = {

@@ -235,2 +435,25 @@ niceType: 'Mir',

creditCardType.updateCard = function (cardType, updates) {
var clonedCard;
var originalObject = customCards[cardType] || types[cardType];
if (!originalObject) {
throw new Error('"' + cardType + '" is not a recognized type. Use `addCard` instead.');
}
if (updates.type && originalObject.type !== updates.type) {
throw new Error('Cannot overwrite type parameter.');
}
clonedCard = clone(originalObject, true);
Object.keys(clonedCard).forEach(function (key) {
if (updates[key]) {
clonedCard[key] = updates[key];
}
});
customCards[clonedCard.type] = clonedCard;
};
creditCardType.changeOrder = function (name, position) {

@@ -257,2 +480,3 @@ var currentPosition = getCardPosition(name);

MAESTRO: MAESTRO,
ELO: ELO,
MIR: MIR

@@ -259,0 +483,0 @@ };

2

dist/js/app.built.min.js

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

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.creditCardType=e()}}(function(){return function e(t,n,r){function i(p,s){if(!n[p]){if(!t[p]){var o="function"==typeof require&&require;if(!s&&o)return o(p,!0);if(a)return a(p,!0);var c=new Error("Cannot find module '"+p+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[p]={exports:{}};t[p][0].call(f.exports,function(e){var n=t[p][1][e];return i(n?n:e)},f,f.exports,e,t,n,r)}return n[p].exports}for(var a="function"==typeof require&&require,p=0;p<r.length;p++)i(r[p]);return i}({1:[function(e,t,n){"use strict";function r(e){var t;return e?(t=JSON.parse(JSON.stringify(e)),delete t.prefixPattern,delete t.exactPattern,t):null}function i(e){return c[e]||o[e]}function a(e){var t,n,a,p=[],o=[];if(!("string"==typeof e||e instanceof String))return[];for(a=0;a<s.length;a++)t=s[a],n=i(t),0!==e.length?n.exactPattern.test(e)?o.push(r(n)):n.prefixPattern.test(e)&&p.push(r(n)):p.push(r(n));return o.length?o:p}function p(e,t){var n=s.indexOf(e);if(!t&&n===-1)throw new Error('"'+e+'" is not a supported card type.');return n}var s,o={},c={},f="visa",d="mastercard",u="american-express",y="diners-club",l="discover",x="jcb",g="unionpay",P="maestro",h="mir",m="CVV",$="CID",v="CVC",C="CVN",T="CVP2",E=[f,d,u,y,l,x,g,P,h];s=r(E),o[f]={niceType:"Visa",type:f,prefixPattern:/^4$/,exactPattern:/^4\d*$/,gaps:[4,8,12],lengths:[16,18,19],code:{name:m,size:3}},o[d]={niceType:"Mastercard",type:d,prefixPattern:/^(5|5[1-5]|2|22|222|222[1-9]|2[3-6]|27|27[0-2]|2720)$/,exactPattern:/^(5[1-5]|222[1-9]|22[3-9]|2[3-6]|27[0-1]|2720)\d*$/,gaps:[4,8,12],lengths:[16],code:{name:v,size:3}},o[u]={niceType:"American Express",type:u,prefixPattern:/^(3|34|37)$/,exactPattern:/^3[47]\d*$/,isAmex:!0,gaps:[4,10],lengths:[15],code:{name:$,size:4}},o[y]={niceType:"Diners Club",type:y,prefixPattern:/^(3|3[0689]|30[0-5])$/,exactPattern:/^3(0[0-5]|[689])\d*$/,gaps:[4,10],lengths:[14,16,19],code:{name:m,size:3}},o[l]={niceType:"Discover",type:l,prefixPattern:/^(6|60|601|6011|65|64|64[4-9])$/,exactPattern:/^(6011|65|64[4-9])\d*$/,gaps:[4,8,12],lengths:[16,19],code:{name:$,size:3}},o[x]={niceType:"JCB",type:x,prefixPattern:/^(2|21|213|2131|1|18|180|1800|3|35)$/,exactPattern:/^(2131|1800|35)\d*$/,gaps:[4,8,12],lengths:[16,17,18,19],code:{name:m,size:3}},o[g]={niceType:"UnionPay",type:g,prefixPattern:/^((6|62|62\d|(621(?!83|88|98|99))|622(?!06)|627[02,06,07]|628(?!0|1)|629[1,2])|622018)$/,exactPattern:/^(((620|(621(?!83|88|98|99))|622(?!06|018)|62[3-6]|627[02,06,07]|628(?!0|1)|629[1,2]))\d*|622018\d{12})$/,gaps:[4,8,12],lengths:[16,17,18,19],code:{name:C,size:3}},o[P]={niceType:"Maestro",type:P,prefixPattern:/^(5|5[06-9]|6\d*)$/,exactPattern:/^(5[06-9]|6[37])\d*$/,gaps:[4,8,12],lengths:[12,13,14,15,16,17,18,19],code:{name:v,size:3}},o[h]={niceType:"Mir",type:h,prefixPattern:/^(2|22|220|220[0-4])$/,exactPattern:/^(220[0-4])\d*$/,gaps:[4,8,12],lengths:[16,17,18,19],code:{name:T,size:3}},a.getTypeInfo=function(e){return r(i(e))},a.removeCard=function(e){var t=p(e);s.splice(t,1)},a.addCard=function(e){var t=p(e.type,!0);c[e.type]=e,t===-1&&s.push(e.type)},a.changeOrder=function(e,t){var n=p(e);s.splice(n,1),s.splice(t,0,e)},a.resetModifications=function(){s=r(E),c={}},a.types={VISA:f,MASTERCARD:d,AMERICAN_EXPRESS:u,DINERS_CLUB:y,DISCOVER:l,JCB:x,UNIONPAY:g,MAESTRO:P,MIR:h},t.exports=a},{}]},{},[1])(1)});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.creditCardType=e()}}(function(){return function e(t,n,r){function a(p,d){if(!n[p]){if(!t[p]){var o="function"==typeof require&&require;if(!d&&o)return o(p,!0);if(i)return i(p,!0);var s=new Error("Cannot find module '"+p+"'");throw s.code="MODULE_NOT_FOUND",s}var c=n[p]={exports:{}};t[p][0].call(c.exports,function(e){var n=t[p][1][e];return a(n?n:e)},c,c.exports,e,t,n,r)}return n[p].exports}for(var i="function"==typeof require&&require,p=0;p<r.length;p++)a(r[p]);return a}({1:[function(e,t,n){"use strict";function r(e,t){var n,r,a;return e?(r=e.prefixPattern,a=e.exactPattern,n=JSON.parse(JSON.stringify(e)),t?(n.prefixPattern=r,n.exactPattern=a):(delete n.prefixPattern,delete n.exactPattern),n):null}function a(e){return s[e]||o[e]}function i(e){var t,n,i,p=[],o=[];if(!("string"==typeof e||e instanceof String))return[];for(i=0;i<d.length;i++)t=d[i],n=a(t),0!==e.length?n.exactPattern.test(e)?o.push(r(n)):n.prefixPattern.test(e)&&p.push(r(n)):p.push(r(n));return o.length?o:p}function p(e,t){var n=d.indexOf(e);if(!t&&n===-1)throw new Error('"'+e+'" is not a supported card type.');return n}var d,o={},s={},c="visa",f="mastercard",u="american-express",y="diners-club",x="discover",g="elo",l="jcb",P="unionpay",h="maestro",E="mir",m="CVV",C="CID",v="CVC",w="CVN",$="CVP2",T="CVE",R=[c,f,u,y,x,l,P,h,g,E];d=r(R),o[c]={niceType:"Visa",type:c,prefixPattern:/^4/,exactPattern:new RegExp("^4(?!31274|51416|57393|0117[89]|38935|5763[12])\\d{5,}$"),gaps:[4,8,12],lengths:[16,18,19],code:{name:m,size:3}},o[f]={niceType:"Mastercard",type:f,prefixPattern:/^(5|5[1-5]|2|22|222|222[1-9]|2[3-6]|27|27[0-2]|2720)$/,exactPattern:/^(5[1-5]|222[1-9]|22[3-9]|2[3-6]|27[0-1]|2720)\d*$/,gaps:[4,8,12],lengths:[16],code:{name:v,size:3}},o[u]={niceType:"American Express",type:u,prefixPattern:/^(3|34|37)$/,exactPattern:/^3[47]\d*$/,isAmex:!0,gaps:[4,10],lengths:[15],code:{name:C,size:4}},o[y]={niceType:"Diners Club",type:y,prefixPattern:/^(3|3[0689]|30[0-5])$/,exactPattern:/^3(0[0-5]|[689])\d*$/,gaps:[4,10],lengths:[14,16,19],code:{name:m,size:3}},o[x]={niceType:"Discover",type:x,prefixPattern:/^(6|60|601|6011|65|65\d{1,4}|64|64[4-9])$/,exactPattern:new RegExp("^(6011|65(?!003[1-3]|003[5-9]|004\\d|005[0-1]|040[5-9]|04[1-3]\\d|048[5-9]|049\\d|05[0-2]\\d|053[0-8]|054[1-9]|05[5-8]\\d|059[0-8]|070\\d|071[0-8]|072[0-7]|090[1-9]|09[1-6]\\d|097[0-8]|165[2-9]|16[6-7]\\d|50[0-1]\\d|502[1-9]|50[3-4]\\d|505[0-8])\\d{4}|64[4-9])\\d*$"),gaps:[4,8,12],lengths:[16,19],code:{name:C,size:3}},o[l]={niceType:"JCB",type:l,prefixPattern:/^(2|21|213|2131|1|18|180|1800|3|35)$/,exactPattern:/^(2131|1800|35)\d*$/,gaps:[4,8,12],lengths:[16,17,18,19],code:{name:m,size:3}},o[P]={niceType:"UnionPay",type:P,prefixPattern:/^((6|62|62\d|(621(?!83|88|98|99))|622(?!06)|627[0267]\d?|628(?!0|1)|629[1,2])|622018)$/,exactPattern:new RegExp("^((620|(621(?!83|88|98|99))|622(?!06|018)|62[3-6]|627[026]|6277(?!80)\\d{2}|628(?!0|1)|629[12])\\d*|622018\\d{12})$"),gaps:[4,8,12],lengths:[16,17,18,19],code:{name:w,size:3}},o[h]={niceType:"Maestro",type:h,prefixPattern:/^(5|5[06-9]|6\d*)$/,exactPattern:new RegExp("^(5[6-9]|50(?!6699|067[0-6][0-9]|677[0-8]|9[0-9][0-9][0-9])\\d{4}|67|63(?!6297|6368)\\d{4})\\d*$"),gaps:[4,8,12],lengths:[12,13,14,15,16,17,18,19],code:{name:v,size:3}},o[g]={niceType:"Elo",type:g,prefixPattern:new RegExp("^([4-6]|4[035]|4[035]1|4011|40117|40117[89]|4312|43127|431274|438|4389|43893|438935|4514|45141|451416|457|457[36]|45739|45763|457393|45763[12]|50|50[69]|506[6-7]|50669|5067[0-7]|5067[0-6][0-9]|50677[0-8]|509[0-9]|509[0-9][0-9]|509[0-9][0-9][0-9]|6[235]|627|636|65[015]|6277|62778|627780|636[23]|63629|636297|63636|636368|650[0479]|6500[3-5]|65003[1-3]|65003[5-9]|65004[0-9]65005[01]|6504[0-3]|65040[5-9]|65041[0-9]|6505[4-9]|65054[1-9]|6505[5-8][0-9]|65059[0-8]|6507[0-2]|65070[0-9]|65071[0-8]|65072[0-7]|6509[0-7]|65090[1-9]|6509[1-6][0-9]|65097[0-8]|6516|6516[5-7]|65165[2-9]|6516[6-7][0-9]|6550|6550[0-5]|6550[01][0-9]|65502[1-9]|6550[3-4][0-9]|65505[0-8])$"),exactPattern:new RegExp("^(4(31274|51416|57393)|50(4175|6699|67[0-6][0-9]|677[0-8]|9[0-9][0-9][0-9])|627780|636(297|368)|4(0117[89]|38935|5763[12])|65(003[1-3]|003[5-9]|004\\d|005[0-1]|040[5-9]|04[1-3]\\d|048[5-9]|049\\d|05[0-2]\\d|053[0-8]|054[1-9]|05[5-8]\\d|059[0-8]|070[0-9]|071[0-8]|072[0-7]|090[1-9]|09[1-6][0-9]|097[0-8]|165[2-9]|16[6-7][0-9]|50[0-1][0-9]|502[1-9]|50[3-4][0-9]|505[0-8]))\\d*$"),gaps:[4,8,12],lengths:[16],code:{name:T,size:3}},o[E]={niceType:"Mir",type:E,prefixPattern:/^(2|22|220|220[0-4])$/,exactPattern:/^(220[0-4])\d*$/,gaps:[4,8,12],lengths:[16,17,18,19],code:{name:$,size:3}},i.getTypeInfo=function(e){return r(a(e))},i.removeCard=function(e){var t=p(e);d.splice(t,1)},i.addCard=function(e){var t=p(e.type,!0);s[e.type]=e,t===-1&&d.push(e.type)},i.updateCard=function(e,t){var n,a=s[e]||o[e];if(!a)throw new Error('"'+e+'" is not a recognized type. Use `addCard` instead.');if(t.type&&a.type!==t.type)throw new Error("Cannot overwrite type parameter.");n=r(a,!0),Object.keys(n).forEach(function(e){t[e]&&(n[e]=t[e])}),s[n.type]=n},i.changeOrder=function(e,t){var n=p(e);d.splice(n,1),d.splice(t,0,e)},i.resetModifications=function(){d=r(R),s={}},i.types={VISA:c,MASTERCARD:f,AMERICAN_EXPRESS:u,DINERS_CLUB:y,DISCOVER:x,JCB:l,UNIONPAY:P,MAESTRO:h,ELO:g,MIR:E},t.exports=i},{}]},{},[1])(1)});

@@ -11,2 +11,3 @@ 'use strict';

var DISCOVER = 'discover';
var ELO = 'elo';
var JCB = 'jcb';

@@ -21,2 +22,3 @@ var UNIONPAY = 'unionpay';

var CVP2 = 'CVP2';
var CVE = 'CVE';
var ORIGINAL_TEST_ORDER = [

@@ -31,14 +33,23 @@ VISA,

MAESTRO,
ELO,
MIR
];
function clone(originalObject) {
var dupe;
function clone(originalObject, persistPatterns) {
var dupe, prefixPattern, exactPattern;
if (!originalObject) { return null; }
prefixPattern = originalObject.prefixPattern;
exactPattern = originalObject.exactPattern;
dupe = JSON.parse(JSON.stringify(originalObject));
delete dupe.prefixPattern;
delete dupe.exactPattern;
if (persistPatterns) {
dupe.prefixPattern = prefixPattern;
dupe.exactPattern = exactPattern;
} else {
delete dupe.prefixPattern;
delete dupe.exactPattern;
}
return dupe;

@@ -52,4 +63,9 @@ }

type: VISA,
prefixPattern: /^4$/,
exactPattern: /^4\d*$/,
prefixPattern: /^4/,
exactPattern: new RegExp('^' +
'4' +
'(?!' +
'31274|51416|57393|0117[89]|38935|5763[12]' + // Elo cards
')\\d{5,}' +
'$'),
gaps: [4, 8, 12],

@@ -106,4 +122,33 @@ lengths: [16, 18, 19],

type: DISCOVER,
prefixPattern: /^(6|60|601|6011|65|64|64[4-9])$/,
exactPattern: /^(6011|65|64[4-9])\d*$/,
prefixPattern: /^(6|60|601|6011|65|65\d{1,4}|64|64[4-9])$/,
exactPattern: new RegExp('^(' +
'6011' +
'|' +
'65' +
'(?!' + // Elo cards
'003[1-3]' +
'|' +
'003[5-9]|004\\d|005[0-1]' +
'|' +
'040[5-9]|04[1-3]\\d' +
'|' +
'048[5-9]|049\\d|05[0-2]\\d|053[0-8]' +
'|' +
'054[1-9]|05[5-8]\\d|059[0-8]' +
'|' +
'070\\d|071[0-8]' +
'|' +
'072[0-7]' +
'|' +
'090[1-9]|09[1-6]\\d|097[0-8]' +
'|' +
'165[2-9]|16[6-7]\\d' +
'|' +
'50[0-1]\\d' +
'|' +
'502[1-9]|50[3-4]\\d|505[0-8]' +
')\\d{4}' +
'|' +
'64[4-9]' +
')\\d*$'),
gaps: [4, 8, 12],

@@ -133,4 +178,26 @@ lengths: [16, 19],

type: UNIONPAY,
prefixPattern: /^((6|62|62\d|(621(?!83|88|98|99))|622(?!06)|627[02,06,07]|628(?!0|1)|629[1,2])|622018)$/,
exactPattern: /^(((620|(621(?!83|88|98|99))|622(?!06|018)|62[3-6]|627[02,06,07]|628(?!0|1)|629[1,2]))\d*|622018\d{12})$/,
prefixPattern: /^((6|62|62\d|(621(?!83|88|98|99))|622(?!06)|627[0267]\d?|628(?!0|1)|629[1,2])|622018)$/,
exactPattern: new RegExp('^(' +
'(' +
'620' +
'|' +
'(621(?!83|88|98|99))' +
'|' +
'622(?!06|018)' +
'|' +
'62[3-6]' +
'|' +
'627[026]' +
'|' +
'6277(?!80)\\d{2}' + // Elo card
'|' +
'628(?!0|1)' +
'|' +
'629[12]' +
')\\d*' +
'|' +
'622018\\d{12}' +
')$'),
gaps: [4, 8, 12],

@@ -148,3 +215,22 @@ lengths: [16, 17, 18, 19],

prefixPattern: /^(5|5[06-9]|6\d*)$/,
exactPattern: /^(5[06-9]|6[37])\d*$/,
exactPattern: new RegExp('^(' +
'5[6-9]' +
'|' +
'50' +
'(?!' + // Elo card ranges
'6699|067[0-6][0-9]' +
'|' +
'677[0-8]' +
'|' +
'9[0-9][0-9][0-9]' +
')\\d{4}' +
'|' +
'67' +
'|' +
'63' +
'(?!' + // More Elo card ranges
'6297|6368' +
')\\d{4}' +
')\\d*$'
),
gaps: [4, 8, 12],

@@ -158,2 +244,116 @@ lengths: [12, 13, 14, 15, 16, 17, 18, 19],

types[ELO] = {
niceType: 'Elo',
type: ELO,
prefixPattern: new RegExp('^(' +
'[4-6]' +
'|' +
'4[035]|4[035]1' +
'|' +
'4011|40117|40117[89]' +
'|' +
'4312|43127|431274' +
'|' +
'438|4389|43893|438935' +
'|' +
'4514|45141|451416' +
'|' +
'457|457[36]|45739|45763|457393|45763[12]' +
'|' +
'50|50[69]' +
'|' +
'506[6-7]|50669|5067[0-7]|5067[0-6][0-9]|50677[0-8]' +
'|' +
'509[0-9]|509[0-9][0-9]|509[0-9][0-9][0-9]' +
'|' +
'6[235]|627|636|65[015]' +
'|' +
'6277|62778|627780' +
'|' +
'636[23]|63629|636297|63636|636368' +
'|' +
'650[0479]' +
'|' +
'6500[3-5]|65003[1-3]|65003[5-9]|65004[0-9]65005[01]' +
'|' +
'6504[0-3]|65040[5-9]|65041[0-9]' +
'|' +
'6505[4-9]|65054[1-9]|6505[5-8][0-9]|65059[0-8]' +
'|' +
'6507[0-2]|65070[0-9]|65071[0-8]|65072[0-7]' +
'|' +
'6509[0-7]|65090[1-9]|6509[1-6][0-9]|65097[0-8]' +
'|' +
'6516|6516[5-7]|65165[2-9]|6516[6-7][0-9]' +
'|' +
'6550|6550[0-5]|6550[01][0-9]|65502[1-9]|6550[3-4][0-9]|65505[0-8]' +
')$'),
exactPattern: new RegExp('^(' +
// Elo only ranges
'4(31274|51416|57393)' +
'|' +
'50(' +
'4175' +
'|' +
'6699|67[0-6][0-9]|677[0-8]' + // 506699-506778
'|' +
'9[0-9][0-9][0-9]' + // 509000-509999
')' +
'|' +
'627780' +
'|' +
'636(297|368)' +
'|' +
// Dual Branded with Visa
'4(0117[89]|38935|5763[12])' +
'|' +
// Dual Branded with Discover
'65(' +
'003[1-3]' + // 650031-650033
'|' +
'003[5-9]|004\\d|005[0-1]' + // 650035-650051
'|' +
'040[5-9]|04[1-3]\\d' + // 650405-650439
'|' +
'048[5-9]|049\\d|05[0-2]\\d|053[0-8]' + // 650485-650538
'|' +
'054[1-9]|05[5-8]\\d|059[0-8]' + // 650541-650598
'|' +
'070[0-9]|071[0-8]' + // 650700-650718
'|' +
'072[0-7]' + // 650720-650727
'|' +
'090[1-9]|09[1-6][0-9]|097[0-8]' + // 650901-650978
'|' +
'165[2-9]|16[6-7][0-9]' + // 651652-651679
'|' +
'50[0-1][0-9]' + // 655000-655019
'|' +
'502[1-9]|50[3-4][0-9]|505[0-8]' + // 655021-655058
')' +
')\\d*$'),
gaps: [4, 8, 12],
lengths: [16],
code: {
name: CVE,
size: 3
}
};
types[MIR] = {

@@ -234,2 +434,25 @@ niceType: 'Mir',

creditCardType.updateCard = function (cardType, updates) {
var clonedCard;
var originalObject = customCards[cardType] || types[cardType];
if (!originalObject) {
throw new Error('"' + cardType + '" is not a recognized type. Use `addCard` instead.');
}
if (updates.type && originalObject.type !== updates.type) {
throw new Error('Cannot overwrite type parameter.');
}
clonedCard = clone(originalObject, true);
Object.keys(clonedCard).forEach(function (key) {
if (updates[key]) {
clonedCard[key] = updates[key];
}
});
customCards[clonedCard.type] = clonedCard;
};
creditCardType.changeOrder = function (name, position) {

@@ -256,2 +479,3 @@ var currentPosition = getCardPosition(name);

MAESTRO: MAESTRO,
ELO: ELO,
MIR: MIR

@@ -258,0 +482,0 @@ };

{
"name": "credit-card-type",
"version": "7.0.0",
"version": "7.1.0",
"description": "A library for determining credit card type",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -42,9 +42,9 @@ 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)

| 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` |
| `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 />- `master-card`<br />- `american-express`<br />- `diners-club`<br />- `discover`<br />- `jcb`<br />- `unionpay`<br />- `maestro`<br />- `mir` |
| `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. |
| 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` |
| `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` |
| `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. |

@@ -70,2 +70,3 @@ If no card types are found, this returns an empty array.

* `MIR`
* `ELO`

@@ -87,2 +88,3 @@ #### `code`

| `Mir` | `CVP` | 3 |
| `Elo` | `CVE` | 3 |

@@ -186,3 +188,4 @@ A full response for a `Visa` card will look like this:

creditCardType.types.MAESTRO,
creditCardType.types.MIR
creditCardType.types.MIR,
creditCardType.types.ELO
]

@@ -210,3 +213,29 @@ ```

#### Updating Card Types
You can update cards with `updateCard`. Pass in the card type and the configuration object. Any properties left off will inherit from the original card object.
```javascript
creditCardType.updateCard(creditCardType.types.VISA, {
niceType: 'Fancy Visa',
lengths: [11, 16]
});
var visa = creditCardType.getCardInfo(creditCardType.types.VISA);
// overwritten properties
visa.niceType; // 'Fancy Visa'
visa.length; // [11, 16]
// unchanged properties
visa.gaps // [4, 8, 12]
visa.code.name // 'CVV'
```
If you need to reset the modifications you have created, simply call `resetModifications`:
```javascript
creditCardType.resetModifications();
```
#### Pretty Card Numbers

@@ -213,0 +242,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