nanoid 3.1.19 → 3.1.20

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.

Potentially problematic release.


This version of nanoid might be problematic. Click here for more details.

package/CHANGELOG.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Change Log
2
2
  This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
+ ## 3.1.20
5
+ * Fix ES modules support.
6
+
4
7
  ## 3.1.19
5
- * Reduce `customAlphabet` size (by Enrico Scherlies).
8
+ * Reduced `customAlphabet` size (by Enrico Scherlies).
6
9
 
7
10
  ## 3.1.18
8
11
  * Fixed `package.exports`.
@@ -34,7 +34,6 @@ let customAlphabet = (alphabet, size) => {
34
34
  while (i--) {
35
35
  // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
36
36
  id += alphabet[bytes[i] & mask] || ''
37
- // Return if id length equals size.
38
37
  if (id.length === size) return Promise.resolve(id)
39
38
  }
40
39
  }
@@ -68,4 +67,4 @@ let nanoid = (size = 21) => {
68
67
  return Promise.resolve(id)
69
68
  }
70
69
 
71
- module.exports = { nanoid, customAlphabet, random }
70
+ export { nanoid, customAlphabet, random }
@@ -0,0 +1,71 @@
1
+ let crypto = require('crypto')
2
+
3
+ let { urlAlphabet } = require('../url-alphabet/index.cjs')
4
+
5
+ // `crypto.randomFill()` is a little faster than `crypto.randomBytes()`,
6
+ // because it is possible to use in combination with `Buffer.allocUnsafe()`.
7
+ let random = bytes =>
8
+ new Promise((resolve, reject) => {
9
+ // `Buffer.allocUnsafe()` is faster because it doesn’t flush the memory.
10
+ // Memory flushing is unnecessary since the buffer allocation itself resets
11
+ // the memory with the new bytes.
12
+ crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
13
+ if (err) {
14
+ reject(err)
15
+ } else {
16
+ resolve(buf)
17
+ }
18
+ })
19
+ })
20
+
21
+ let customAlphabet = (alphabet, size) => {
22
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
23
+ // values closer to the alphabet size. The bitmask calculates the closest
24
+ // `2^31 - 1` number, which exceeds the alphabet size.
25
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
26
+ let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
27
+ // Though, the bitmask solution is not perfect since the bytes exceeding
28
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
29
+ // the random bytes redundancy has to be satisfied.
30
+
31
+ // Note: every hardware random generator call is performance expensive,
32
+ // because the system call for entropy collection takes a lot of time.
33
+ // So, to avoid additional system calls, extra bytes are requested in advance.
34
+
35
+ // Next, a step determines how many random bytes to generate.
36
+ // The number of random bytes gets decided upon the ID size, mask,
37
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
38
+ // according to benchmarks).
39
+ let step = Math.ceil((1.6 * mask * size) / alphabet.length)
40
+
41
+ let tick = id =>
42
+ random(step).then(bytes => {
43
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
44
+ let i = step
45
+ while (i--) {
46
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
47
+ id += alphabet[bytes[i] & mask] || ''
48
+ if (id.length === size) return id
49
+ }
50
+ return tick(id)
51
+ })
52
+
53
+ return () => tick('')
54
+ }
55
+
56
+ let nanoid = (size = 21) =>
57
+ random(size).then(bytes => {
58
+ let id = ''
59
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
60
+ while (size--) {
61
+ // It is incorrect to use bytes exceeding the alphabet size.
62
+ // The following mask reduces the random byte in the 0-255 value
63
+ // range to the 0-63 value range. Therefore, adding hacks, such
64
+ // as empty string fallback or magic numbers, is unneccessary because
65
+ // the bitmask trims bytes down to the alphabet size.
66
+ id += urlAlphabet[bytes[size] & 63]
67
+ }
68
+ return id
69
+ })
70
+
71
+ module.exports = { nanoid, customAlphabet, random }
package/async/index.js CHANGED
@@ -1,6 +1,6 @@
1
- let crypto = require('crypto')
1
+ import crypto from 'crypto'
2
2
 
3
- let { urlAlphabet } = require('../url-alphabet')
3
+ import { urlAlphabet } from '../url-alphabet/index.js'
4
4
 
5
5
  // `crypto.randomFill()` is a little faster than `crypto.randomBytes()`,
6
6
  // because it is possible to use in combination with `Buffer.allocUnsafe()`.
@@ -45,7 +45,6 @@ let customAlphabet = (alphabet, size) => {
45
45
  while (i--) {
46
46
  // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
47
47
  id += alphabet[bytes[i] & mask] || ''
48
- // Return if id length equals size.
49
48
  if (id.length === size) return id
50
49
  }
51
50
  return tick(id)
@@ -69,4 +68,4 @@ let nanoid = (size = 21) =>
69
68
  return id
70
69
  })
