nanoid 5.1.0 → 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,7 +10,7 @@
10
10
  * ```
11
11
  *
12
12
  * @param size Size of the ID. The default size is 21.
13
- * @typeparam Type The type of the generated ID.
13
+ * @typeparam Type The ID type to replace `string` with some opaque type.
14
14
  * @returns A random string.
15
15
  */
16
16
  export function nanoid<Type extends string>(size?: number): Type
@@ -23,7 +23,7 @@ export function nanoid<Type extends string>(size?: number): Type
23
23
  *
24
24
  * @param alphabet Alphabet used to generate the ID.
25
25
  * @param defaultSize Size of the ID. The default size is 21.
26
- * @typeparam Type The type of the generated ID.
26
+ * @typeparam Type The ID type to replace `string` with some opaque type.
27
27
  * @returns A random string generator.
28
28
  *
29
29
  * ```js
@@ -60,7 +60,7 @@ export function customAlphabet<Type extends string>(
60
60
  * @param alphabet Alphabet used to generate a random string.
61
61
  * @param size Size of the random string.
62
62
  * @param random A random bytes generator.
63
- * @typeparam Type The type of the generated ID.
63
+ * @typeparam Type The ID type to replace `string` with some opaque type.
64
64
  * @returns A random string generator.
65
65
  */
66
66
  export function customRandom<Type extends string>(
@@ -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.1.0",
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",