creditcard-warder
Advanced tools
Comparing version 0.2.9 to 0.3.9
185
index.js
@@ -7,103 +7,103 @@ | ||
var CredircardWarder = function(number) { | ||
this.number = number; | ||
this.number = number; | ||
this.rules = [ | ||
{ | ||
type: 'elo', | ||
pattern: /^(((40117[89])|(431274)|(438935)|(451416)|(457393)|(45763[12])|(504175)|(627780)|(636297)|(636368)|(65500[0-3])|(65165[2-4])|(65048[5-8])|(650489|65049[0-4])|(506699|5067[0-6][0-9]|50677[0-8])|(509[0-8][0-9]{2}|5099[0-8][0-9]|50999[0-9])|(65003[1-3])|(65003[5-9]|65004[0-9]|65005[01])|(65040[5-9]|6504[1-3][0-9])|(65048[5-9]|65049[0-9]|6505[0-2][0-9]|65053[0-8])|(65054[1-9]|6505[5-8][0-9]|65059[0-8])|(65070[0-9]|65071[0-8])|(65072[0-7])|(65090[1-9]|65091[0-9]|650920)|(65165[2-9]|6516[67][0-9])|(65500[0-9]|65501[0-9])|(65502[1-9]|6550[34][0-9]|65505[0-8]))\d{0,16})$/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'hipercard', | ||
pattern: /^(606282\d{10}(\d{3})?)|(3841\d{15})$/, | ||
format: /\d/g, | ||
length: [13, 16, 19], | ||
cvcLength: [3] | ||
}, { | ||
type: 'aura', | ||
pattern: /^(50)/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'visaelectron', | ||
pattern: /^4(026|17500|405|508|844|91[37])/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'maestro', | ||
pattern: /^(5(018|0[23]|[68])|6(39|7))/, | ||
length: [12, 13, 14, 15, 16, 17, 18, 19], | ||
cvcLength: [3] | ||
}, { | ||
type: 'forbrugsforeningen', | ||
pattern: /^600/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'dankort', | ||
pattern: /^5019/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'visa', | ||
pattern: /^4/, | ||
length: [13, 16], | ||
cvcLength: [3] | ||
}, { | ||
alias: 'master', | ||
type: 'mastercard', | ||
pattern: /^5[1-5]\d{14}$|^2(?:2(?:2[1-9]|[3-9]\d)|[3-6]\d\d|7(?:[01]\d|20))\d{12}$/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'amex', | ||
pattern: /^3[47]/, | ||
length: [15], | ||
cvcLength: [3, 4] | ||
}, { | ||
type: 'dinersclub', | ||
pattern: /^(?:3(?:0[0-5]|[68][0-9])[0-9]{11})$/, | ||
length: [14], | ||
cvcLength: [3] | ||
}, { | ||
type: 'discover', | ||
pattern: /^6([045]|22)/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'unionpay', | ||
pattern: /^(62|88)/, | ||
length: [16, 17, 18, 19], | ||
cvcLength: [3] | ||
}, { | ||
type: 'jcb', | ||
pattern: /^35/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'other', | ||
pattern: /\d/g, | ||
length: [20], | ||
cvcLength: [3] | ||
} | ||
]; | ||
this.rules = [ | ||
{ | ||
type: 'elo', | ||
pattern: /^(((40117[89])|(431274)|(438935)|(451416)|(457393)|(45763[12])|(504175)|(627780)|(636297)|(636368)|(65500[0-3])|(65165[2-4])|(65048[5-8])|(650489|65049[0-4])|(506699|5067[0-6][0-9]|50677[0-8])|(509[0-8][0-9]{2}|5099[0-8][0-9]|50999[0-9])|(65003[1-3])|(65003[5-9]|65004[0-9]|65005[01])|(65040[5-9]|6504[1-3][0-9])|(65048[5-9]|65049[0-9]|6505[0-2][0-9]|65053[0-8])|(65054[1-9]|6505[5-8][0-9]|65059[0-8])|(65070[0-9]|65071[0-8])|(65072[0-7])|(65090[1-9]|65091[0-9]|650920)|(65165[2-9]|6516[67][0-9])|(65500[0-9]|65501[0-9])|(65502[1-9]|6550[34][0-9]|65505[0-8]))\d{0,16})$/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'hipercard', | ||
pattern: /^(606282\d{10}(\d{3})?)|(3841\d{15})$/, | ||
format: /\d/g, | ||
length: [13, 16, 19], | ||
cvcLength: [3] | ||
}, { | ||
type: 'aura', | ||
pattern: /^(50)/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'visaelectron', | ||
pattern: /^4(026|17500|405|508|844|91[37])/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'maestro', | ||
pattern: /^(5(018|0[23]|[68])|6(39|7))/, | ||
length: [12, 13, 14, 15, 16, 17, 18, 19], | ||
cvcLength: [3] | ||
}, { | ||
type: 'forbrugsforeningen', | ||
pattern: /^600/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'dankort', | ||
pattern: /^5019/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'visa', | ||
pattern: /^4/, | ||
length: [13, 16], | ||
cvcLength: [3] | ||
}, { | ||
alias: 'master', | ||
type: 'mastercard', | ||
pattern: /(?:(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12})/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'amex', | ||
pattern: /^3[47]/, | ||
length: [15], | ||
cvcLength: [3, 4] | ||
}, { | ||
type: 'dinersclub', | ||
pattern: /^(?:3(?:0[0-5]|[68][0-9])[0-9]{11})$/, | ||
length: [14], | ||
cvcLength: [3] | ||
}, { | ||
type: 'discover', | ||
pattern: /^6([045]|22)/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'unionpay', | ||
pattern: /^(62|88)/, | ||
length: [16, 17, 18, 19], | ||
cvcLength: [3] | ||
}, { | ||
type: 'jcb', | ||
pattern: /^35/, | ||
length: [16], | ||
cvcLength: [3] | ||
}, { | ||
type: 'other', | ||
pattern: /\d/g, | ||
length: [20], | ||
cvcLength: [3] | ||
} | ||
]; | ||
}; | ||
CredircardWarder.prototype.getRule = function () { | ||
var self = this; | ||
var other = _(self.rules).find({type: 'other'}); | ||
var rule = _(self.rules).find( function(rule) { | ||
return rule.pattern.test( self.number ); | ||
}); | ||
return rule ? rule : other; | ||
var self = this; | ||
var other = _(self.rules).find({type: 'other'}); | ||
var rule = _(self.rules).find( function(rule) { | ||
return rule.pattern.test( self.number ); | ||
}); | ||
return rule ? rule : other; | ||
}; | ||
CredircardWarder.prototype.getBrand = function () { | ||
return this.getRule().type; | ||
return this.getRule().type; | ||
}; | ||
CredircardWarder.prototype.validate = function () { | ||
return luhn.validate(this.number); | ||
return luhn.validate(this.number); | ||
}; | ||
@@ -113,3 +113,4 @@ | ||
module.exports = function (number) { | ||
return new CredircardWarder(number); | ||
return new CredircardWarder(number); | ||
}; | ||
{ | ||
"name": "creditcard-warder", | ||
"version": "0.2.9", | ||
"version": "0.3.9", | ||
"description": "Rules from credit card from Brazil", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -41,3 +41,12 @@ var assert = require('assert'); | ||
assert.equal("mastercard", CreditcardWarder('5555555555555555').getBrand()); | ||
assert.equal("mastercard", CreditcardWarder('2221005555555459').getBrand()); | ||
assert.equal("mastercard", CreditcardWarder('2222005555555459').getBrand()); | ||
assert.equal("mastercard", CreditcardWarder('2720995555555459').getBrand()); | ||
assert.equal("mastercard", CreditcardWarder('5153295555555459').getBrand()); | ||
assert.equal("mastercard", CreditcardWarder('5321655555555459').getBrand()); | ||
assert.equal("mastercard", CreditcardWarder('5547845555555459').getBrand()); | ||
assert.equal("mastercard", CreditcardWarder('5413515555555459').getBrand()); | ||
assert.equal("mastercard", CreditcardWarder('5436275555555459').getBrand()); | ||
}); | ||
it('should not return mater brand', function(){ | ||
@@ -44,0 +53,0 @@ assert.notEqual("mastercard", CreditcardWarder('1221009999999999').getBrand()); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12318
2
531786