card-validator
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -0,5 +1,10 @@ | ||
2.2.0 | ||
===== | ||
- CVV validator can accept an array of possible length values | ||
2.1.0 | ||
===== | ||
- Contextually validate month based on current year. | ||
- Contextually validate month based on current date. | ||
@@ -6,0 +11,0 @@ 2.0.2 |
{ | ||
"name": "card-validator", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "A library for validating credit card fields", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var isString = require('lodash.isstring'); | ||
var DEFAULT_LENGTH = 3; | ||
function includes(array, thing) { | ||
var i = 0; | ||
for (; i < array.length; i++) { | ||
if (thing === array[i]) { return true; } | ||
} | ||
return false; | ||
} | ||
function min(array) { | ||
var minimum = DEFAULT_LENGTH; | ||
var i = 0; | ||
for (; i < array.length; i++) { | ||
minimum = array[i] < minimum ? array[i] : minimum; | ||
} | ||
return minimum; | ||
} | ||
function max(array) { | ||
var maximum = DEFAULT_LENGTH; | ||
var i = 0; | ||
for (; i < array.length; i++) { | ||
maximum = array[i] > maximum ? array[i] : maximum; | ||
} | ||
return maximum; | ||
} | ||
function verification(isValid, isPotentiallyValid) { | ||
@@ -10,8 +42,9 @@ return {isValid: isValid, isPotentiallyValid: isPotentiallyValid}; | ||
maxLength = maxLength || DEFAULT_LENGTH; | ||
maxLength = maxLength instanceof Array ? maxLength : [maxLength]; | ||
if (!isString(value)) { return verification(false, false); } | ||
if (!/^\d*$/.test(value)) { return verification(false, false); } | ||
if (value.length === maxLength) { return verification(true, true); } | ||
if (value.length < maxLength) { return verification(false, true); } | ||
if (value.length > maxLength) { return verification(false, false); } | ||
if (includes(maxLength, value.length)) { return verification(true, true); } | ||
if (value.length < min(maxLength)) { return verification(false, true); } | ||
if (value.length > max(maxLength)) { return verification(false, false); } | ||
@@ -18,0 +51,0 @@ return verification(true, true); |
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
106696
2360