npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@juspay/simple-card-validator

v1.2.3

Published

Card validation helpers for card number, expiry and CVV.

Downloads

1,537

Readme

Card Validator

Generic helpers for card number, expiry and CVV validations

npm version

Usage:

Import the library and initialize card object.

Install from npm:

npm i @juspay/simple-card-validator --save

var cardValidator = require('simple-card-validator');

Or, you can simply use the file from dist/validator.js if you are not using node/npm.

var card = new cardValidator('4242-4242-4242-4242');

Getting card details

card.getCardDetails(); This would output, card brand and different validation outputs like below:

{ card_type: 'visa',
  valid: true,
  luhn_valid: true,
  length_valid: true,
  cvv_length: [ 3 ],
  gaps: [ 4, 8, 12 ],
  supported_lengths: [ 16 ],
  max_length: 16 }

Output format

| Field | Description | Type | | ----------------- | ------------------------------------- | ----------------- | | card_type | The card issuer for the provided card | String | | valid | Are the card details valid | Boolean | | luhn_valid | Is the card number valid | Boolean | | length_valid | If the card number length is valid | Boolean | | cvv_length | If the CVV/CAVV length is valid | Array [ Integer ] | | gaps | Gaps for UI as printed in cards | Array [ Integer ] | | supported_lengths | Supported lengths for the card type | Array [ Integer ] | | max_length | Maximum length for the card type | Integer |

Validations

To simply validate a card, call: card.validateCard(); The result will be a validity boolean.

For validating expiry date, card.validateExpiry('12/2018');

Additionally, the base date can be set for expiry validations. The base month and date can be provided by using, card.setBaseDate(month, year);

eg: card.setBaseDate('02', '2016');

For validating CVV, use: card.validateCvv(111); CVV will be validated based on the brand of the card.

Contribution

Read through the development guidelines.

License

MIT license. Copyright © 2018 - juspay.in.