CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
index.d.ts92 linesDownload Raw Back to nanoid
1/**2 * Generate secure URL-friendly unique ID.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'9 * model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"10 * ```11 *12 * @param size Size of the ID. The default size is 21.13 * @returns A random string.14 */15export function nanoid(size?: number): string16 17/**18 * Generate secure unique ID with custom alphabet.19 *20 * Alphabet must contain 256 symbols or less. Otherwise, the generator21 * will not be secure.22 *23 * @param alphabet Alphabet used to generate the ID.24 * @param defaultSize Size of the ID. The default size is 21.25 * @returns A random string generator.26 *27 * ```js28 * const { customAlphabet } = require('nanoid')29 * const nanoid = customAlphabet('0123456789абвгдеё', 5)30 * nanoid() //=> "8ё56а"31 * ```32 */33export function customAlphabet(34  alphabet: string,35  defaultSize?: number36): (size?: number) => string37 38/**39 * Generate unique ID with custom random generator and alphabet.40 *41 * Alphabet must contain 256 symbols or less. Otherwise, the generator42 * will not be secure.43 *44 * ```js45 * import { customRandom } from 'nanoid/format'46 *47 * const nanoid = customRandom('abcdef', 5, size => {48 *   const random = []49 *   for (let i = 0; i < size; i++) {50 *     random.push(randomByte())51 *   }52 *   return random53 * })54 *55 * nanoid() //=> "fbaef"56 * ```57 *58 * @param alphabet Alphabet used to generate a random string.59 * @param size Size of the random string.60 * @param random A random bytes generator.61 * @returns A random string generator.62 */63export function customRandom(64  alphabet: string,65  size: number,66  random: (bytes: number) => Uint8Array67): () => string68 69/**70 * URL safe symbols.71 *72 * ```js73 * import { urlAlphabet } from 'nanoid'74 * const nanoid = customAlphabet(urlAlphabet, 10)75 * nanoid() //=> "Uakgb_J5m9"76 * ```77 */78export const urlAlphabet: string79 80/**81 * Generate an array of random bytes collected from hardware noise.82 *83 * ```js84 * import { customRandom, random } from 'nanoid'85 * const nanoid = customRandom("abcdef", 5, random)86 * ```87 *88 * @param bytes Size of the array.89 * @returns An array of random bytes.90 */91export function random(bytes: number): Uint8Array92