nanoid 3.1.27 → 3.1.31

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.prod.js ADDED
@@ -0,0 +1,62 @@
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, size, getRandom) => {
30
+ let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
31
+ let step = -~((1.6 * mask * size) / alphabet.length)
32
+ return () => {
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) => customRandom(alphabet, size, random)
45
+ let nanoid = (size = 21) => {
46
+ let id = ''
47
+ let bytes = crypto.getRandomValues(new Uint8Array(size))
48
+ while (size--) {
49
+ let byte = bytes[size] & 63
50
+ if (byte < 36) {
51
+ id += byte.toString(36)
52
+ } else if (byte < 62) {
53
+ id += (byte - 26).toString(36).toUpperCase()
54
+ } else if (byte < 63) {
55
+ id += '_'
56
+ } else {
57
+ id += '-'
58
+ }
59
+ }
60
+ return id
61
+ }
62
+ export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
@@ -0,0 +1,21 @@
1
+ let urlAlphabet =
2
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
3
+ let customAlphabet = (alphabet, size) => {
4
+ return () => {
5
+ let id = ''
6
+ let i = size
7
+ while (i--) {
8
+ id += alphabet[(Math.random() * alphabet.length) | 0]
9
+ }
10
+ return id
11
+ }
12
+ }
13
+ let nanoid = (size = 21) => {
14
+ let id = ''
15
+ let i = size
16
+ while (i--) {
17
+ id += urlAlphabet[(Math.random() * 64) | 0]
18
+ }
19
+ return id
20
+ }
21
+ module.exports = { nanoid, customAlphabet }
@@ -1,30 +1,21 @@
1
- // This alphabet uses `A-Za-z0-9_-` symbols. The genetic algorithm helped
2
- // optimize the gzip compression for this alphabet.
3
1
  let urlAlphabet =
4
- 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'
5
-
2
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
6
3
  let customAlphabet = (alphabet, size) => {
7
4
  return () => {
8
5
  let id = ''
9
- // A compact alternative for `for (var i = 0; i < step; i++)`.
10
6
  let i = size
11
7
  while (i--) {
12
- // `| 0` is more compact and faster than `Math.floor()`.
13
8
  id += alphabet[(Math.random() * alphabet.length) | 0]
14
9
  }
15
10
  return id
16
11
  }
17
12
  }
18
-
19
13
  let nanoid = (size = 21) => {
20
14
  let id = ''
21
- // A compact alternative for `for (var i = 0; i < step; i++)`.
22
15
  let i = size
23
16
  while (i--) {
24
- // `| 0` is more compact and faster than `Math.floor()`.
25
17
  id += urlAlphabet[(Math.random() * 64) | 0]
26
18
  }
27
19
  return id
28
20
  }
29
-
30
- module.exports = { nanoid, customAlphabet }
21
+ export { nanoid, customAlphabet }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "main": "index.cjs",
4
+ "module": "index.js",
5
+ "react-native": "index.js"
6
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nanoid",
3
- "version": "3.1.27",
4
- "description": "A tiny (108 bytes), secure URL-friendly unique string ID generator",
3
+ "version": "3.1.31",
4
+ "description": "A tiny (130 bytes), secure URL-friendly unique string ID generator",
5
5
  "keywords": [
6
6
  "uuid",
7
7
  "random",
@@ -17,12 +17,48 @@
17
17
  "browser": {
18
18
  "./index.js": "./index.browser.js",
19
19
  "./async/index.js": "./async/index.browser.js",
20
- "./async/index.cjs": "./async/index.browser.cjs"
21
- },
22
- "react-native": {
23
- "./async/index.js": "./async/index.native.js"
20
+ "./async/index.cjs": "./async/index.browser.cjs",
21
+ "./index.cjs": "./index.browser.cjs"
24
22
  },
23
+ "react-native": "index.js",
25
24
  "bin": "./bin/nanoid.cjs",
26
25
  "sideEffects": false,
27
- "types": "./index.d.ts"
28
- }
26
+ "types": "./index.d.ts",
27
+ "type": "module",
28
+ "main": "index.cjs",
29
+ "module": "index.js",
30
+ "exports": {
31
+ ".": {
32
+ "browser": {
33
+ "development": "./index.dev.js",
34
+ "production": "./index.prod.js",
35
+ "default": "./index.prod.js"
36
+ },
37
+ "require": "./index.cjs",
38
+ "import": "./index.js",
39
+ "default": "./index.js",
40
+ "types": "./index.d.ts"
41
+ },
42
+ "./package.json": "./package.json",
43
+ "./async/package.json": "./async/package.json",
44
+ "./async": {
45
+ "browser": "./async/index.browser.js",
46
+ "require": "./async/index.cjs",
47
+ "import": "./async/index.js",
48
+ "default": "./async/index.js"
49
+ },
50
+ "./non-secure/package.json": "./non-secure/package.json",
51
+ "./non-secure": {
52
+ "require": "./non-secure/index.cjs",
53
+ "import": "./non-secure/index.js",
54
+ "default": "./non-secure/index.js"
55
+ },
56
+ "./url-alphabet/package.json": "./url-alphabet/package.json",
57
+ "./url-alphabet": {
58
+ "require": "./url-alphabet/index.cjs",
59
+ "import": "./url-alphabet/index.js",
60
+ "default": "./url-alphabet/index.js"
61
+ },
62
+ "./index.d.ts": "./index.d.ts"
63
+ }
64
+ }
@@ -0,0 +1,3 @@
1
+ let urlAlphabet =
2
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
3
+ module.exports = { urlAlphabet }
@@ -1,6 +1,3 @@
1
- // This alphabet uses `A-Za-z0-9_-` symbols. The genetic algorithm helped
2
- // optimize the gzip compression for this alphabet.
3
1
  let urlAlphabet =
4
- 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'
5
-
6
- module.exports = { urlAlphabet }
2
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
3
+ export { urlAlphabet }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "main": "index.cjs",
4
+ "module": "index.js",
5
+ "react-native": "index.js"
6
+ }