🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

card-validator

Package Overview
Dependencies
Maintainers
1
Versions
39
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

to
6.1.0

5

CHANGELOG.md

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

6.1.0
=====
- Add option to set a `maxLength` for card number valiation
6.0.0

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

2

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

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

@@ -75,2 +75,18 @@ # 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)

You can optionally pass `maxLength` as a property of an object as a second argument. This will override the default behavior to use the card type's max length property and mark any cards that exceed the max length as invalid.
If a card brand has a normal max length that is shorter than the passed in max length, the validator will use the shorter one. For instance, if a `maxLength` of `16` is provided, the validator will still use `15` as the max length for American Express cards.
```javascript
valid.number(<Maestro Card with 19 Digits>, {maxLength: 16});
{
card: {
// Maestro card data
},
isPotentiallyValid: false,
isValid: false
}
```
If a valid card type cannot be determined, the `card` field in the response will be `null`.

@@ -77,0 +93,0 @@

@@ -35,2 +35,6 @@ 'use strict';

if (options.maxLength && value.length > options.maxLength) {
return verification(cardType, false, false);
}
if (cardType.type === getCardTypes.types.UNIONPAY && options.luhnValidateUnionPay !== true) {

@@ -43,6 +47,9 @@ isValid = true;

maxLength = Math.max.apply(null, cardType.lengths);
if (options.maxLength) {
maxLength = Math.min(options.maxLength, maxLength);
}
for (i = 0; i < cardType.lengths.length; i++) {
if (cardType.lengths[i] === value.length) {
isPotentiallyValid = value.length !== maxLength || isValid;
isPotentiallyValid = value.length < maxLength || isValid;
return verification(cardType, isPotentiallyValid, isValid);

@@ -49,0 +56,0 @@ }