credit-card-type
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -0,1 +1,6 @@ | ||
4.0.2 | ||
===== | ||
- Removes dependency on Lodash | ||
4.0.1 | ||
@@ -2,0 +7,0 @@ ===== |
@@ -10,4 +10,2 @@ 'use strict'; | ||
var rename = require('gulp-rename'); | ||
var watch = require('gulp-watch'); | ||
var eslint = require('gulp-eslint'); | ||
var del = require('del'); | ||
@@ -26,12 +24,6 @@ | ||
}, | ||
dist: { js: 'dist/js' } | ||
dist: {js: 'dist/js'} | ||
}; | ||
gulp.task('lint', function () { | ||
gulp.src([config.src.js.main]) | ||
.pipe(eslint()) | ||
.pipe(eslint.format()); | ||
}); | ||
gulp.task('js', ['lint'], function () { | ||
gulp.task('js', function () { | ||
return browserify(config.src.js.main) | ||
@@ -53,5 +45,5 @@ .bundle() | ||
gulp.task('clean', function (done) { | ||
del([ config.dist.js ], done); | ||
del([config.dist.js], done); | ||
}); | ||
gulp.task('build', ['clean', 'js']); |
38
index.js
@@ -1,3 +0,2 @@ | ||
var isString = require('lodash/lang/isString'); | ||
var clone = require('lodash/lang/cloneDeep'); | ||
'use strict'; | ||
@@ -19,3 +18,3 @@ var types = [ | ||
type: 'master-card', | ||
pattern: '^5([1-5]\\d*)?$', | ||
pattern: '^(5|5[1-5]\\d*|2|22|222|222[1-9]\\d*|2[3-6]\\d*|27[0-1]\\d*|2720\\d*)$', | ||
gaps: [4, 8, 12], | ||
@@ -54,5 +53,5 @@ lengths: [16], | ||
type: 'discover', | ||
pattern: '^6(0|01|011\\d*|5\\d*|4|4[4-9]\\d*)?$', | ||
pattern: discoverPattern(), | ||
gaps: [4, 8, 12], | ||
lengths: [16], | ||
lengths: [16, 19], | ||
code: { | ||
@@ -102,3 +101,5 @@ name: 'CID', | ||
if (!isString(cardNumber)) { return result; } | ||
if (!(typeof cardNumber === 'string' || cardNumber instanceof String)) { | ||
return result; | ||
} | ||
@@ -117,1 +118,26 @@ if (cardNumber === '') { return clone(types); } | ||
}; | ||
function unionPayAndDiscoverPattern() { | ||
var i, firstPattern, secondPattern, thirdPattern; | ||
var firstPatternBins = []; | ||
for (i = 622126; i <= 622925; i++) { firstPatternBins.push(i); } | ||
firstPattern = '^(' + firstPatternBins.join('|') + ')\\d*$'; | ||
secondPattern = '^(62[4-6])\\d*$'; | ||
thirdPattern = '^(628[2-9])\\d*$'; | ||
return [firstPattern, secondPattern, thirdPattern].join('|'); | ||
} | ||
function nonUnionPayAndDiscoverPattern() { | ||
return '(^6(0|01|011\\d*|5\\d*|4|4[4-9]\\d*)?$)'; | ||
} | ||
function discoverPattern() { | ||
return [unionPayAndDiscoverPattern(), nonUnionPayAndDiscoverPattern()].join('|'); | ||
} | ||
function clone(x) { | ||
return JSON.parse(JSON.stringify(x)); | ||
} |
{ | ||
"name": "credit-card-type", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "A library for determining credit card type", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "gulp lint && mocha test/**/*.js", | ||
"build": "gulp build" | ||
"lint": "eslint .", | ||
"test": "npm run lint && mocha test/**/*.js", | ||
"build": "npm run lint && gulp build" | ||
}, | ||
@@ -21,4 +22,5 @@ "repository": { | ||
"del": "^1.1.0", | ||
"eslint": "2.7.0", | ||
"eslint-config-braintree": "1.0.0", | ||
"gulp": "^3.8.8", | ||
"gulp-eslint": "^0.14.0", | ||
"gulp-rename": "^1.2.0", | ||
@@ -29,17 +31,7 @@ "gulp-size": "^1.1.0", | ||
"gulp-watch": "^0.6.8", | ||
"karma": "^0.12.31", | ||
"karma-browserify": "^4.0.0", | ||
"karma-chai-sinon": "^0.1.4", | ||
"karma-es5-shim": "0.0.4", | ||
"karma-mocha": "^0.1.10", | ||
"karma-phantomjs-launcher": "^0.1.4", | ||
"mocha": "^2.2.1", | ||
"phantomjs": "^1.9.16", | ||
"sinon": "^1.14.1", | ||
"sinon-chai": "^2.7.0", | ||
"vinyl-source-stream": "^1.0.0" | ||
}, | ||
"dependencies": { | ||
"lodash": "3.10.1" | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
var expect = require('chai').expect; | ||
@@ -26,2 +28,18 @@ var getCardType = require('../index'); | ||
['2221', 'master-card'], | ||
['2222', 'master-card'], | ||
['2223', 'master-card'], | ||
['2224', 'master-card'], | ||
['2225', 'master-card'], | ||
['2226', 'master-card'], | ||
['2225', 'master-card'], | ||
['2226', 'master-card'], | ||
['23', 'master-card'], | ||
['24', 'master-card'], | ||
['25', 'master-card'], | ||
['26', 'master-card'], | ||
['270', 'master-card'], | ||
['271', 'master-card'], | ||
['2720', 'master-card'], | ||
['51', 'master-card'], | ||
@@ -71,4 +89,3 @@ ['52', 'master-card'], | ||
['627', 'unionpay'], | ||
['6221558812340000', 'unionpay'], | ||
['6269992058134322', 'unionpay'], | ||
['6221258812340000', 'unionpay'], | ||
@@ -86,3 +103,2 @@ ['50', 'maestro'], | ||
['1', 'jcb'], | ||
['2', 'jcb'], | ||
['35', 'jcb'], | ||
@@ -97,2 +113,17 @@ ['2131', 'jcb'], | ||
var dualBrandTests = [ | ||
['6221260000000000', ['discover', 'unionpay']], | ||
['6221260000000000000', ['discover', 'unionpay']], | ||
['6222000000000000', ['discover', 'unionpay']], | ||
['6228000000000000', ['discover', 'unionpay']], | ||
['6229250000000000', ['discover', 'unionpay']], | ||
['6229250000000000000', ['discover', 'unionpay']], | ||
['6240000000000000', ['discover', 'unionpay']], | ||
['6260000000000000000', ['discover', 'unionpay']], | ||
['6282000000000000', ['discover', 'unionpay']], | ||
['6289000000000000000', ['discover', 'unionpay']], | ||
['6221558812340000', ['discover', 'unionpay']], | ||
['6269992058134322', ['discover', 'unionpay']] | ||
]; | ||
tests.forEach(function (test) { | ||
@@ -104,2 +135,3 @@ var number = test[0]; | ||
var actual = getCardType(number); | ||
expect(actual).to.have.lengthOf(1); | ||
@@ -109,2 +141,15 @@ expect(actual[0].type).to.equal(type); | ||
}); | ||
dualBrandTests.forEach(function (test) { | ||
var number = test[0]; | ||
var types = test[1]; | ||
it('returns type ' + types.join(', ') + ' for ' + number, function () { | ||
var actual = getCardType(number); | ||
expect(actual).to.have.lengthOf(2); | ||
expect(actual[0].type).to.equal(types[0]); | ||
expect(actual[1].type).to.equal(types[1]); | ||
}); | ||
}); | ||
}); | ||
@@ -115,2 +160,3 @@ | ||
['', ['visa', 'master-card', 'american-express', 'diners-club', 'discover', 'jcb', 'unionpay', 'maestro']], | ||
['2', ['master-card', 'jcb']], | ||
['3', ['american-express', 'diners-club', 'jcb']], | ||
@@ -129,2 +175,3 @@ ['5', ['master-card', 'maestro']], | ||
}).sort(); | ||
expect(expectedNames).to.deep.equal(actualNames); | ||
@@ -142,3 +189,5 @@ }); | ||
'1802', | ||
'22', | ||
'221', | ||
'222099', | ||
'2721', | ||
'212', | ||
@@ -191,37 +240,52 @@ '2132', | ||
var code = getCardType('5454545454545454')[0].code; | ||
expect(code.size).to.equal(3); | ||
expect(code.name).to.equal('CVC'); | ||
}); | ||
it('Visa', function () { | ||
var code = getCardType('4111111111111111')[0].code; | ||
expect(code.size).to.equal(3); | ||
expect(code.name).to.equal('CVV'); | ||
}); | ||
it('American Express', function () { | ||
var code = getCardType('378734493671000')[0].code; | ||
expect(code.size).to.equal(4); | ||
expect(code.name).to.equal('CID'); | ||
}); | ||
it('Discover', function () { | ||
var code = getCardType('6011000990139424')[0].code; | ||
expect(code.size).to.equal(3); | ||
expect(code.name).to.equal('CID'); | ||
}); | ||
it('JCB', function () { | ||
var code = getCardType('30569309025904')[0].code; | ||
expect(code.size).to.equal(3); | ||
expect(code.name).to.equal('CVV'); | ||
}); | ||
it('Diners Club', function () { | ||
var code = getCardType('30569309025904')[0].code; | ||
expect(code.size).to.equal(3); | ||
expect(code.name).to.equal('CVV'); | ||
}); | ||
it('UnionPay', function () { | ||
var code = getCardType('6221558812340000')[0].code; | ||
var code = getCardType('6220558812340000')[0].code; | ||
expect(code.size).to.equal(3); | ||
expect(code.name).to.equal('CVN'); | ||
}); | ||
it('Maestro', function () { | ||
var code = getCardType('6304000000000000')[0].code; | ||
expect(code.size).to.equal(3); | ||
@@ -234,3 +298,3 @@ expect(code.name).to.equal('CVC'); | ||
it('Maestro', function () { | ||
expect(getCardType('6304000000000000')[0].lengths).to.deep.equal([12,13,14,15,16,17,18,19]); | ||
expect(getCardType('6304000000000000')[0].lengths).to.deep.equal([12, 13, 14, 15, 16, 17, 18, 19]); | ||
}); | ||
@@ -241,3 +305,3 @@ it('Diners Club', function () { | ||
it('Discover', function () { | ||
expect(getCardType('6011')[0].lengths).to.deep.equal([16]); | ||
expect(getCardType('6011')[0].lengths).to.deep.equal([16, 19]); | ||
}); | ||
@@ -253,3 +317,4 @@ it('Visa', function () { | ||
it('works for String objects', function () { | ||
var number = new String('4111111111111111'); | ||
var number = new String('4111111111111111'); // eslint-disable-line no-new-wrappers | ||
expect(getCardType(number)[0].type).to.equal('visa'); | ||
@@ -259,3 +324,4 @@ }); | ||
it('preserves integrity of returned values', function () { | ||
var result = getCardType('4111111111111111'); | ||
var result = getCardType('4111111111111111')[0]; | ||
result.type = 'whaaaaaat'; | ||
@@ -262,0 +328,0 @@ expect(getCardType('4111111111111111')[0].type).to.equal('visa'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
15
14
466
19405
- Removedlodash@3.10.1
- Removedlodash@3.10.1(transitive)