nanoid 3.3.6 → 3.3.7
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/README.md +1 -1
- package/index.d.cts +91 -0
- package/package.json +33 -11
package/README.md
CHANGED
package/index.d.cts
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
/**
|
2
|
+
* Generate secure URL-friendly unique ID.
|
3
|
+
*
|
4
|
+
* By default, the ID will have 21 symbols to have a collision probability
|
5
|
+
* similar to UUID v4.
|
6
|
+
*
|
7
|
+
* ```js
|
8
|
+
* 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
|
+
*/
|
15
|
+
export function nanoid(size?: number): string
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Generate secure unique ID with custom alphabet.
|
19
|
+
*
|
20
|
+
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
21
|
+
* 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
|
+
* ```js
|
28
|
+
* const { customAlphabet } = require('nanoid')
|
29
|
+
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
30
|
+
* nanoid() //=> "8ё56а"
|
31
|
+
* ```
|
32
|
+
*/
|
33
|
+
export function customAlphabet(
|
34
|
+
alphabet: string,
|
35
|
+
defaultSize?: number
|
36
|
+
): (size?: number) => string
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Generate unique ID with custom random generator and alphabet.
|
40
|
+
*
|
41
|
+
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
42
|
+
* will not be secure.
|
43
|
+
*
|
44
|
+
* ```js
|
45
|
+
* 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 random
|
53
|
+
* })
|
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
|
+
*/
|
63
|
+
export function customRandom(
|
64
|
+
alphabet: string,
|
65
|
+
size: number,
|
66
|
+
random: (bytes: number) => Uint8Array
|
67
|
+
): () => string
|
68
|
+
|
69
|
+
/**
|
70
|
+
* URL safe symbols.
|
71
|
+
*
|
72
|
+
* ```js
|
73
|
+
* import { urlAlphabet } from 'nanoid'
|
74
|
+
* const nanoid = customAlphabet(urlAlphabet, 10)
|
75
|
+
* nanoid() //=> "Uakgb_J5m9"
|
76
|
+
* ```
|
77
|
+
*/
|
78
|
+
export const urlAlphabet: string
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Generate an array of random bytes collected from hardware noise.
|
82
|
+
*
|
83
|
+
* ```js
|
84
|
+
* 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
|
+
*/
|
91
|
+
export function random(bytes: number): Uint8Array
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nanoid",
|
3
|
-
"version": "3.3.
|
3
|
+
"version": "3.3.7",
|
4
4
|
"description": "A tiny (116 bytes), secure URL-friendly unique string ID generator",
|
5
5
|
"keywords": [
|
6
6
|
"uuid",
|
@@ -35,31 +35,53 @@
|
|
35
35
|
"module": "index.js",
|
36
36
|
"exports": {
|
37
37
|
".": {
|
38
|
-
"types": "./index.d.ts",
|
39
38
|
"browser": "./index.browser.js",
|
40
|
-
"require":
|
41
|
-
|
39
|
+
"require": {
|
40
|
+
"types": "./index.d.cts",
|
41
|
+
"default": "./index.cjs"
|
42
|
+
},
|
43
|
+
"import": {
|
44
|
+
"types": "./index.d.ts",
|
45
|
+
"default": "./index.js"
|
46
|
+
},
|
42
47
|
"default": "./index.js"
|
43
48
|
},
|
44
|
-
"./index.d.ts": "./index.d.ts",
|
45
49
|
"./package.json": "./package.json",
|
46
50
|
"./async/package.json": "./async/package.json",
|
47
51
|
"./async": {
|
48
52
|
"browser": "./async/index.browser.js",
|
49
|
-
"require":
|
50
|
-
|
53
|
+
"require": {
|
54
|
+
"types": "./index.d.cts",
|
55
|
+
"default": "./async/index.cjs"
|
56
|
+
},
|
57
|
+
"import": {
|
58
|
+
"types": "./index.d.ts",
|
59
|
+
"default": "./async/index.js"
|
60
|
+
},
|
51
61
|
"default": "./async/index.js"
|
52
62
|
},
|
53
63
|
"./non-secure/package.json": "./non-secure/package.json",
|
54
64
|
"./non-secure": {
|
55
|
-
"require":
|
56
|
-
|
65
|
+
"require": {
|
66
|
+
"types": "./index.d.cts",
|
67
|
+
"default": "./non-secure/index.cjs"
|
68
|
+
},
|
69
|
+
"import": {
|
70
|
+
"types": "./index.d.ts",
|
71
|
+
"default": "./non-secure/index.js"
|
72
|
+
},
|
57
73
|
"default": "./non-secure/index.js"
|
58
74
|
},
|
59
75
|
"./url-alphabet/package.json": "./url-alphabet/package.json",
|
60
76
|
"./url-alphabet": {
|
61
|
-
"require":
|
62
|
-
|
77
|
+
"require": {
|
78
|
+
"types": "./index.d.cts",
|
79
|
+
"default": "./url-alphabet/index.cjs"
|
80
|
+
},
|
81
|
+
"import": {
|
82
|
+
"types": "./index.d.ts",
|
83
|
+
"default": "./url-alphabet/index.js"
|
84
|
+
},
|
63
85
|
"default": "./url-alphabet/index.js"
|
64
86
|
}
|
65
87
|
}
|