getRandomKey()function
getRandomKey(length = 12): string
| Param | Type | |
|---|---|---|
length | unknown | Number of characters in the returned key — defaults to 12. Defaults to 12 |
| Return | |
|---|---|
string | Random string of length lowercase alphanumeric characters. |
Make a random key, e.g. xs23r34hhsdx or e4m29klrugef
- Not designed to be cryptographically random!
- Will probably clash — if you're making a random ID, check for existence of the record before saving.
- Designed to be semi-readable, doesn't use capital letters or
ioroorloru
Examples
const id = getRandomKey(); // e.g. `xs23r34hhsdx`