71
70
 
72
- module.exports = { nanoid, customAlphabet, random }
71
+ export { nanoid, customAlphabet, random }
@@ -1,6 +1,6 @@
1
- let { getRandomBytesAsync } = require('expo-random')
1
+ import { getRandomBytesAsync } from 'expo-random'
2
2
 
3
- let { urlAlphabet } = require('../url-alphabet')
3
+ import { urlAlphabet } from '../url-alphabet/index.js'
4
4
 
5
5
  let random = getRandomBytesAsync
6
6
 
@@ -31,7 +31,6 @@ let customAlphabet = (alphabet, size) => {
31
31
  while (i--) {
32
32
  // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
33
33
  id += alphabet[bytes[i] & mask] || ''
34
- // Return if id length equals size.
35
34
  if (id.length === size) return id
36
35
  }
37
36
  return tick(id)
@@ -55,4 +54,4 @@ let nanoid = (size = 21) =>
55
54
  return id
56
55
  })
57
56
 
58
- module.exports = { nanoid, customAlphabet, random }
57
+ export { nanoid, customAlphabet, random }
@@ -0,0 +1,11 @@
1
+ {
2
+ "type": "module",
3
+ "main": "index.cjs",
4
+ "module": "index.js",
5
+ "react-native": {
6
+ "./index.js": "./index.native.js"
7
+ },
8
+ "browser": {
9
+ "./index.js": "./index.browser.js"
10
+ }
11
+ }
package/index.browser.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // This file replaces `index.js` in bundlers like webpack or Rollup,
2
2
  // according to `browser` config in `package.json`.
3
3
 
4
- let { urlAlphabet } = require('./url-alphabet')
4
+ import { urlAlphabet } from './url-alphabet/index.js'
5
5
 
