Skip to content
Myr

Speed up ID generation by binary mask

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andrey Sitnik · committed by Andrey Sitnik · parent bb3d6ca · Browse files · 4 files+37 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+37 added−17 removed

  • other:+37 added−17 removed

4 files+37 added−17 removed

modified:format.js+9 added-3 removed
modified:index.js+16 added-5 removed
modified:package.json+5 added-1 removed
modified:README.md+7 added-8 removed
78 unmodified lines
7980Symbols `-,.()` are not encoded in URL, but in the end of a link81they could be identified as a punctuation symbol.8283If you want to reduce ID length (and increase collisions probability),84you can pass length as argument:8586```js87nanoid(10) //=> "IRFa~VaY2b"88```8990### Custom Alphabet or Length9192If you want to change the ID alphabet or the length93you can use low-level `generate` module.
4 unmodified lines
98```99100Alphabet must contain less than 256 symbols.10195If you want to use the same URL-friendly symbols and just change the length,96you can get default alphabet from the `url` module:9798```js99var url = require('nanoid/url')100model.id = generate(url, 10) //=> "Uakgb_J5m9"101```102102### Custom Random Bytes Generator103104You can replace the default safe random generator using the `format` module.105For instance, to use seed-based generator.
23 unmodified lines