/luhnjs

😬 💳 Simple N-API addon with Luhn's algorithm implementation.

Primary LanguageC++MIT LicenseMIT

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 📚