Socket
Book a DemoInstallSign in
Socket

cardy

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cardy

A credit card utility belt for browser and Node.js apps

latest
Source
npmnpm
Version
0.7.0
Version published
Weekly downloads
22
-24.14%
Maintainers
1
Weekly downloads
 
Created
Source

cardy

cardy

A credit card utility belt for browser and Node.js apps

Try out the demo

Installation

npm install cardy

Usage

Browser (ES6)

Validation

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

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

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

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

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
  • Icon by Flaticon

FAQs

Package last updated on 08 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.