-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use fork of nanoid * Remove nanoid * Update to Immer 6 alpha * Enable Immer 6's ES5 support * Add TS 3.8 coverage
- Loading branch information
1 parent
a6e5e5f
commit 7699b02
Showing
6 changed files
with
40 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Borrowed from https://github.com/ai/nanoid/tree/master/non-secure | ||
// This alphabet uses a-z A-Z 0-9 _- symbols. | ||
// Symbols are generated for smaller size. | ||
// -_zyxwvutsrqponmlkjihgfedcba9876543210ZYXWVUTSRQPONMLKJIHGFEDCBA | ||
let url = '-_' | ||
// Loop from 36 to 0 (from z to a and 9 to 0 in Base36). | ||
let i = 36 | ||
while (i--) { | ||
// 36 is radix. Number.prototype.toString(36) returns number | ||
// in Base36 representation. Base36 is like hex, but it uses 0–9 and a-z. | ||
url += i.toString(36) | ||
} | ||
// Loop from 36 to 10 (from Z to A in Base36). | ||
i = 36 | ||
while (i-- - 10) { | ||
url += i.toString(36).toUpperCase() | ||
} | ||
|
||
export function nanoid(size = 21) { | ||
let id = '' | ||
// Compact alternative for `for (var i = 0; i < size; i++)` | ||
while (size--) { | ||
// `| 0` is compact and faster alternative for `Math.floor()` | ||
id += url[(Math.random() * 64) | 0] | ||
} | ||
return id | ||
} |