node-cdkey
Generate random string by template.
Installation
npm i cdkey
Basic Usage
Browser
Node.js
const cdkey = default // cjs console // eC8q-8ERg-fTZa-Vh2o
Advenced Usage
Simple amount
Generate string by default template (diablo style).
// eC8q-8ERg-fTZa-Vh2o // [ 'kcsi-V5xR-1xv8-zq7q', 'cumh-jYVn-5vL9-mwLM' ]
Template
Generate string by custom template.
syntax | chars for random | exclude non-readable chars |
---|---|---|
0 |
[0-9] | [01] |
A |
[A-Z] | [OI] |
a |
[a-z] | [l] |
X |
[0-9] + [A-Z] | [01OI] |
x |
[0-9] + [a-z] | [01l] |
? |
[0-9] + [A-Z] + [a-z] | [01OIl] |
// 7F3K // [ 'cUwc', 'n9zu' ] // ABBA // [ 'BCAA', 'ACAB' ]
Options
Generate string by custom or builtin options.
- The 2ed argument would override options.amount
- The 3rd argument would override options.template or options.length, depand on style.
attribute | type | default |
---|---|---|
options.char | string | |
options.length | number | |
options.template | string | |
options.syntax | object | |
options.amount | number | 1 |
char + length (custom)
// acab // aca
template + syntax (custom)
// [ "1220", "2001" ] // [ "1220", "2001" ]
char + length (builtin options)
key | char | length |
---|---|---|
ALPHANUMERIC |
[0-9 a-z A-Z] | 32 |
ALPHABETIC |
[a-z A-Z] | 32 |
NUMBER , NUMERIC |
[0-9] | 32 |
UPPER |
[A-Z] | 32 |
LOWER |
[a-z] | 32 |
HEX |
[0-9 A-F] | 32 |
// 22030189956236488846744098007707 // [ '05250373', '42852368' ]
template + syntax (builtin options)
key | template |
---|---|
DEFAULT |
'????-????-????-????' |
DIABLO |
'XXXX-XXXX-XXXX-XXXX' |
// [ '2F2L-HJTG-P4L6-QBTZ', 'F1XM-K9JZ-ED9L-EPL9' ]
Fluent (chain methods)
Generate string by custom options and chain methods.
lengthNumber length
length8 // 01201002 // [ 'BCAA', 'ACAB' ]
Helper methods
// To get default syntax object.// {// '0': '23456789',// 'A': 'ABCDEFGHJKLMNPQRSTUVWXYZ',// 'a': 'abcdefghijkmnopqrstuvwxyz',// 'X': '23456789ABCDEFGHJKLMNPQRSTUVWXYZ',// 'x': '23456789abcdefghijkmnopqrstuvwxyz',// '?': '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'// }
TODO
- escape string in template.
- command line support.
browser support.