Skip to content

pniewiejski/luhnjs

Repository files navigation

luhnjs

Luhn's algorithm, also known as mod 10 algorithm is a simple checksum algorithm used widely for validating identification numbers, such as credit card numbers. Check out Wikipedia article for more information. πŸ’°πŸ’³

ymmm... but why? πŸ’β€β™‚οΈ

The main goal for this project was to simply play with the N-API addon capability, implement some algorithm in C++ and use it in node.js application. πŸ‘¨β€πŸ’»

Also, ...just for fun! πŸ€·β€β™‚οΈ

πŸ’‘ If you notice some bad practices or you have any comments, please feel free to contact me.

How do I use it? πŸ€”

You can check if provided number (actually a string 🀫) is "valid" according to the Luhn's algorithm.

const luhn = require("luhnjs");
const isValid = luhn.isValid("123");
console.log(isValid);

You can also generate a checkDigit. Let's take an example from Wikipedia: Assume an example of an account number "7992739871" that will have a check digit added, making it of the form "7992739871x.

The way it works is that you should provide the 7992739871 number and the algorithm will compute the x digit.

const luhn = require("luhnjs");
const checkDigit = luhn.generateCheckDigit("7992739871");
console.log(checkDigit);

How to build it? πŸ› οΈ

Please find scripts in package.json:

  • npm run build - This command will build the C++ project.
  • npm run clean

If you want to find out how to run the C++ unit tests please read this.

Sources πŸ“š

About

😬 πŸ’³ Simple N-API addon with Luhn's algorithm implementation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published