(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i 0){ return card[0].type; } return ''; }; },{"credit-card-type":2}],2:[function(require,module,exports){ 'use strict'; var types = require('./lib/card-types'); var clone = require('./lib/clone'); var findBestMatch = require('./lib/find-best-match'); var isValidInputType = require('./lib/is-valid-input-type'); var addMatchingCardsToResults = require('./lib/add-matching-cards-to-results'); var testOrder; var customCards = {}; var cardNames = { VISA: 'visa', MASTERCARD: 'mastercard', AMERICAN_EXPRESS: 'american-express', DINERS_CLUB: 'diners-club', DISCOVER: 'discover', JCB: 'jcb', UNIONPAY: 'unionpay', MAESTRO: 'maestro', ELO: 'elo', MIR: 'mir', HIPER: 'hiper', HIPERCARD: 'hipercard' }; var ORIGINAL_TEST_ORDER = [ cardNames.VISA, cardNames.MASTERCARD, cardNames.AMERICAN_EXPRESS, cardNames.DINERS_CLUB, cardNames.DISCOVER, cardNames.JCB, cardNames.UNIONPAY, cardNames.MAESTRO, cardNames.ELO, cardNames.MIR, cardNames.HIPER, cardNames.HIPERCARD ]; testOrder = clone(ORIGINAL_TEST_ORDER); function findType(type) { return customCards[type] || types[type]; } function getAllCardTypes() { return testOrder.map(function (type) { return clone(findType(type)); }); } function getCardPosition(name, ignoreErrorForNotExisting) { var position = testOrder.indexOf(name); if (!ignoreErrorForNotExisting && position === -1) { throw new Error('"' + name + '" is not a supported card type.'); } return position; } function creditCardType(cardNumber) { var bestMatch; var results = []; if (!isValidInputType(cardNumber)) { return []; } if (cardNumber.length === 0) { return getAllCardTypes(testOrder); } testOrder.forEach(function (type) { var cardConfiguration = findType(type); addMatchingCardsToResults(cardNumber, cardConfiguration, results); }); bestMatch = findBestMatch(results); if (bestMatch) { return [bestMatch]; } return results; } creditCardType.getTypeInfo = function (type) { return clone(findType(type)); }; creditCardType.removeCard = function (name) { var position = getCardPosition(name); testOrder.splice(position, 1); }; creditCardType.addCard = function (config) { var existingCardPosition = getCardPosition(config.type, true); customCards[config.type] = config; if (existingCardPosition === -1) { testOrder.push(config.type); } }; 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) { var currentPosition = getCardPosition(name); testOrder.splice(currentPosition, 1); testOrder.splice(position, 0, name); }; creditCardType.resetModifications = function () { testOrder = clone(ORIGINAL_TEST_ORDER); customCards = {}; }; creditCardType.types = cardNames; module.exports = creditCardType; },{"./lib/add-matching-cards-to-results":3,"./lib/card-types":4,"./lib/clone":5,"./lib/find-best-match":6,"./lib/is-valid-input-type":7}],3:[function(require,module,exports){ 'use strict'; var clone = require('./clone'); var matches = require('./matches'); function addMatchingCardsToResults(cardNumber, cardConfiguration, results) { var i, pattern, patternLength, clonedCardConfiguration; for (i = 0; i < cardConfiguration.patterns.length; i++) { pattern = cardConfiguration.patterns[i]; if (!matches(cardNumber, pattern)) { continue; } clonedCardConfiguration = clone(cardConfiguration); if (Array.isArray(pattern)) { patternLength = String(pattern[0]).length; } else { patternLength = String(pattern).length; } if (cardNumber.length >= patternLength) { clonedCardConfiguration.matchStrength = patternLength; } results.push(clonedCardConfiguration); break; } } module.exports = addMatchingCardsToResults; },{"./clone":5,"./matches":8}],4:[function(require,module,exports){ 'use strict'; var cardTypes = { visa: { niceType: 'Visa', type: 'visa', patterns: [ 4 ], gaps: [4, 8, 12], lengths: [16, 18, 19], code: { name: 'CVV', size: 3 } }, mastercard: { niceType: 'Mastercard', type: 'mastercard', patterns: [ [51, 55], [2221, 2229], [223, 229], [23, 26], [270, 271], 2720 ], gaps: [4, 8, 12], lengths: [16], code: { name: 'CVC', size: 3 } }, 'american-express': { niceType: 'American Express', type: 'american-express', patterns: [ 34, 37 ], gaps: [4, 10], lengths: [15], code: { name: 'CID', size: 4 } }, 'diners-club': { niceType: 'Diners Club', type: 'diners-club', patterns: [ [300, 305], 36, 38, 39 ], gaps: [4, 10], lengths: [14, 16, 19], code: { name: 'CVV', size: 3 } }, discover: { niceType: 'Discover', type: 'discover', patterns: [ 6011, [644, 649], 65 ], gaps: [4, 8, 12], lengths: [16, 19], code: { name: 'CID', size: 3 } }, jcb: { niceType: 'JCB', type: 'jcb', patterns: [ 2131, 1800, [3528, 3589] ], gaps: [4, 8, 12], lengths: [16, 17, 18, 19], code: { name: 'CVV', size: 3 } }, unionpay: { niceType: 'UnionPay', type: 'unionpay', patterns: [ 620, [624, 626], [62100, 62182], [62184, 62187], [62185, 62197], [62200, 62205], [622010, 622999], 622018, [622019, 622999], [62207, 62209], [622126, 622925], [623, 626], 6270, 6272, 6276, [627700, 627779], [627781, 627799], [6282, 6289], 6291, 6292, 810, [8110, 8131], [8132, 8151], [8152, 8163], [8164, 8171] ], gaps: [4, 8, 12], lengths: [14, 15, 16, 17, 18, 19], code: { name: 'CVN', size: 3 } }, maestro: { niceType: 'Maestro', type: 'maestro', patterns: [ 493698, [500000, 506698], [506779, 508999], [56, 59], 63, 67, 6 ], gaps: [4, 8, 12], lengths: [12, 13, 14, 15, 16, 17, 18, 19], code: { name: 'CVC', size: 3 } }, elo: { niceType: 'Elo', type: 'elo', patterns: [ 401178, 401179, 438935, 457631, 457632, 431274, 451416, 457393, 504175, [506699, 506778], [509000, 509999], 627780, 636297, 636368, [650031, 650033], [650035, 650051], [650405, 650439], [650485, 650538], [650541, 650598], [650700, 650718], [650720, 650727], [650901, 650978], [651652, 651679], [655000, 655019], [655021, 655058] ], gaps: [4, 8, 12], lengths: [16], code: { name: 'CVE', size: 3 } }, mir: { niceType: 'Mir', type: 'mir', patterns: [ [2200, 2204] ], gaps: [4, 8, 12], lengths: [16, 17, 18, 19], code: { name: 'CVP2', size: 3 } }, hiper: { niceType: 'Hiper', type: 'hiper', patterns: [ 637095, 637568, 637599, 637609, 637612 ], gaps: [4, 8, 12], lengths: [16], code: { name: 'CVC', size: 3 } }, hipercard: { niceType: 'Hipercard', type: 'hipercard', patterns: [ 606282 ], gaps: [4, 8, 12], lengths: [16], code: { name: 'CVC', size: 3 } } }; module.exports = cardTypes; },{}],5:[function(require,module,exports){ 'use strict'; function clone(originalObject) { var dupe; if (!originalObject) { return null; } dupe = JSON.parse(JSON.stringify(originalObject)); return dupe; } module.exports = clone; },{}],6:[function(require,module,exports){ 'use strict'; function hasEnoughResultsToDetermineBestMatch(results) { var numberOfResultsWithMaxStrengthProperty = results.filter(function (result) { return result.matchStrength; }).length; // if all possible results have a maxStrength property // that means the card number is sufficiently long // enough to determine conclusively what the type is return numberOfResultsWithMaxStrengthProperty > 0 && numberOfResultsWithMaxStrengthProperty === results.length; } function findBestMatch(results) { if (!hasEnoughResultsToDetermineBestMatch(results)) { return; } return results.reduce(function (bestMatch, result) { // eslint-disable-line consistent-return if (!bestMatch) { return result; } // if the current best match pattern is less specific // than this result, set the result as the new best match if (bestMatch.matchStrength < result.matchStrength) { return result; } return bestMatch; }); } module.exports = findBestMatch; },{}],7:[function(require,module,exports){ 'use strict'; function isValidInputType(cardNumber) { return typeof cardNumber === 'string' || cardNumber instanceof String; } module.exports = isValidInputType; },{}],8:[function(require,module,exports){ 'use strict'; // Adapted from https://github.com/polvo-labs/card-type/blob/aaab11f80fa1939bccc8f24905a06ae3cd864356/src/cardType.js#L37-L42 function matchesRange(cardNumber, min, max) { var maxLengthToCheck = String(min).length; var substr = cardNumber.substr(0, maxLengthToCheck); var integerRepresentationOfCardNumber = parseInt(substr, 10); min = parseInt(String(min).substr(0, substr.length), 10); max = parseInt(String(max).substr(0, substr.length), 10); return integerRepresentationOfCardNumber >= min && integerRepresentationOfCardNumber <= max; } function matchesPattern(cardNumber, pattern) { pattern = String(pattern); return pattern.substring(0, cardNumber.length) === cardNumber.substring(0, pattern.length); } function matches(cardNumber, pattern) { if (Array.isArray(pattern)) { return matchesRange(cardNumber, pattern[0], pattern[1]); } return matchesPattern(cardNumber, pattern); } module.exports = matches; },{}]},{},[1]);