CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
index.d.ts57 linesDownload Raw Back to async
1/**2 * Generate secure URL-friendly unique ID. The non-blocking version.3 *4 * By default, the ID will have 21 symbols to have a collision probability5 * similar to UUID v4.6 *7 * ```js8 * import { nanoid } from 'nanoid/async'9 * nanoid().then(id => {10 *   model.id = id11 * })12 * ```13 *14 * @param size Size of the ID. The default size is 21.15 * @returns A promise with a random string.16 */17export function nanoid(size?: number): Promise<string>18 19/**20 * A low-level function.21 * Generate secure unique ID with custom alphabet. The non-blocking version.22 *23 * Alphabet must contain 256 symbols or less. Otherwise, the generator24 * will not be secure.25 *26 * @param alphabet Alphabet used to generate the ID.27 * @param defaultSize Size of the ID. The default size is 21.28 * @returns A function that returns a promise with a random string.29 *30 * ```js31 * import { customAlphabet } from 'nanoid/async'32 * const nanoid = customAlphabet('0123456789абвгдеё', 5)33 * nanoid().then(id => {34 *   model.id = id //=> "8ё56а"35 * })36 * ```37 */38export function customAlphabet(39  alphabet: string,40  defaultSize?: number41): (size?: number) => Promise<string>42 43/**44 * Generate an array of random bytes collected from hardware noise.45 *46 * ```js47 * import { random } from 'nanoid/async'48 * random(5).then(bytes => {49 *   bytes //=> [10, 67, 212, 67, 89]50 * })51 * ```52 *53 * @param bytes Size of the array.54 * @returns A promise with a random bytes array.55 */56export function random(bytes: number): Promise<Uint8Array>57