diff options
| author | Marak <[email protected]> | 2017-09-08 12:52:43 -0400 |
|---|---|---|
| committer | Marak <[email protected]> | 2017-09-08 12:52:43 -0400 |
| commit | b652617fa5f78279cae3a5f64e7930a19369dd38 (patch) | |
| tree | b029cbd80f86be3db39c3b72e7f7514a6624b179 /test/support | |
| parent | f4236a85b904394c729c3efb383c09fa5d137c54 (diff) | |
| parent | 52d8cc1471080fe67c8abd8115240b6aa933f85f (diff) | |
| download | faker-b652617fa5f78279cae3a5f64e7930a19369dd38.tar.xz faker-b652617fa5f78279cae3a5f64e7930a19369dd38.zip | |
Merge branch 'creditCard' of https://github.com/zpiman/faker.js
Diffstat (limited to 'test/support')
| -rw-r--r-- | test/support/luhnCheck.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/support/luhnCheck.js b/test/support/luhnCheck.js new file mode 100644 index 00000000..1e195544 --- /dev/null +++ b/test/support/luhnCheck.js @@ -0,0 +1,18 @@ +module.exports = function (number) { + number = number.replace(/\D/g,""); + var split = number.split(""); + split = split.map(function(num){return parseInt(num);}); + var check = split.pop(); + split.reverse(); + split = split.map(function(num, index){ + if(index%2 === 0) { + num *= 2; + if(num>9) { + num -= 9; + } + } + return num; + }); + var sum = split.reduce(function(prev,curr){return prev + curr;}); + return (sum%10 === check); +}; |
