Static
dictionaryDictionary that contains all valid characters. Override it if you want to use additional/less characters
Static
sensitiveToggle if the class should be case sensitive
Static
Protected
Readonly
char2indexStatic
Protected
Readonly
filterStatic
generateGenerates a check character for the input string.
Luhn.generate('foo') // -> {phrase: 'foo', checksum: '5'}
Luhn.generate('FoO') // -> {phrase: 'foo', checksum: '5'}
Luhn.generate('FoO', true) // -> {phrase: 'FoO', checksum: 'n'}
The string that should have a check character
Optional
sensitive: booleanToggle if the function should be case-sensitive or not.
The filtered string and checksum character
Static
Protected
Readonly
getNStatic
Protected
Readonly
index2charStatic
lowercaseStatic
Protected
Readonly
reduceHigher-order function that returns a reducer that calculates the checksum
Reducer function that is applied on an array of characters in order to calculate a checksum.
current sum of the checksum
current character that is being calculated
the checksum
Static
validateValidates if the given string, matches the calculated checksum. The last character in the string is considered the checksum.
Luhn.validate('foo5') // -> {phrase: 'foo5', isValid: true}
Luhn.validate('FoO5') // -> {phrase: 'foo5', isValid: true}
Luhn.validate('FoOö5') // -> {phrase: 'foo5', isValid: true}
Luhn.validate('FoO5', true) // -> {phrase: 'FoO5', isValid: false}
The string that you want to check, including the check character in the end of the string
Optional
sensitive: booleanToggle if the function should be case-sensitive or not.
returns if the string is valid or not.
Generated using TypeDoc
Lets you easily generate and validate checksum values based on the Luhn mod-N algorithm