nanoid 5.0.9 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.browser.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* @ts-self-types="./index.d.ts" */
1
2
  import { urlAlphabet as scopedUrlAlphabet } from './url-alphabet/index.js'
2
3
  export { urlAlphabet } from './url-alphabet/index.js'
3
4
  export let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
package/index.d.ts CHANGED
@@ -10,9 +10,10 @@
10
10
  * ```
11
11
  *
12
12
  * @param size Size of the ID. The default size is 21.
13
+ * @typeparam Type The ID type to replace `string` with some opaque type.
13
14
  * @returns A random string.
14
15
  */
15
- export function nanoid(size?: number): string
16
+ export function nanoid<Type extends string>(size?: number): Type
16
17
 
17
18
  /**
18
19
  * Generate secure unique ID with custom alphabet.
@@ -22,6 +23,7 @@ export function nanoid(size?: number): string
22
23
  *
23
24
  * @param alphabet Alphabet used to generate the ID.
24
25
  * @param defaultSize Size of the ID. The default size is 21.
26
+ * @typeparam Type The ID type to replace `string` with some opaque type.
25
27
  * @returns A random string generator.
26
28
  *
27
29
  * ```js
@@ -30,10 +32,10 @@ export function nanoid(size?: number): string
30
32
  * nanoid() //=> "8ё56а"
31
33
  * ```
32
34
  */
33
- export function customAlphabet(
35
+ export function customAlphabet<Type extends string>(
34
36
  alphabet: string,
35
37
  defaultSize?: number
36
- ): (size?: number) => string
38
+ ): (size?: number) => Type
37
39
 
38
40
  /**
39
41
  * Generate unique ID with custom random generator and alphabet.
@@ -58,13 +60,14 @@ export function customAlphabet(
58
60
  * @param alphabet Alphabet used to generate a random string.
59
61
  * @param size Size of the random string.
60
62
  * @param random A random bytes generator.
63
+ * @typeparam Type The ID type to replace `string` with some opaque type.
61
64
  * @returns A random string generator.
62
65
  */
63
- export function customRandom(
66
+ export function customRandom<Type extends string>(
64
67
  alphabet: string,
65
68
  size: number,
66
69
  random: (bytes: number) => Uint8Array
67
- ): () => string
70
+ ): () => Type
68
71
 
69
72
  /**
70
73
  * URL safe symbols.
@@ -8,9 +8,10 @@
8
8
  * ```
9
9
  *
10
10
  * @param size Size of the ID. The default size is 21.
11
+ * @typeparam Type The ID type to replace `string` with some opaque type.
11
12
  * @returns A random string.
12
13
  */
13
- export function nanoid(size?: number): string
14
+ export function nanoid<Type extends string>(size?: number): Type
14
15
 
15
16
  /**
16
17
  * Generate a unique ID based on a custom alphabet.
@@ -19,15 +20,16 @@ export function nanoid(size?: number): string
19
20
  *
20
21
  * @param alphabet Alphabet used to generate the ID.
21
22
  * @param defaultSize Size of the ID. The default size is 21.
23
+ * @typeparam Type The ID type to replace `string` with some opaque type.
22
24
  * @returns A random string generator.
23
25
  *
24
26
  * ```js
25
27
  * import { customAlphabet } from 'nanoid/non-secure'
26
28
  * const nanoid = customAlphabet('0123456789абвгдеё', 5)
27
- * model.id = //=> "8ё56а"
29
+ * model.id = nanoid() //=> "8ё56а"
28
30
  * ```
29
31
  */
30
- export function customAlphabet(
32
+ export function customAlphabet<Type extends string>(
31
33
  alphabet: string,
32
34
  defaultSize?: number
33
- ): (size?: number) => string
35
+ ): (size?: number) => Type
@@ -1,3 +1,16 @@
1
+ /* @ts-self-types="./index.d.ts" */
2
+ /**
3
+ * By default, Nano ID uses hardware random bytes generation for security
4
+ * and low collision probability. If you are not so concerned with security,
5
+ * you can use it for environments without hardware random generators.
6
+ *
7
+ * ```js
8
+ * import { nanoid } from 'nanoid/non-secure'
9
+ * const id = nanoid()
10
+ * ```
11
+ *
12
+ * @module
13
+ */
1
14
  let urlAlphabet =
2
15
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
3
16
  export let customAlphabet = (alphabet, defaultSize = 21) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoid",
3
- "version": "5.0.9",
3
+ "version": "5.1.1",
4
4
  "description": "A tiny (118 bytes), secure URL-friendly unique string ID generator",
5
5
  "keywords": [
6
6
  "uuid",