card-validator
Advanced tools
@@ -19,4 +19,5 @@ import type { Verification } from "./types"; | ||
| luhnValidateUnionPay?: boolean; | ||
| skipLuhnValidation?: boolean; | ||
| }; | ||
| export declare function cardNumber(value: string | unknown, options?: CardNumberOptions): CardNumberVerification; | ||
| export {}; |
@@ -34,4 +34,5 @@ "use strict"; | ||
| } | ||
| if (cardType.type === getCardTypes.types.UNIONPAY && | ||
| options.luhnValidateUnionPay !== true) { | ||
| if (options.skipLuhnValidation === true || | ||
| (cardType.type === getCardTypes.types.UNIONPAY && | ||
| options.luhnValidateUnionPay !== true)) { | ||
| isValid = true; | ||
@@ -38,0 +39,0 @@ } |
+1
-1
| { | ||
| "name": "card-validator", | ||
| "version": "9.0.0", | ||
| "version": "9.1.0", | ||
| "description": "A library for validating credit card fields", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+2
-0
@@ -79,2 +79,4 @@ # Credit Card Validator [](https://github.com/braintree/card-validator/actions?query=workflow%3A%22Unit+Tests%22) [](http://badge.fury.io/js/card-validator) | ||
| You can optionally pass `skipLuhnValidation: true` as a property of an object as a second argument. This will override the default behaviour and will skip the validation of the check digit of the card number using Luhn Algorithm. The `skipLuhnValidation` **should not** be set to `true` in production environment. | ||
| ```javascript | ||
@@ -81,0 +83,0 @@ valid.number(<Maestro Card with 19 Digits>, {maxLength: 16}); |
@@ -352,2 +352,23 @@ import { cardNumber, CardNumberVerification } from "../card-number"; | ||
| }); | ||
| describe("Skip Luhn Validation", () => { | ||
| const number = "5732806135556590"; | ||
| it("should fail validation for a card with invalid luhn check digit", () => { | ||
| const actual = cardNumber(number); | ||
| expect(actual.card.type).toBe("maestro"); | ||
| expect(actual.isPotentiallyValid).toBe(true); | ||
| expect(actual.isValid).toBe(false); | ||
| }); | ||
| it("should succeed validation for a card with invalid luhn check digit when using skipLuhnValidation=true", () => { | ||
| const actual = cardNumber(number, { | ||
| skipLuhnValidation: true, | ||
| }); | ||
| expect(actual.card.type).toBe("maestro"); | ||
| expect(actual.isPotentiallyValid).toBe(true); | ||
| expect(actual.isValid).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
@@ -25,2 +25,3 @@ import luhn10 = require("./luhn-10"); | ||
| luhnValidateUnionPay?: boolean; | ||
| skipLuhnValidation?: boolean; | ||
| }; | ||
@@ -71,4 +72,5 @@ | ||
| if ( | ||
| cardType.type === getCardTypes.types.UNIONPAY && | ||
| options.luhnValidateUnionPay !== true | ||
| options.skipLuhnValidation === true || | ||
| (cardType.type === getCardTypes.types.UNIONPAY && | ||
| options.luhnValidateUnionPay !== true) | ||
| ) { | ||
@@ -75,0 +77,0 @@ isValid = true; |
118584
1.02%3512
0.6%402
0.5%