Skip to content
Myr

index.d.ts

This file

Path

index.d.ts

106 lines · 2.8 KiB · TypeScript

Last changed by

docs: fix custom generator JSDoc examples (#610)Alexbefore adoptionbb68abc

History of this file

Take it

The walk stopped after 200 commits: lines older than cdc3edc point at it.

Update size limitAndrey Sitnikbefore adoptioncdc3edc

line 1why, one step back
1/**

Move module docs to .d.tsAndrey Sitnikbefore adoptiond4fb377

lines 2–13why, one step back
2 * A tiny, secure, URL-friendly, unique string ID generator for JavaScript
3 * with hardware random generator.4 *5 * ```js6 * import { nanoid } from 'nanoid'7 * model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"8 * ```9 *10 * @module11 */1213/**

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 14–24why, one step back
14 * Generate secure URL-friendly unique ID.
15 *16 * By default, the ID will have 21 symbols to have a collision probability17 * similar to UUID v4.18 *19 * ```js20 * import { nanoid } from 'nanoid'21 * model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"22 * ```23 *24 * @param size Size of the ID. The default size is 21.

Add opaque type for non-secure generatorAndrey Sitnikbefore adoption1e24963

line 25why, one step back
25 * @typeparam Type The ID type to replace `string` with some opaque type.

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 26–27why, one step back
26 * @returns A random string.
27 */

Make functions generic so it can cast to opaque (branded) types (#521)Sasha Kossbefore adoptionea64dc7

line 28why, one step back
28export function nanoid<Type extends string>(size?: number): Type

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 29–37why, one step back
29
30/**31 * Generate secure unique ID with custom alphabet.32 *33 * Alphabet must contain 256 symbols or less. Otherwise, the generator34 * will not be secure.35 *36 * @param alphabet Alphabet used to generate the ID.37 * @param defaultSize Size of the ID. The default size is 21.

Add opaque type for non-secure generatorAndrey Sitnikbefore adoption1e24963

line 38why, one step back
38 * @typeparam Type The ID type to replace `string` with some opaque type.

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 39–41why, one step back
39 * @returns A random string generator.
40 *41 * ```js

Fix incorrect import paths in JSDoc examples (#567)Mahmoud Hamdybefore adoptiona1873f7

line 42why, one step back
42 * import { customAlphabet } from 'nanoid'

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 43–46why, one step back
43 * const nanoid = customAlphabet('0123456789абвгдеё', 5)
44 * nanoid() //=> "8ё56а"45 * ```46 */

Make functions generic so it can cast to opaque (branded) types (#521)Sasha Kossbefore adoptionea64dc7

line 47why, one step back
47export function customAlphabet<Type extends string>(

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 48–49why, one step back
48 alphabet: string,
49 defaultSize?: number

Make functions generic so it can cast to opaque (branded) types (#521)Sasha Kossbefore adoptionea64dc7

line 50why, one step back
50): (size?: number) => Type

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 51–58why, one step back
51
52/**53 * Generate unique ID with custom random generator and alphabet.54 *55 * Alphabet must contain 256 symbols or less. Otherwise, the generator56 * will not be secure.57 *58 * ```js

Fix incorrect import paths in JSDoc examples (#567)Mahmoud Hamdybefore adoptiona1873f7

line 59why, one step back
59 * import { customRandom } from 'nanoid'

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 60–61why, one step back
60 *
61 * const nanoid = customRandom('abcdef', 5, size => {

docs: fix custom generator JSDoc examples (#610)Alexbefore adoptionbb68abc

line 62why, one step back
62 * const random = new Uint8Array(size)

Update size limitAndrey Sitnikbefore adoptioncdc3edc

line 63why, one step back
63 * for (let i = 0; i < size; i++) {

docs: fix custom generator JSDoc examples (#610)Alexbefore adoptionbb68abc

line 64why, one step back
64 * random[i] = randomByte()

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 65–72why, one step back
65 * }
66 * return random67 * })68 *69 * nanoid() //=> "fbaef"70 * ```71 *72 * @param alphabet Alphabet used to generate a random string.

Port amazing nope-id optimizations (#602)Andrey Sitnikbefore adoptionb1bb75f

line 73why, one step back
73 * @param defaultSize Size of the random string.

Update size limitAndrey Sitnikbefore adoptioncdc3edc

line 74why, one step back
74 * @param random A random bytes generator.

Add opaque type for non-secure generatorAndrey Sitnikbefore adoption1e24963

line 75why, one step back
75 * @typeparam Type The ID type to replace `string` with some opaque type.

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 76–77why, one step back
76 * @returns A random string generator.
77 */

Make functions generic so it can cast to opaque (branded) types (#521)Sasha Kossbefore adoptionea64dc7

line 78why, one step back
78export function customRandom<Type extends string>(

Update size limitAndrey Sitnikbefore adoptioncdc3edc

line 79why, one step back
79 alphabet: string,

Port amazing nope-id optimizations (#602)Andrey Sitnikbefore adoptionb1bb75f

line 80why, one step back
80 defaultSize: number,

Update size limitAndrey Sitnikbefore adoptioncdc3edc

line 81why, one step back
81 random: (bytes: number) => Uint8Array

Change customRandom signature to accept optional size (#551)Olivier Guimbalbefore adoption787a511

line 82why, one step back
82): (size?: number) => Type

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 83–87why, one step back
83
84/**85 * URL safe symbols.86 *87 * ```js

docs: fix custom generator JSDoc examples (#610)Alexbefore adoptionbb68abc

line 88why, one step back
88 * import { customAlphabet, urlAlphabet } from 'nanoid'

Update size limitAndrey Sitnikbefore adoptioncdc3edc

lines 89–106why, one step back
89 * const nanoid = customAlphabet(urlAlphabet, 10)
90 * nanoid() //=> "Uakgb_J5m9"91 * ```92 */93export const urlAlphabet: string9495/**96 * Generate an array of random bytes collected from hardware noise.97 *98 * ```js99 * import { customRandom, random } from 'nanoid'100 * const nanoid = customRandom("abcdef", 5, random)101 * ```102 *103 * @param bytes Size of the array.104 * @returns An array of random bytes.105 */106export function random(bytes: number): Uint8Array