forked from daren.hsu/line_push
update
This commit is contained in:
+3
-12
@@ -1,30 +1,21 @@
|
||||
// This alphabet uses `A-Za-z0-9_-` symbols. The genetic algorithm helped
|
||||
// optimize the gzip compression for this alphabet.
|
||||
let urlAlphabet =
|
||||
'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'
|
||||
|
||||
let customAlphabet = (alphabet, size) => {
|
||||
return () => {
|
||||
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||||
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||
return (size = defaultSize) => {
|
||||
let id = ''
|
||||
// A compact alternative for `for (var i = 0; i < step; i++)`.
|
||||
let i = size
|
||||
while (i--) {
|
||||
// `| 0` is more compact and faster than `Math.floor()`.
|
||||
id += alphabet[(Math.random() * alphabet.length) | 0]
|
||||
}
|
||||
return id
|
||||
}
|
||||
}
|
||||
|
||||
let nanoid = (size = 21) => {
|
||||
let id = ''
|
||||
// A compact alternative for `for (var i = 0; i < step; i++)`.
|
||||
let i = size
|
||||
while (i--) {
|
||||
// `| 0` is more compact and faster than `Math.floor()`.
|
||||
id += urlAlphabet[(Math.random() * 64) | 0]
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
module.exports = { nanoid, customAlphabet }
|
||||
|
||||
+8
-5
@@ -10,16 +10,16 @@
|
||||
* @param size Size of the ID. The default size is 21.
|
||||
* @returns A random string.
|
||||
*/
|
||||
export function nanoid (size?: number): string
|
||||
export function nanoid(size?: number): string
|
||||
|
||||
/**
|
||||
* Generate URL-friendly unique ID based on the custom alphabet.
|
||||
* Generate a unique ID based on a custom alphabet.
|
||||
* This method uses the non-secure predictable random generator
|
||||
* with bigger collision probability.
|
||||
*
|
||||
* @param alphabet Alphabet used to generate the ID.
|
||||
* @param size Size of the ID.
|
||||
* @returns A random string.
|
||||
* @param defaultSize Size of the ID. The default size is 21.
|
||||
* @returns A random string generator.
|
||||
*
|
||||
* ```js
|
||||
* import { customAlphabet } from 'nanoid/non-secure'
|
||||
@@ -27,4 +27,7 @@ export function nanoid (size?: number): string
|
||||
* model.id = //=> "8ё56а"
|
||||
* ```
|
||||
*/
|
||||
export function customAlphabet (alphabet: string, size: number): () => string
|
||||
export function customAlphabet(
|
||||
alphabet: string,
|
||||
defaultSize?: number
|
||||
): (size?: number) => string
|
||||
|
||||
+3
-12
@@ -1,30 +1,21 @@
|
||||
// This alphabet uses `A-Za-z0-9_-` symbols. The genetic algorithm helped
|
||||
// optimize the gzip compression for this alphabet.
|
||||
let urlAlphabet =
|
||||
'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'
|
||||
|
||||
let customAlphabet = (alphabet, size) => {
|
||||
return () => {
|
||||
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||||
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||
return (size = defaultSize) => {
|
||||
let id = ''
|
||||
// A compact alternative for `for (var i = 0; i < step; i++)`.
|
||||
let i = size
|
||||
while (i--) {
|
||||
// `| 0` is more compact and faster than `Math.floor()`.
|
||||
id += alphabet[(Math.random() * alphabet.length) | 0]
|
||||
}
|
||||
return id
|
||||
}
|
||||
}
|
||||
|
||||
let nanoid = (size = 21) => {
|
||||
let id = ''
|
||||
// A compact alternative for `for (var i = 0; i < step; i++)`.
|
||||
let i = size
|
||||
while (i--) {
|
||||
// `| 0` is more compact and faster than `Math.floor()`.
|
||||
id += urlAlphabet[(Math.random() * 64) | 0]
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
export { nanoid, customAlphabet }
|
||||
|
||||
Reference in New Issue
Block a user