Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinsisley/cardy
A credit card utility belt for browser and Node.js apps
https://github.com/justinsisley/cardy
browser creditcard nodejs
Last synced: about 1 month ago
JSON representation
A credit card utility belt for browser and Node.js apps
- Host: GitHub
- URL: https://github.com/justinsisley/cardy
- Owner: justinsisley
- License: mit
- Created: 2017-08-19T04:23:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-08T05:15:09.000Z (over 7 years ago)
- Last Synced: 2024-09-18T09:13:03.001Z (3 months ago)
- Topics: browser, creditcard, nodejs
- Language: JavaScript
- Homepage: http://bit.ly/2xvZtf4
- Size: 129 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
cardy
A credit card utility belt for browser and Node.js apps#### Try out the demo
## Installation
```bash
npm install cardy
```## Usage
### Browser (ES6)
#### Validation
```javascript
import cardy from 'cardy';// Validate a card number
const numberValidationResult = cardy.number.validate('4111111111111111');// Validate an expiration date
const expirationValidationResult = cardy.expiration.validate('01/2020');
```#### Formatting
```javascript
import cardy from 'cardy';// Format a card number
const formattedNumber = cardy.number.format('4111111111111111');// Format an expiration date
const formattedExpiration = cardy.expiration.format('01/2020');
```#### Input Masking
```javascript
import cardy from 'cardy';// Credit card input field in your app
const numberInput = document.querySelector('#card-number-input');numberInput.addEventListener('input', (e) => {
numberInput.value = cardy.number.mask(numberInput.value);
});// Expiration date input field in your app
const expirationInput = document.querySelector('#card-expiration-input');expirationInput.addEventListener('input', (e) => {
expirationInput.value = cardy.expiration.mask(expirationInput.value);
});// Security code input field in your app
const securityCodeInput = document.querySelector('#card-security-code-input');securityCodeInput.addEventListener('input', (e) => {
securityCodeInput.value = cardy.code.mask(securityCodeInput.value);// Optionally, enforce the security code length by passing a valid `codeSize`
// value, which you can obtain from `card.number.validate()`
securityCodeInput.value = cardy.code.mask(securityCodeInput.value, 3);
});
```### Node.js
#### Validation
```javascript
const cardy = require('cardy');// Validate a card number
const numberValidationResult = cardy.number.validate('4111111111111111');// Validate an expiration date
const expirationValidationResult = cardy.expiration.validate('01/2020');
```#### Formatting
```javascript
const cardy = require('cardy');// Format a card number
const formattedNumber = cardy.number.format('4111111111111111');// Format an expiration date
const formattedExpiration = cardy.expiration.format('01/2020');
```## Credits
- Depends on [card-validator](https://github.com/braintree/card-validator)
- Icon by [Flaticon](http://www.flaticon.com/)