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. π°π³
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.
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);
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.