nanoid 3.3.0 → 3.3.3
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.cjs +8 -37
- package/index.browser.js +8 -37
- package/nanoid.js +1 -1
- package/package.json +7 -11
- package/index.dev.js +0 -63
- package/index.prod.js +0 -63
package/index.browser.cjs
CHANGED
@@ -1,30 +1,4 @@
|
|
1
1
|
let { urlAlphabet } = require('./url-alphabet/index.cjs')
|
2
|
-
if (process.env.NODE_ENV !== 'production') {
|
3
|
-
if (
|
4
|
-
typeof navigator !== 'undefined' &&
|
5
|
-
navigator.product === 'ReactNative' &&
|
6
|
-
typeof crypto === 'undefined'
|
7
|
-
) {
|
8
|
-
throw new Error(
|
9
|
-
'React Native does not have a built-in secure random generator. ' +
|
10
|
-
'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +
|
11
|
-
'For secure IDs, import `react-native-get-random-values` ' +
|
12
|
-
'before Nano ID.'
|
13
|
-
)
|
14
|
-
}
|
15
|
-
if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {
|
16
|
-
throw new Error(
|
17
|
-
'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +
|
18
|
-
' before importing Nano ID to fix IE 11 support'
|
19
|
-
)
|
20
|
-
}
|
21
|
-
if (typeof crypto === 'undefined') {
|
22
|
-
throw new Error(
|
23
|
-
'Your browser does not have secure random generator. ' +
|
24
|
-
'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'
|
25
|
-
)
|
26
|
-
}
|
27
|
-
}
|
28
2
|
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
29
3
|
let customRandom = (alphabet, defaultSize, getRandom) => {
|
30
4
|
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
@@ -43,21 +17,18 @@ let customRandom = (alphabet, defaultSize, getRandom) => {
|
|
43
17
|
}
|
44
18
|
let customAlphabet = (alphabet, size = 21) =>
|
45
19
|
customRandom(alphabet, size, random)
|
46
|
-
let nanoid = (size = 21) =>
|
47
|
-
|
48
|
-
|
49
|
-
while (size--) {
|
50
|
-
let byte = bytes[size] & 63
|
20
|
+
let nanoid = (size = 21) =>
|
21
|
+
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
22
|
+
byte &= 63
|
51
23
|
if (byte < 36) {
|
52
24
|
id += byte.toString(36)
|
53
25
|
} else if (byte < 62) {
|
54
26
|
id += (byte - 26).toString(36).toUpperCase()
|
55
|
-
} else if (byte
|
56
|
-
id += '_'
|
57
|
-
} else {
|
27
|
+
} else if (byte > 62) {
|
58
28
|
id += '-'
|
29
|
+
} else {
|
30
|
+
id += '_'
|
59
31
|
}
|
60
|
-
|
61
|
-
|
62
|
-
}
|
32
|
+
return id
|
33
|
+
}, '')
|
63
34
|
module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
package/index.browser.js
CHANGED
@@ -1,30 +1,4 @@
|
|
1
1
|
import { urlAlphabet } from './url-alphabet/index.js'
|
2
|
-
if (process.env.NODE_ENV !== 'production') {
|
3
|
-
if (
|
4
|
-
typeof navigator !== 'undefined' &&
|
5
|
-
navigator.product === 'ReactNative' &&
|
6
|
-
typeof crypto === 'undefined'
|
7
|
-
) {
|
8
|
-
throw new Error(
|
9
|
-
'React Native does not have a built-in secure random generator. ' +
|
10
|
-
'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +
|
11
|
-
'For secure IDs, import `react-native-get-random-values` ' +
|
12
|
-
'before Nano ID.'
|
13
|
-
)
|
14
|
-
}
|
15
|
-
if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {
|
16
|
-
throw new Error(
|
17
|
-
'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +
|
18
|
-
' before importing Nano ID to fix IE 11 support'
|
19
|
-
)
|
20
|
-
}
|
21
|
-
if (typeof crypto === 'undefined') {
|
22
|
-
throw new Error(
|
23
|
-
'Your browser does not have secure random generator. ' +
|
24
|
-
'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'
|
25
|
-
)
|
26
|
-
}
|
27
|
-
}
|
28
2
|
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
29
3
|
let customRandom = (alphabet, defaultSize, getRandom) => {
|
30
4
|
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
@@ -43,21 +17,18 @@ let customRandom = (alphabet, defaultSize, getRandom) => {
|
|
43
17
|
}
|
44
18
|
let customAlphabet = (alphabet, size = 21) =>
|
45
19
|
customRandom(alphabet, size, random)
|
46
|
-
let nanoid = (size = 21) =>
|
47
|
-
|
48
|
-
|
49
|
-
while (size--) {
|
50
|
-
let byte = bytes[size] & 63
|
20
|
+
let nanoid = (size = 21) =>
|
21
|
+
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
22
|
+
byte &= 63
|
51
23
|
if (byte < 36) {
|
52
24
|
id += byte.toString(36)
|
53
25
|
} else if (byte < 62) {
|
54
26
|
id += (byte - 26).toString(36).toUpperCase()
|
55
|
-
} else if (byte
|
56
|
-
id += '_'
|
57
|
-
} else {
|
27
|
+
} else if (byte > 62) {
|
58
28
|
id += '-'
|
29
|
+
} else {
|
30
|
+
id += '_'
|
59
31
|
}
|
60
|
-
|
61
|
-
|
62
|
-
}
|
32
|
+
return id
|
33
|
+
}, '')
|
63
34
|
export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
package/nanoid.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export let nanoid=(t=21)=>
|
1
|
+
export let nanoid=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce(((t,e)=>t+=(e&=63)<36?e.toString(36):e<62?(e-26).toString(36).toUpperCase():e<63?"_":"-"),"");
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "nanoid",
|
3
|
-
"version": "3.3.
|
4
|
-
"description": "A tiny (
|
3
|
+
"version": "3.3.3",
|
4
|
+
"description": "A tiny (116 bytes), secure URL-friendly unique string ID generator",
|
5
5
|
"keywords": [
|
6
6
|
"uuid",
|
7
7
|
"random",
|
@@ -29,16 +29,13 @@
|
|
29
29
|
"module": "index.js",
|
30
30
|
"exports": {
|
31
31
|
".": {
|
32
|
-
"
|
33
|
-
|
34
|
-
"production": "./index.prod.js",
|
35
|
-
"default": "./index.prod.js"
|
36
|
-
},
|
32
|
+
"types": "./index.d.ts",
|
33
|
+
"browser": "./index.browser.js",
|
37
34
|
"require": "./index.cjs",
|
38
35
|
"import": "./index.js",
|
39
|
-
"default": "./index.js"
|
40
|
-
"types": "./index.d.ts"
|
36
|
+
"default": "./index.js"
|
41
37
|
},
|
38
|
+
"./index.d.ts": "./index.d.ts",
|
42
39
|
"./package.json": "./package.json",
|
43
40
|
"./async/package.json": "./async/package.json",
|
44
41
|
"./async": {
|
@@ -58,7 +55,6 @@
|
|
58
55
|
"require": "./url-alphabet/index.cjs",
|
59
56
|
"import": "./url-alphabet/index.js",
|
60
57
|
"default": "./url-alphabet/index.js"
|
61
|
-
}
|
62
|
-
"./index.d.ts": "./index.d.ts"
|
58
|
+
}
|
63
59
|
}
|
64
60
|
}
|
package/index.dev.js
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
import { urlAlphabet } from './url-alphabet/index.js'
|
2
|
-
if (true) {
|
3
|
-
if (
|
4
|
-
typeof navigator !== 'undefined' &&
|
5
|
-
navigator.product === 'ReactNative' &&
|
6
|
-
typeof crypto === 'undefined'
|
7
|
-
) {
|
8
|
-
throw new Error(
|
9
|
-
'React Native does not have a built-in secure random generator. ' +
|
10
|
-
'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +
|
11
|
-
'For secure IDs, import `react-native-get-random-values` ' +
|
12
|
-
'before Nano ID.'
|
13
|
-
)
|
14
|
-
}
|
15
|
-
if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {
|
16
|
-
throw new Error(
|
17
|
-
'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +
|
18
|
-
' before importing Nano ID to fix IE 11 support'
|
19
|
-
)
|
20
|
-
}
|
21
|
-
if (typeof crypto === 'undefined') {
|
22
|
-
throw new Error(
|
23
|
-
'Your browser does not have secure random generator. ' +
|
24
|
-
'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'
|
25
|
-
)
|
26
|
-
}
|
27
|
-
}
|
28
|
-
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
29
|
-
let customRandom = (alphabet, defaultSize, getRandom) => {
|
30
|
-
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
31
|
-
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
32
|
-
return (size = defaultSize) => {
|
33
|
-
let id = ''
|
34
|
-
while (true) {
|
35
|
-
let bytes = getRandom(step)
|
36
|
-
let j = step
|
37
|
-
while (j--) {
|
38
|
-
id += alphabet[bytes[j] & mask] || ''
|
39
|
-
if (id.length === size) return id
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
let customAlphabet = (alphabet, size = 21) =>
|
45
|
-
customRandom(alphabet, size, random)
|
46
|
-
let nanoid = (size = 21) => {
|
47
|
-
let id = ''
|
48
|
-
let bytes = crypto.getRandomValues(new Uint8Array(size))
|
49
|
-
while (size--) {
|
50
|
-
let byte = bytes[size] & 63
|
51
|
-
if (byte < 36) {
|
52
|
-
id += byte.toString(36)
|
53
|
-
} else if (byte < 62) {
|
54
|
-
id += (byte - 26).toString(36).toUpperCase()
|
55
|
-
} else if (byte < 63) {
|
56
|
-
id += '_'
|
57
|
-
} else {
|
58
|
-
id += '-'
|
59
|
-
}
|
60
|
-
}
|
61
|
-
return id
|
62
|
-
}
|
63
|
-
export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
package/index.prod.js
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
import { urlAlphabet } from './url-alphabet/index.js'
|
2
|
-
if (false) {
|
3
|
-
if (
|
4
|
-
typeof navigator !== 'undefined' &&
|
5
|
-
navigator.product === 'ReactNative' &&
|
6
|
-
typeof crypto === 'undefined'
|
7
|
-
) {
|
8
|
-
throw new Error(
|
9
|
-
'React Native does not have a built-in secure random generator. ' +
|
10
|
-
'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +
|
11
|
-
'For secure IDs, import `react-native-get-random-values` ' +
|
12
|
-
'before Nano ID.'
|
13
|
-
)
|
14
|
-
}
|
15
|
-
if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {
|
16
|
-
throw new Error(
|
17
|
-
'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +
|
18
|
-
' before importing Nano ID to fix IE 11 support'
|
19
|
-
)
|
20
|
-
}
|
21
|
-
if (typeof crypto === 'undefined') {
|
22
|
-
throw new Error(
|
23
|
-
'Your browser does not have secure random generator. ' +
|
24
|
-
'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'
|
25
|
-
)
|
26
|
-
}
|
27
|
-
}
|
28
|
-
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
29
|
-
let customRandom = (alphabet, defaultSize, getRandom) => {
|
30
|
-
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
31
|
-
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
32
|
-
return (size = defaultSize) => {
|
33
|
-
let id = ''
|
34
|
-
while (true) {
|
35
|
-
let bytes = getRandom(step)
|
36
|
-
let j = step
|
37
|
-
while (j--) {
|
38
|
-
id += alphabet[bytes[j] & mask] || ''
|
39
|
-
if (id.length === size) return id
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
let customAlphabet = (alphabet, size = 21) =>
|
45
|
-
customRandom(alphabet, size, random)
|
46
|
-
let nanoid = (size = 21) => {
|
47
|
-
let id = ''
|
48
|
-
let bytes = crypto.getRandomValues(new Uint8Array(size))
|
49
|
-
while (size--) {
|
50
|
-
let byte = bytes[size] & 63
|
51
|
-
if (byte < 36) {
|
52
|
-
id += byte.toString(36)
|
53
|
-
} else if (byte < 62) {
|
54
|
-
id += (byte - 26).toString(36).toUpperCase()
|
55
|
-
} else if (byte < 63) {
|
56
|
-
id += '_'
|
57
|
-
} else {
|
58
|
-
id += '-'
|
59
|
-
}
|
60
|
-
}
|
61
|
-
return id
|
62
|
-
}
|
63
|
-
export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|