damm32
v2.0.0
Published
Base32 implementation of the Damm check digit algorithm
Maintainers
Readme
damm32
Base32 check digits using the Damm algorithm, which detects every single-character error and every adjacent transposition. Useful for human-entered codes such as licence keys, voucher codes and sample IDs.
The alphabet leaves out easily confused characters (0/o, 1/i/l):
23456789abcdefghjkmnpqrstuvwxyz*Input is case-insensitive. No dependencies; works in Node.js 20+ and modern browsers. TypeScript declarations are included.
Install
npm install damm32Usage
import { checkDigit, isValid, value, INVALID } from 'damm32';
checkDigit('fdfsdfds'); // '3', or INVALID ('-') if a character is outside the alphabet
isValid('fdfsdfds3'); // true
isValid('fdfsdfd3s'); // false (transposition detected)
value('f'); // 0-31, or -1 if not in the alphabetCommand line
npx damm32 -a fdfsdfds # fdfsdfds3
npx damm32 -c fdfsdfds3 # exit status 0 if valid, 1 if notRun npx damm32 --help for all options. Quote codes containing * in the shell.
C and PHP implementations with identical output are in the GitHub repository.
Licence
BSD 2-Clause
