Skip to content
Fastest JavaScript implementation of the Luhn algorithm
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.editorconfig
.eslintrc
.gitignore
.npmignore Already working
.travis.yml
.zuul.yml
LICENSE
README.md
bower.json
gulpfile.babel.js
index.js
index.js.map Already working
index.min.js
package.json
src.js
test.js

README.md

luhn.js

npm Bower Travis

Fastest JavaScript implementation of the Luhn algorithm.

Benchmarks here.

This algorithm (also known as Luhn formula) is useful to validate a variety of identification numbers (e.g. credit card numbers).

Install

~1KB.

UMD builds for development - index.js and index.js.map - and production - index.min.js - available.

So it's installable both on node and/or for browsers.

$ npm install luhn-alg
$ bower install luhn-alg

Usage

Simplest API ever.

luhn(x: number): boolean

Node.js

Try it in node.

$ > var luhn = require('luhn-alg');
$ > luhn('4242424242424242');
$ true

Browsers

Include the UMD build (e.g., index.min.js) and you'll have a luhn function on the window/global scope.

Or use CommonJS, AMD, WTFYW etc.

Tests

This project is fully unit tested on:

Credits

  • ShirtlessKirk's popular gist
  • Anyone contributing and improving performances

Analytics

Something went wrong with that request. Please try again.