Small Node.js CLI for generating zero-padded numeric codes with cryptographically secure randomness.
This project targets Node.js 24 LTS. Use .nvmrc with nvm use, or install any 24.x release.
Global install:
npm install -g @poln/gen6dcodeRun without installing:
npx @poln/gen6dcodeGenerate the default 6-digit code:
gen6dcodeGenerate a custom length:
gen6dcode --digits 8
gen6dcode -d 20Generate JSON output:
gen6dcode --json
gen6dcode --json --digits 8Show help:
gen6dcode --helpExample output:
gen6dcode v3.1.0
+---------------------------+
| digits : 6 |
| code : 482913 |
+---------------------------+
JSON output:
{"name":"@poln/gen6dcode","version":"3.1.0","digits":6,"code":"482913"}- Supported digit range:
1to20 - Output is always zero-padded to the requested length
- Invalid input exits with code
1
Example invalid input:
gen6dcode -d 0
# --digits must be an integer between 1 and 20Older implementations based on Math.random() and floating-point math can produce biased output and become inaccurate at higher digit counts. This package now uses Node's crypto module, including a secure fast path for smaller codes and exact BigInt-based generation for larger ones.
npm install
nvm use
npm start
npm start -- --digits 12
npm test