card-validator
Advanced tools
Comparing version 4.1.1 to 4.2.0
@@ -0,1 +1,6 @@ | ||
4.2.0 | ||
===== | ||
- Allow `maxElapsedYear` to be configurable in `expirationYear` and `expirationDate` (thanks @wozaki) | ||
4.1.1 | ||
@@ -2,0 +7,0 @@ ===== |
{ | ||
"name": "card-validator", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"description": "A library for validating credit card fields", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -213,4 +213,6 @@ # 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) | ||
#### `valid.expirationDate(value: string|object): object` | ||
#### `valid.expirationDate(value: string|object, maxElapsedYear: integer): object` | ||
The `maxElapsedYear` has a default value of 19. It can be overridden by passing in an `integer` as a second argument. | ||
```javascript | ||
@@ -250,6 +252,8 @@ { | ||
#### `valid.expirationYear(value: string): object` | ||
#### `valid.expirationYear(value: string, maxElapsedYear: integer): object` | ||
`expirationYear` accepts 2 or 4 digit years. `16` and `2016` are both valid entries. | ||
The `maxElapsedYear` has a default value of 19. It can be overridden by passing in an `integer` as a second argument. | ||
```javascript | ||
@@ -302,3 +306,3 @@ { | ||
- The maximum expiration year is 19 years from now. ([view in source](src/expiration-year.js)) | ||
- The default maximum expiration year is 19 years from now. | ||
- `valid.expirationDate` will only return `month:` and `year:` as strings if the two are valid, otherwise they will be `null`. | ||
@@ -305,0 +309,0 @@ - Since non-US postal codes are alpha-numeric, the `postalCode` will allow non-number characters to be used in validation. |
@@ -16,3 +16,3 @@ 'use strict'; | ||
function expirationDate(value) { | ||
function expirationDate(value, maxElapsedYear) { | ||
var date, monthValid, yearValid, isValidForThisYear; | ||
@@ -33,3 +33,3 @@ | ||
monthValid = expirationMonth(date.month); | ||
yearValid = expirationYear(date.year); | ||
yearValid = expirationYear(date.year, maxElapsedYear); | ||
@@ -36,0 +36,0 @@ if (monthValid.isValid) { |
'use strict'; | ||
var maxYear = 19; | ||
var DEFAULT_VALID_NUMBER_OF_YEARS_IN_THE_FUTURE = 19; | ||
@@ -13,5 +13,7 @@ function verification(isValid, isPotentiallyValid, isCurrentYear) { | ||
function expirationYear(value) { | ||
function expirationYear(value, maxElapsedYear) { | ||
var currentFirstTwo, currentYear, firstTwo, len, twoDigitYear, valid, isCurrentYear; | ||
maxElapsedYear = maxElapsedYear || DEFAULT_VALID_NUMBER_OF_YEARS_IN_THE_FUTURE; | ||
if (typeof value !== 'string') { | ||
@@ -51,6 +53,6 @@ return verification(false, false); | ||
isCurrentYear = twoDigitYear === value; | ||
valid = value >= twoDigitYear && value <= twoDigitYear + maxYear; | ||
valid = value >= twoDigitYear && value <= twoDigitYear + maxElapsedYear; | ||
} else if (len === 4) { | ||
isCurrentYear = currentYear === value; | ||
valid = value >= currentYear && value <= currentYear + maxYear; | ||
valid = value >= currentYear && value <= currentYear + maxElapsedYear; | ||
} | ||
@@ -57,0 +59,0 @@ |
23171
289
318