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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cc-validate

v2.0.6

Published

Credit Card validation using luhn algorithm

Readme

cc-validate

npm version license

Credit card validation powered by the Luhn algorithm, with card-type detection and number formatting. Works in Node.js with both JavaScript and TypeScript.

Live Demo


Supported Card Types

| Network | Prefix(es) | Length | |---|---|---| | Visa | 4 | 16–19 | | MasterCard | 51–55, 2221–2720 | 16 | | American Express | 34, 37 | 15 | | Discover | 6011, 622126–622925, 644–649, 65 | 16–19 | | JCB | 3528–3589 | 16–19 | | Maestro | 5018, 5020, 5038, 5893, 6304, 6759, 6761–6763 | 16–19 | | Diners Club | 300–305, 3095, 36, 38–39 | 13–19 |


Installation

npm install cc-validate

Usage

JavaScript

const { isValid } = require('cc-validate');

const result = isValid('4196 2214 3817 0266');

TypeScript

import { isValid, ValidationResult } from 'cc-validate';

const result: ValidationResult = isValid('4196 2214 3817 0266');

API

isValid(cardNumber: string): ValidationResult

Parameter: the card number as a string — spaces are ignored.

Returns a ValidationResult object:

interface ValidationResult {
    cardNumber: string;  // space-formatted number, e.g. "4196 2214 3817 0266"
    cardType:   string;  // detected network, e.g. "Visa" — "Unknown" if unrecognised
    isValid:    boolean; // true only when the Luhn check passes
    message:    string;  // human-readable result
}

Example:

isValid('4196 2214 3817 0266');
// {
//   cardNumber: '4196 2214 3817 0266',
//   cardType:   'Visa',
//   isValid:    true,
//   message:    'credit card number entered is valid'
// }

isValid('4111 2111 1111 1111');
// {
//   cardNumber: '4111 2111 1111 1111',
//   cardType:   'Visa',
//   isValid:    false,
//   message:    'credit card number entered is not valid'
// }

How It Works

The Luhn algorithm works by walking the digits from right to left, doubling every second digit (summing the two sub-digits if the result exceeds 9), then checking whether the total is divisible by 10. A detailed write-up is available in this article.


Development

# build
npm run build

# test
npm test

Changelog

| Version | Changes | |---|---| | 2.0.5 | Added live demo link | | 2.0.4 | Added Diners Club validation | | 2.0.0 | Card type detection and number formatting | | 1.0.9 | First stable release |


License

MIT — Hassan Shulli