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.0.2 to 2.1.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

2.1.0
=====
- Contextually validate month based on current year.
2.0.2

@@ -2,0 +7,0 @@ =====

2

package.json
{
"name": "card-validator",
"version": "2.0.2",
"version": "2.1.0",
"description": "A library for validating credit card fields",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -46,3 +46,3 @@ # Credit Card Validator [![Build Status](https://travis-ci.org/braintree/card-validator.svg)](https://travis-ci.org/braintree/card-validator) [![npm version](https://badge.fury.io/js/card-validator.svg)](http://badge.fury.io/js/card-validator)

type: 'american-express',
pattern: '^3[47][\\s\\d]*$',
pattern: '^3([47]\\d*)?$',
isAmex: true,

@@ -99,3 +99,3 @@ gaps: [4, 10],

<td><code>'60'</code></td>
<td><code>null</code></td>
<td><code>'discover'</code></td>
<td><strong>true</strong></td>

@@ -108,3 +108,3 @@ <td>false</td>

<td><code>'601'</code></td>
<td><code>null</code></td>
<td><code>'discover'</code></td>
<td><strong>true</strong></td>

@@ -125,3 +125,3 @@ <td>false</td>

<td><code>'601'</code></td>
<td><code>null</code></td>
<td><code>'discover'</code></td>
<td><strong>true</strong></td>

@@ -134,3 +134,3 @@ <td>false</td>

<td><code>'60'</code></td>
<td><code>null</code></td>
<td><code>'discover'</code></td>
<td><strong>true</strong></td>

@@ -175,3 +175,3 @@ <td>false</td>

<td><code>'4'</code></td>
<td><code>null</code></td>
<td><code>'visa'</code></td>
<td><strong>true</strong></td>

@@ -200,3 +200,3 @@ <td>false</td>

<td><code>'4111111111111111'</code></td>
<td><code>visa</code></td>
<td><code>'visa'</code></td>
<td><strong>true</strong></td>

@@ -203,0 +203,0 @@ <td><strong>true</strong></td>

@@ -16,3 +16,3 @@ var parseDate = require('./parse-date');

function expirationDate(value) {
var date, monthValid, yearValid;
var date, monthValid, yearValid, isValidForThisYear;

@@ -28,4 +28,11 @@ if (!isString(value)) {

if (monthValid.isValid && yearValid.isValid) {
return verification(true, true, date.month, date.year);
if (yearValid.isValid) {
if (yearValid.isCurrentYear) {
isValidForThisYear = monthValid.isValidForThisYear;
return verification(isValidForThisYear, isValidForThisYear, date.month, date.year);
}
if (monthValid.isValid) {
return verification(true, true, date.month, date.year);
}
}

@@ -32,0 +39,0 @@

var isString = require('lodash.isstring');
function verification(isValid, isPotentiallyValid) {
return {isValid: isValid, isPotentiallyValid: isPotentiallyValid};
function verification(isValid, isPotentiallyValid, isValidForThisYear) {
return {
isValid: isValid,
isPotentiallyValid: isPotentiallyValid,
isValidForThisYear: isValidForThisYear || false
};
}

@@ -9,2 +13,3 @@

var month, result;
var currentMonth = new Date().getMonth() + 1;

@@ -29,5 +34,5 @@ if (!isString(value)) {

return verification(result, result);
return verification(result, result, result && month >= currentMonth);
}
module.exports = expirationMonth;
var isString = require('lodash.isstring');
var maxYear = 19;
function verification(isValid, isPotentiallyValid) {
return {isValid: isValid, isPotentiallyValid: isPotentiallyValid};
function verification(isValid, isPotentiallyValid, isCurrentYear) {
return {
isValid: isValid,
isPotentiallyValid: isPotentiallyValid,
isCurrentYear: isCurrentYear || false
};
}
function expirationYear(value) {
var currentFirstTwo, currentYear, firstTwo, len, twoDigitYear, valid;
var currentFirstTwo, currentYear, firstTwo, len, twoDigitYear, valid, isCurrentYear;

@@ -44,10 +48,12 @@ if (!isString(value)) {

if (len === 2) {
isCurrentYear = twoDigitYear === value;
valid = value >= twoDigitYear && value <= twoDigitYear + maxYear;
} else if (len === 4) {
isCurrentYear = currentYear === value;
valid = value >= currentYear && value <= currentYear + maxYear;
}
return verification(valid, valid);
return verification(valid, valid, isCurrentYear);
}
module.exports = expirationYear;
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