Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ContaAzul/creditcard.js
A simple credit card validation library in JavaScript
https://github.com/ContaAzul/creditcard.js
credit-card javascript nodejs validation
Last synced: about 2 months ago
JSON representation
A simple credit card validation library in JavaScript
- Host: GitHub
- URL: https://github.com/ContaAzul/creditcard.js
- Owner: ContaAzul
- License: other
- Created: 2016-01-25T15:39:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T06:31:04.000Z (5 months ago)
- Last Synced: 2024-07-18T00:16:18.254Z (2 months ago)
- Topics: credit-card, javascript, nodejs, validation
- Language: JavaScript
- Homepage: http://contaazul.github.io/creditcard.js/
- Size: 2.12 MB
- Stars: 372
- Watchers: 56
- Forks: 81
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-made-by-brazilians - creditcard.js
README
# creditcard.js
[![Build Status](https://github.com/ContaAzul/creditcard.js/workflows/Build%20Check/badge.svg)](https://github.com/ContaAzul/creditcard.js/actions?query=workflow%3A%22Build+Check%22)
![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/creditcard.js)
[![npm](https://img.shields.io/npm/v/creditcard.js.svg)](https://www.npmjs.com/package/creditcard.js)> A simple credit cards validation library in JavaScript.
Project website: https://contaazul.github.io/creditcard.js
## Install
creditcard.js is available as a NPM package. You can install through Yarn or NPM:
### Yarn
```sh
yarn add creditcard.js
```### NPM
```sh
npm install creditcard.js
```## Usage
```javascript
import { isValid, isExpirationDateValid, isSecurityCodeValid, getCreditCardNameByNumber } from 'creditcard.js';isValid('4916108926268679'); // returns true
isExpirationDateValid('02', '2020'); // returns true
isSecurityCodeValid('4556603578296676', '250'); // returns true
getCreditCardNameByNumber('4539578763621486'); // returns 'Visa'
```## Methods
### `isValid(number)` -> `boolean`
Checks whether the credit card number format is valid. _(See the full list of [currently supported cards](#suportted-credit-card-types))_
**number**
_Required_\
Type: `string`**options**
_Optional_\
Type: `{ cards: string[] } `---
### `isExpirationDateValid(month, year)` -> `boolean`
Checks that the expiration date is valid and not expired. _(2 or 4 digit years are accepted)_
**month**
_Required_\
Type: `string`**year**
_Required_\
Type: `string`---
### `isSecurityCodeValid(creditCardNumber, securityCode)` -> `boolean`
Check that the security code is valid according to the type of credit card.
**creditCardNumber**
_Required_\
Type: `string`**securityCode**
_Required_\
Type: `string`---
### `getCreditCardNameByNumber(number)` -> `string`
Returns the credit card type from the card number. _(See the full list of [currently supported cards](#supported-credit-card-types))_
**number**
_Required_\
Type: `string`---
## Supported credit card types
- American Express
- Aura
- Banescard
- Cabal
- Diners
- Discover
- Elo
- Goodcard
- Hipercard
- Mastercard
- Maxxvan
- Visa## Credits
The first version of this library was based on [bin-cc](https://github.com/renatovico/bin-cc).
## License
MIT © Conta Azul