Functional Implementation of the Luhn Algorithm. No variable declaration, No mutation. A simple, lightweight implementation using composition. Used for testing a credit cards checksum value. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers.
Why another LUHN library
The goal was to write a LUHN Algorithm using a functional programming paradigm. A series of composable lambas that are processed right to left. Not a single if / else statement. All branching is handled by ternary functions with implicit returns.
yarn add fp-luhn
npm i fp-luhn
// luhn :: Numeric String -> Boolean
Accepts a numeric string. Eg: '4111111111111111'
import luhn from 'fp-luhn' luhn('4916737743057301') // true