项目作者: leodido

项目描述 :
Fastest JavaScript implementation of the Luhn algorithm
高级语言: JavaScript
项目地址: git://github.com/leodido/luhn.js.git
创建时间: 2015-06-15T13:38:41Z
项目社区:https://github.com/leodido/luhn.js

开源协议:MIT License

下载


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.

  1. $ npm install luhn-alg
  2. $ bower install luhn-alg

Usage

Simplest API ever.

  1. luhn(x: number): boolean

Node.js

Try it in node.

  1. $ > var luhn = require('luhn-alg');
  2. $ > luhn('4242424242424242');
  3. $ 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