luhn-tiny
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

luhn

A simple function to allow you to check whether a credit card number's checksum digit (or the trailing luhn checksum digit of any similar number such as a phone's IMEI) is correct.

Usage:

luhn('4111 1111 1111 1111')   // returns true
luhn('4111-1111-1111-1112')   // returns true
luhn(4111111111111)           // returns true
luhn(4111111111112)           // returns false

As you can see, it accepts a number or a string and ignores non-numeric characters in strings (e.g. spaces or dashes).

There's a ton of these functions out there, but I'm pretty sure this is the smallest and probably the fastest.

Package Sidebar

Install

npm i luhn-tiny

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

9.43 kB

Total Files

12

Last publish

Collaborators

  • tonioloewald