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
38
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.2.8 to 2.3.0

5

CHANGELOG.md

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

2.3.0
=====
- valid.expirationDate can take an object with month and year fields or a string value
2.2.8

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

4

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

@@ -16,3 +16,3 @@ "main": "index.js",

},
"author": "",
"author": "Braintree <code@getbraintree.com> (https://www.braintreepayments.com/)",
"license": "MIT",

@@ -19,0 +19,0 @@ "devDependencies": {

@@ -19,2 +19,4 @@ # 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)

### Using a CommonJS build tool (browserify, webpack, etc)
```javascript

@@ -34,2 +36,20 @@ var valid = require('card-validator');

### Loading pre-bundled code in browser
```html
<!-- after downloading the bundled code from https://github.com/braintree/card-validator/blob/master/dist/card-validator.js -->
<script src="path/to/card-validator.js"></script>
<script>
var numberValidation = cardValidator.number('4111');
if (!numberValidation.isPotentiallyValid) {
renderInvalidCardNumber();
}
if (numberValidation.card) {
console.log(numberValidation.card.type); // 'visa'
}
</script>
```
## API

@@ -215,3 +235,3 @@

#### `valid.expirationDate(value: string): object`
#### `valid.expirationDate(value: string|object): object`

@@ -229,6 +249,8 @@ ```javascript

| Input | Output |
| ----- | ------ |
| `'10/19'`<br/>`'10 / 19'`<br />`'1019'`<br/>`'10 19'` | `{month: '10', year: '19'}` |
| `'10/2019'`<br/>`'10 / 2019'`<br />`'102019'`<br/>`'10 2019'`<br/>`'10 19'` | `{month: '10', year: '2019'}` |
| Input | Output |
|-------------------------------------------------------------------------------------------|-------------------------------|
| `'10/19'`<br/>`'10 / 19'`<br />`'1019'`<br/>`'10 19'` | `{month: '10', year: '19'}` |
| `'10/2019'`<br/>`'10 / 2019'`<br />`'102019'`<br/>`'10 2019'`<br/>`'10 19'` | `{month: '10', year: '2019'}` |
| `{month: '01', year: '19'}`<br/>`{month: '1', year: '19'}`<br/>`{month: 1, year: 19}` | `{month: '01', year: '19'}` |
| `{month: '10', year: '2019'}`<br/>`{month: '1', year: '2019'}`<br/>`{month: 1, year: 19}` | `{month: '10', year: '2019'}` |

@@ -235,0 +257,0 @@ - - -

@@ -20,8 +20,14 @@ 'use strict';

if (!isString(value)) {
if (isString(value)) {
value = value.replace(/^(\d\d) (\d\d(\d\d)?)$/, '$1/$2');
date = parseDate(value);
} else if (value !== null && typeof value === 'object') {
date = {
month: String(value.month),
year: String(value.year)
};
} else {
return verification(false, false, null, null);
}
value = value.replace(/^(\d\d) (\d\d(\d\d)?)$/, '$1/$2');
date = parseDate(value);
monthValid = expirationMonth(date.month);

@@ -28,0 +34,0 @@ yearValid = expirationYear(date.year);

@@ -0,8 +1,51 @@

/*
* Luhn algorithm implementation in JavaScript
* Copyright (c) 2009 Nicholas C. Zakas
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
'use strict';
/*eslint-disable*/
module.exports = function luhn10(a,b,c,d,e) {
for(d = +a[b = a.length-1], e=0; b--;)
c = +a[b], d += ++e % 2 ? 2 * c % 10 + (c > 4) : c;
return !(d%10)
};
function luhn10(identifier) {
var sum = 0;
var alt = false;
var i = identifier.length - 1;
var num;
while (i >= 0) {
num = parseInt(identifier.charAt(i), 10);
if (alt) {
num *= 2;
if (num > 9) {
num = (num % 10) + 1; // eslint-disable-line no-extra-parens
}
}
alt = !alt;
sum += num;
i--;
}
return sum % 10 === 0;
}
module.exports = luhn10;
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