Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

card-validator

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

card-validator - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

7

CHANGELOG.md

@@ -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

2

package.json
{
"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);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc