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

creditcards-fabricio

v2.1.2

Published

Utility methods for formatting and validating credit cards

Downloads

3

Readme

creditcards Build Status

Parse, format, and validate credit card data.

Installing

$ npm install --save creditcards

API

creditcards exports:

  • card
  • cvc
  • expiration

You can also require modules individually:

var card = require('creditcards/card')

card

card.parse(number) -> string

Remove all non-numeric characters from a card number, including punctuation and spacing.

number

Required
Type: string


card.format(number, [separator]) -> string

Formats a card number as printed on the physical card

number

Required
Type: string

separator

Type: string Default: ' ' (space)

card.format('4242424242424242') === '4242 4242 4242 4242' // Visa
card.format('378282246310005') === '3782 822463 10005' // American Express

card.type(number, [eager]) -> string

Returns the matched card type, or undefined if there was no match. For a full list of supported card types, see creditcards-types.

number

Required
Type: string

The card number. Punctuation is not allowed. Sanitize input through card.parse first if needed.

eager

Type: boolean
Default: false

When true, the card type will be eagerly matched using a more permissive pattern that can match partial card numbers.


card.luhn(number) -> Boolean

Checks the card number's validity using the Luhn algorithm.

number

Required
Type: string

card.isValid(number, [type]) -> boolean

number

Required
Type: string

type

Type: string
Default: undefined

Detect if a card is a valid card of the specified type. If no type is provided, the card will be valid if any type is matched.

cvc

cvc.isValid(cvc, [type]) -> boolean

cvc

Required
Type: string

type

Type: string
Default: undefined

Detect if a CVC is valid card for the specified type.

expiration

isPast(month, year) -> boolean

month

Required
Type: number

year

Required
Type: number


expiration.month.parse(month) -> number

Casts the provide value a number. All of the following will be 5 after parsing:

  • 5
  • '05'
  • '5'
month

Required
Type: string / number


expiration.month.isValid(month) -> Boolean

month

Required
Type: number


expiration.year.parse(year, [expand]) -> number

All of the following are equivalent:

  • expiration.year.parse(2014)
  • expiration.year.parse('2014')
  • expiration.year.parse('14', true)
  • expiration.year.parse(14, true)
year

Required
Type: string / number

expand

Type: boolean
Default: false

If true, the year is assumed to be a 1 or 2 digit number and is expanded to its full value.


expiration.year.format(year, [strip]) -> string

year

Required
Type: number

strip

Type: boolean
Default: false

If true, year is assumed to be a four digit number and will be converted to a two digit number.

  • expiration.year.format(2014) === '2014'
  • expiration.year.format(2014, true) === '14'

expiration.year.isValid(year) -> Boolean

year

Required
Type: number


expiration.year.isPast(year) -> boolean

year

Required
Type: number

License

MIT © Ben Drucker