6
6
  if (process.env.NODE_ENV !== 'production') {
7
7
  // All bundlers will remove this block in the production bundle.
@@ -67,7 +67,6 @@ let customRandom = (alphabet, size, getRandom) => {
67
67
  while (j--) {
68
68
  // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
69
69
  id += alphabet[bytes[j] & mask] || ''
70
- // Return if id length equals size.
71
70
  if (id.length === size) return id
72
71
  }
73
72
  }
@@ -103,4 +102,4 @@ let nanoid = (size = 21) => {
103
102
  return id
104
103
  }
105
104
 
106
- module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
105
+ export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
package/index.cjs ADDED
@@ -0,0 +1,80 @@
1
+ let crypto = require('crypto')
2
+
3
+ let { urlAlphabet } = require('./url-alphabet/index.cjs')
4
+
5
+ // It is best to make fewer, larger requests to the crypto module to
6
+ // avoid system call overhead. So, random numbers are generated in a
7
+ // pool. The pool is a Buffer that is larger than the initial random
8
+ // request size by this multiplier. The pool is enlarged if subsequent
9
+ // requests exceed the maximum buffer size.
10
+ const POOL_SIZE_MULTIPLIER = 32
11
+ let pool, poolOffset
12
+
13
+ let random = bytes => {
14
+ if (!pool || pool.length < bytes) {
15
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
16
+ crypto.randomFillSync(pool)
17
+ poolOffset = 0
18
+ } else if (poolOffset + bytes > pool.length) {
19
+ crypto.randomFillSync(pool)
20
+ poolOffset = 0
21
+ }
22
+
23
+ let res = pool.subarray(poolOffset, poolOffset + bytes)
24
+ poolOffset += bytes
25
+ return res
26
+ }
27
+
28
+ let customRandom = (alphabet, size, getRandom) => {
29
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
30
+ // values closer to the alphabet size. The bitmask calculates the closest
31
+ // `2^31 - 1` number, which exceeds the alphabet size.
32
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
33
+ let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
34
+ // Though, the bitmask solution is not perfect since the bytes exceeding
35
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
36
+ // the random bytes redundancy has to be satisfied.
37
+
38
+ // Note: every hardware random generator call is performance expensive,
39
+ // because the system call for entropy collection takes a lot of time.
40
+ // So, to avoid additional system calls, extra bytes are requested in advance.
41
+
42
+ // Next, a step determines how many random bytes to generate.
43
+ // The number of random bytes gets decided upon the ID size, mask,
44
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
45
+ // according to benchmarks).
46
+ let step = Math.ceil((1.6 * mask * size) / alphabet.length)
47
+
48
+ return () => {
49
+ let id = ''
50
+ while (true) {
51
+ let bytes = getRandom(step)
52
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
53
+ let i = step
54
+ while (i--) {
55
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
56
+ id += alphabet[bytes[i] & mask] || ''
57
+ if (id.length === size) return id
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ let customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)
64
+
65
+ let nanoid = (size = 21) => {
66
+ let bytes = random(size)
67
+ let id = ''
68
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
69
+ while (size--) {
70
+ // It is incorrect to use bytes exceeding the alphabet size.
71
+ // The following mask reduces the random byte in the 0-255 value
72
+ // range to the 0-63 value range. Therefore, adding hacks, such
73
+ // as empty string fallback or magic numbers, is unneccessary because
74
+ // the bitmask trims bytes down to the alphabet size.
75
+ id += urlAlphabet[bytes[size] & 63]
76
+ }
77
+ return id
78
+ }
79
+
80
+ module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
package/index.dev.js ADDED
@@ -0,0 +1,105 @@
1
+ // This file replaces `index.js` in bundlers like webpack or Rollup,
2
+ // according to `browser` config in `package.json`.
3
+
4
+ import { urlAlphabet } from './url-alphabet/index.js'
5
+
6
+ if (true) {
7
+ // All bundlers will remove this block in the production bundle.
8
+ if (
9
+ typeof navigator !== 'undefined' &&
10
+ navigator.product === 'ReactNative' &&
11
+ typeof crypto === 'undefined'
12
+ ) {
13
+ throw new Error(
14
+ 'React Native does not have a built-in secure random generator. ' +
15
+ 'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +
16
+ 'For secure IDs, import `react-native-get-random-values` ' +
17
+ 'before Nano ID. If you use Expo, install `expo-random` ' +
18
+ 'and use `nanoid/async`.'
19
+ )
20
+ }
21
+ if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {
22
+ throw new Error(
23
+ 'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +
24
+ ' before importing Nano ID to fix IE 11 support'
25
+ )
26
+ }
27
+ if (typeof crypto === 'undefined') {
28
+ throw new Error(
29
+ 'Your browser does not have secure random generator. ' +
30
+ 'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'
31
+ )
32
+ }
33
+ }
34
+
35
+ let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
36
+
37
+ let customRandom = (alphabet, size, getRandom) => {
38
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
39
+ // values closer to the alphabet size. The bitmask calculates the closest
40
+ // `2^31 - 1` number, which exceeds the alphabet size.
41
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
42
+ // `Math.clz32` is not used, because it is not available in browsers.
43
+ let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
44
+ // Though, the bitmask solution is not perfect since the bytes exceeding
45
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
46
+ // the random bytes redundancy has to be satisfied.
47
+
48
+ // Note: every hardware random generator call is performance expensive,
49
+ // because the system call for entropy collection takes a lot of time.
50
+ // So, to avoid additional system calls, extra bytes are requested in advance.
51
+
52
+ // Next, a step determines how many random bytes to generate.
53
+ // The number of random bytes gets decided upon the ID size, mask,
54
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
55
+ // according to benchmarks).
56
+
57
+ // `-~f => Math.ceil(f)` if f is a float
58
+ // `-~i => i + 1` if i is an integer
59
+ let step = -~((1.6 * mask * size) / alphabet.length)
60
+
61
+ return () => {
62
+ let id = ''
63
+ while (true) {
64
+ let bytes = getRandom(step)
65
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
66
+ let j = step
67
+ while (j--) {
68
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
69
+ id += alphabet[bytes[j] & mask] || ''
70
+ if (id.length === size) return id
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ let customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)
77
+
78
+ let nanoid = (size = 21) => {
79
+ let id = ''
80
+ let bytes = crypto.getRandomValues(new Uint8Array(size))
81
+
82
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
83
+ while (size--) {
84
+ // It is incorrect to use bytes exceeding the alphabet size.
85
+ // The following mask reduces the random byte in the 0-255 value
86
+ // range to the 0-63 value range. Therefore, adding hacks, such
87
+ // as empty string fallback or magic numbers, is unneccessary because
88
+ // the bitmask trims bytes down to the alphabet size.
89
+ let byte = bytes[size] & 63
90
+ if (byte < 36) {
91
+ // `0-9a-z`
92
+ id += byte.toString(36)
93
+ } else if (byte < 62) {
94
+ // `A-Z`
95
+ id += (byte - 26).toString(36).toUpperCase()
96
+ } else if (byte < 63) {
97
+ id += '_'
98
+ } else {
99
+ id += '-'
100
+ }
101
+ }
102
+ return id
103
+ }
104
+
105
+ export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
- let crypto = require('crypto')
1
+ import crypto from 'crypto'
2
2
 
3
- let { urlAlphabet } = require('./url-alphabet')
3
+ import { urlAlphabet } from './url-alphabet/index.js'
4
4
 
5
5
  // It is best to make fewer, larger requests to the crypto module to
6
6
  // avoid system call overhead. So, random numbers are generated in a
@@ -54,7 +54,6 @@ let customRandom = (alphabet, size, getRandom) => {
54
54
  while (i--) {
55
55
  // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
56
56
  id += alphabet[bytes[i] & mask] || ''
57
- // Return if id length equals size.
58
57
  if (id.length === size) return id
59
58
  }
60
59
  }
@@ -78,4 +77,4 @@ let nanoid = (size = 21) => {
78
77
  return id
79
78
  }
80
79
 
81
- module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
80
+ export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
package/index.prod.js ADDED
@@ -0,0 +1,105 @@
1
+ // This file replaces `index.js` in bundlers like webpack or Rollup,
2
+ // according to `browser` config in `package.json`.
3
+
4
+ import { urlAlphabet } from './url-alphabet/index.js'
5
+
6
+ if (false) {
7
+ // All bundlers will remove this block in the production bundle.
8
+ if (
9
+ typeof navigator !== 'undefined' &&
10
+ navigator.product === 'ReactNative' &&
11
+ typeof crypto === 'undefined'
12
+ ) {
13
+ throw new Error(
14
+ 'React Native does not have a built-in secure random generator. ' +
15
+ 'If you don’t need unpredictable IDs use `nanoid/non-secure`. ' +
16
+ 'For secure IDs, import `react-native-get-random-values` ' +
17
+ 'before Nano ID. If you use Expo, install `expo-random` ' +
18
+ 'and use `nanoid/async`.'
19
+ )
20
+ }
21
+ if (typeof msCrypto !== 'undefined' && typeof crypto === 'undefined') {
22
+ throw new Error(
23
+ 'Import file with `if (!window.crypto) window.crypto = window.msCrypto`' +
24
+ ' before importing Nano ID to fix IE 11 support'
25
+ )
26
+ }
27
+ if (typeof crypto === 'undefined') {
28
+ throw new Error(
29
+ 'Your browser does not have secure random generator. ' +
30
+ 'If you don’t need unpredictable IDs, you can use nanoid/non-secure.'
31
+ )
32
+ }
33
+ }
34
+
35
+ let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
36
+
37
+ let customRandom = (alphabet, size, getRandom) => {
38
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
39
+ // values closer to the alphabet size. The bitmask calculates the closest
40
+ // `2^31 - 1` number, which exceeds the alphabet size.
41
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
42
+ // `Math.clz32` is not used, because it is not available in browsers.
43
+ let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
44
+ // Though, the bitmask solution is not perfect since the bytes exceeding
45
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
46
+ // the random bytes redundancy has to be satisfied.
47
+
48
+ // Note: every hardware random generator call is performance expensive,
49
+ // because the system call for entropy collection takes a lot of time.
50
+ // So, to avoid additional system calls, extra bytes are requested in advance.
51
+
52
+ // Next, a step determines how many random bytes to generate.
53
+ // The number of random bytes gets decided upon the ID size, mask,
54
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
55
+ // according to benchmarks).
56
+
57
+ // `-~f => Math.ceil(f)` if f is a float
58
+ // `-~i => i + 1` if i is an integer
59
+ let step = -~((1.6 * mask * size) / alphabet.length)
60
+
61
+ return () => {
62
+ let id = ''
63
+ while (true) {
64
+ let bytes = getRandom(step)
65
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
66
+ let j = step
67
+ while (j--) {
68
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
69
+ id += alphabet[bytes[j] & mask] || ''
70
+ if (id.length === size) return id
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ let customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)
77
+
78
+ let nanoid = (size = 21) => {
79
+ let id = ''
80
+ let bytes = crypto.getRandomValues(new Uint8Array(size))
81
+
82
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
83
+ while (size--) {
84
+ // It is incorrect to use bytes exceeding the alphabet size.
85
+ // The following mask reduces the random byte in the 0-255 value
86
+ // range to the 0-63 value range. Therefore, adding hacks, such
87
+ // as empty string fallback or magic numbers, is unneccessary because
88
+ // the bitmask trims bytes down to the alphabet size.
89
+ let byte = bytes[size] & 63
90
+ if (byte < 36) {
91
+ // `0-9a-z`
92
+ id += byte.toString(36)
93
+ } else if (byte < 62) {
94
+ // `A-Z`
95
+ id += (byte - 26).toString(36).toUpperCase()
96
+ } else if (byte < 63) {
97
+ id += '_'
98
+ } else {
99
+ id += '-'
100
+ }
101
+ }
102
+ return id
103
+ }
104
+
105
+ export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
@@ -0,0 +1,30 @@
1
+ // This alphabet uses `A-Za-z0-9_-` symbols. The genetic algorithm helped
2
+ // optimize the gzip compression for this alphabet.
3
+ let urlAlphabet =
4
+ 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'
5
+
6
+ let customAlphabet = (alphabet, size) => {
7
+ return () => {
8
+ let id = ''
9
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
10
+ let i = size
11
+ while (i--) {
12
+ // `| 0` is more compact and faster than `Math.floor()`.
13
+ id += alphabet[(Math.random() * alphabet.length) | 0]
14
+ }
15
+ return id
16
+ }
17
+ }
18
+
19
+ let nanoid = (size = 21) => {
20
+ let id = ''
21
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
22
+ let i = size
23
+ while (i--) {
24
+ // `| 0` is more compact and faster than `Math.floor()`.
25
+ id += urlAlphabet[(Math.random() * 64) | 0]
26
+ }
27
+ return id
28
+ }
29
+
30
+ module.exports = { nanoid, customAlphabet }
@@ -27,4 +27,4 @@ let nanoid = (size = 21) => {
27
27
  return id
28
28
  }
29
29
 
30
- module.exports = { nanoid, customAlphabet }
30
+ 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,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoid",
3
- "version": "3.1.19",
3
+ "version": "3.1.20",
4
4
  "description": "A tiny (108 bytes), secure URL-friendly unique string ID generator",
5
5
  "keywords": [
6
6
  "uuid",
@@ -15,13 +15,42 @@
15
15
  "license": "MIT",
16
16
  "repository": "ai/nanoid",
17
17
  "browser": {
18
- "./index.js": "./index.browser.js",
19
- "./async/index.js": "./async/index.browser.js"
20
- },
21
- "react-native": {
22
- "./async/index.js": "./async/index.native.js"
18
+ "./index.js": "./index.browser.js"
23
19
  },
20
+ "react-native": "index.js",
24
21
  "bin": "./bin/nanoid.cjs",
25
22
  "sideEffects": false,
26
- "types": "./index.d.ts"
27
- }
23
+ "types": "./index.d.ts",
24
+ "type": "module",
25
+ "main": "index.cjs",
26
+ "module": "index.js",
27
+ "exports": {
28
+ ".": {
29
+ "browser": {
30
+ "development": "./index.dev.js",
31
+ "production": "./index.prod.js"
32
+ },
33
+ "require": "./index.cjs",
34
+ "import": "./index.js",
35
+ "types": "./index.d.ts"
36
+ },
37
+ "./package.json": "./package.json",
38
+ "./async/package.json": "./async/package.json",
39
+ "./async": {
40
+ "browser": "./async/index.browser.js",
41
+ "require": "./async/index.cjs",
42
+ "import": "./async/index.js"
43
+ },
44
+ "./non-secure/package.json": "./non-secure/package.json",
45
+ "./non-secure": {
46
+ "require": "./non-secure/index.cjs",
47
+ "import": "./non-secure/index.js"
48
+ },
49
+ "./url-alphabet/package.json": "./url-alphabet/package.json",
50
+ "./url-alphabet": {
51
+ "require": "./url-alphabet/index.cjs",
52
+ "import": "./url-alphabet/index.js"
53
+ },
54
+ "./index.d.ts": "./index.d.ts"
55
+ }
56
+ }
@@ -0,0 +1,6 @@
1
+ // This alphabet uses `A-Za-z0-9_-` symbols. The genetic algorithm helped
2
+ // optimize the gzip compression for this alphabet.
3
+ let urlAlphabet =
4
+ 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'
5
+
6
+ module.exports = { urlAlphabet }
@@ -3,4 +3,4 @@
3
3
  let urlAlphabet =
4
4
  'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'
5
5
 
6
- module.exports = { urlAlphabet }
6
+ export { urlAlphabet }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "main": "index.cjs",
4
+ "module": "index.js",
5
+ "react-native": "index.js"
6
+ }
@@ -1,11 +0,0 @@
1
- let { promisify } = require('util')
2
- let { join } = require('path')
3
- let child = require('child_process')
4
-
5
- let exec = promisify(child.exec)
6
-
7
- it('prints unique ID', async () => {
8
- let { stdout, stderr } = await exec('node ' + join(__dirname, 'nanoid.cjs'))
9
- expect(stderr).toEqual('')
10
- expect(stdout).toMatch(/^[\w-]{21}\n$/)
11
- })