| 1 |
// Borrowed from https://github.com/ai/nanoid/blob/3.0.2/non-secure/index.js |
| 2 |
// This alphabet uses `A-Za-z0-9_-` symbols. A genetic algorithm helped |
| 3 |
// optimize the gzip compression for this alphabet. |
| 4 |
let urlAlphabet = |
| 5 |
'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW' |
| 6 |
|
| 7 |
/** |
| 8 |
* |
| 9 |
* @public |
| 10 |
*/ |
| 11 |
export let nanoid = (size = 21) => { |
| 12 |
let id = '' |
| 13 |
// A compact alternative for `for (var i = 0; i < step; i++)`. |
| 14 |
let i = size |
| 15 |
while (i--) { |
| 16 |
// `| 0` is more compact and faster than `Math.floor()`. |
| 17 |
id += urlAlphabet[(Math.random() * 64) | 0] |
| 18 |
} |
| 19 |
return id |
| 20 |
} |