@emulsify/cli 1.11.3 → 1.12.0

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.
Files changed (149) hide show
  1. package/dist/index.js +3 -1
  2. package/dist/node_modules/.package-lock.json +34 -24
  3. package/dist/node_modules/@types/node/README.md +2 -2
  4. package/dist/node_modules/@types/node/assert.d.ts +23 -1
  5. package/dist/node_modules/@types/node/async_hooks.d.ts +64 -0
  6. package/dist/node_modules/@types/node/buffer.buffer.d.ts +124 -38
  7. package/dist/node_modules/@types/node/buffer.d.ts +19 -17
  8. package/dist/node_modules/@types/node/child_process.d.ts +88 -161
  9. package/dist/node_modules/@types/node/cluster.d.ts +5 -6
  10. package/dist/node_modules/@types/node/constants.d.ts +14 -12
  11. package/dist/node_modules/@types/node/crypto.d.ts +237 -171
  12. package/dist/node_modules/@types/node/dgram.d.ts +15 -14
  13. package/dist/node_modules/@types/node/diagnostics_channel.d.ts +39 -15
  14. package/dist/node_modules/@types/node/dns/promises.d.ts +11 -9
  15. package/dist/node_modules/@types/node/dns.d.ts +28 -21
  16. package/dist/node_modules/@types/node/events.d.ts +81 -35
  17. package/dist/node_modules/@types/node/fs/promises.d.ts +61 -36
  18. package/dist/node_modules/@types/node/fs.d.ts +251 -193
  19. package/dist/node_modules/@types/node/globals.d.ts +146 -442
  20. package/dist/node_modules/@types/node/globals.typedarray.d.ts +17 -0
  21. package/dist/node_modules/@types/node/http.d.ts +137 -32
  22. package/dist/node_modules/@types/node/http2.d.ts +102 -26
  23. package/dist/node_modules/@types/node/https.d.ts +94 -60
  24. package/dist/node_modules/@types/node/index.d.ts +5 -3
  25. package/dist/node_modules/@types/node/{inspector.d.ts → inspector.generated.d.ts} +272 -2
  26. package/dist/node_modules/@types/node/module.d.ts +362 -138
  27. package/dist/node_modules/@types/node/net.d.ts +27 -20
  28. package/dist/node_modules/@types/node/os.d.ts +14 -3
  29. package/dist/node_modules/@types/node/package.json +4 -89
  30. package/dist/node_modules/@types/node/perf_hooks.d.ts +37 -10
  31. package/dist/node_modules/@types/node/process.d.ts +108 -35
  32. package/dist/node_modules/@types/node/querystring.d.ts +2 -3
  33. package/dist/node_modules/@types/node/readline/promises.d.ts +15 -3
  34. package/dist/node_modules/@types/node/readline.d.ts +66 -17
  35. package/dist/node_modules/@types/node/stream/consumers.d.ts +33 -7
  36. package/dist/node_modules/@types/node/stream/web.d.ts +13 -4
  37. package/dist/node_modules/@types/node/stream.d.ts +963 -1014
  38. package/dist/node_modules/@types/node/string_decoder.d.ts +2 -2
  39. package/dist/node_modules/@types/node/test.d.ts +1504 -1655
  40. package/dist/node_modules/@types/node/timers/promises.d.ts +28 -17
  41. package/dist/node_modules/@types/node/timers.d.ts +157 -111
  42. package/dist/node_modules/@types/node/tls.d.ts +105 -67
  43. package/dist/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +120 -37
  44. package/dist/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +15 -0
  45. package/dist/node_modules/@types/node/ts5.6/index.d.ts +5 -3
  46. package/dist/node_modules/@types/node/url.d.ts +10 -1
  47. package/dist/node_modules/@types/node/util.d.ts +43 -10
  48. package/dist/node_modules/@types/node/v8.d.ts +7 -6
  49. package/dist/node_modules/@types/node/vm.d.ts +148 -70
  50. package/dist/node_modules/@types/node/wasi.d.ts +1 -1
  51. package/dist/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  52. package/dist/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  53. package/dist/node_modules/@types/node/web-globals/events.d.ts +97 -0
  54. package/dist/node_modules/@types/node/web-globals/fetch.d.ts +46 -0
  55. package/dist/node_modules/@types/node/worker_threads.d.ts +60 -39
  56. package/dist/node_modules/@types/node/zlib.d.ts +21 -20
  57. package/dist/node_modules/debug/package.json +7 -3
  58. package/dist/node_modules/debug/src/browser.js +2 -1
  59. package/dist/node_modules/debug/src/common.js +57 -39
  60. package/dist/node_modules/fast-uri/.github/dependabot.yml +1 -1
  61. package/dist/node_modules/fast-uri/.github/workflows/ci.yml +81 -3
  62. package/dist/node_modules/fast-uri/.github/workflows/package-manager-ci.yml +6 -2
  63. package/dist/node_modules/fast-uri/LICENSE +3 -1
  64. package/dist/node_modules/fast-uri/README.md +55 -37
  65. package/dist/node_modules/fast-uri/benchmark/benchmark.mjs +159 -0
  66. package/dist/node_modules/fast-uri/benchmark/equal.mjs +51 -0
  67. package/dist/node_modules/fast-uri/benchmark/non-simple-domain.mjs +22 -0
  68. package/dist/node_modules/fast-uri/benchmark/package.json +17 -0
  69. package/dist/node_modules/fast-uri/benchmark/string-array-to-hex-stripped.mjs +24 -0
  70. package/dist/node_modules/fast-uri/benchmark/ws-is-secure.mjs +65 -0
  71. package/dist/node_modules/fast-uri/eslint.config.js +6 -0
  72. package/dist/node_modules/fast-uri/index.js +98 -61
  73. package/dist/node_modules/fast-uri/lib/schemes.js +160 -81
  74. package/dist/node_modules/fast-uri/lib/utils.js +217 -123
  75. package/dist/node_modules/fast-uri/package.json +44 -14
  76. package/dist/node_modules/fast-uri/test/ajv.test.js +7 -3
  77. package/dist/node_modules/fast-uri/test/equal.test.js +7 -2
  78. package/dist/node_modules/fast-uri/test/fixtures/uri-js-parse.json +501 -0
  79. package/dist/node_modules/fast-uri/test/fixtures/uri-js-serialize.json +120 -0
  80. package/dist/node_modules/fast-uri/test/parse.test.js +31 -31
  81. package/dist/node_modules/fast-uri/test/resolve.test.js +52 -49
  82. package/dist/node_modules/fast-uri/test/rfc-3986.test.js +90 -0
  83. package/dist/node_modules/fast-uri/test/serialize.test.js +55 -47
  84. package/dist/node_modules/fast-uri/test/uri-js-compatibility.test.js +33 -0
  85. package/dist/node_modules/fast-uri/test/uri-js.test.js +230 -230
  86. package/dist/node_modules/fast-uri/test/util.test.js +23 -8
  87. package/dist/node_modules/fast-uri/tsconfig.json +9 -0
  88. package/dist/node_modules/fast-uri/types/index.d.ts +16 -9
  89. package/dist/node_modules/fast-uri/types/index.test-d.ts +9 -9
  90. package/dist/node_modules/fs-extra/LICENSE +1 -1
  91. package/dist/node_modules/fs-extra/README.md +3 -1
  92. package/dist/node_modules/fs-extra/lib/copy/copy-sync.js +11 -1
  93. package/dist/node_modules/fs-extra/lib/copy/copy.js +13 -15
  94. package/dist/node_modules/fs-extra/lib/fs/index.js +6 -0
  95. package/dist/node_modules/fs-extra/lib/util/async.js +29 -0
  96. package/dist/node_modules/fs-extra/lib/util/stat.js +2 -1
  97. package/dist/node_modules/fs-extra/package.json +1 -1
  98. package/dist/node_modules/jsonfile/README.md +1 -1
  99. package/dist/node_modules/jsonfile/index.js +3 -3
  100. package/dist/node_modules/jsonfile/package.json +1 -1
  101. package/dist/node_modules/simple-git/dist/cjs/index.js +235 -235
  102. package/dist/node_modules/simple-git/dist/cjs/index.js.map +3 -3
  103. package/dist/node_modules/simple-git/dist/esm/index.js +229 -233
  104. package/dist/node_modules/simple-git/dist/esm/index.js.map +3 -3
  105. package/dist/node_modules/simple-git/dist/src/lib/git-logger.d.ts +1 -1
  106. package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-branch.d.ts +1 -1
  107. package/dist/node_modules/simple-git/dist/src/lib/plugins/error-detection.plugin.d.ts +2 -3
  108. package/dist/node_modules/simple-git/dist/src/lib/plugins/simple-git-plugin.d.ts +2 -3
  109. package/dist/node_modules/simple-git/dist/src/lib/plugins/spawn-options-plugin.d.ts +0 -1
  110. package/dist/node_modules/simple-git/dist/src/lib/runners/scheduler.d.ts +1 -1
  111. package/dist/node_modules/simple-git/dist/src/lib/runners/tasks-pending-queue.d.ts +2 -2
  112. package/dist/node_modules/simple-git/dist/src/lib/tasks/apply-patch.d.ts +1 -1
  113. package/dist/node_modules/simple-git/dist/src/lib/tasks/clean.d.ts +1 -1
  114. package/dist/node_modules/simple-git/dist/src/lib/tasks/clone.d.ts +1 -1
  115. package/dist/node_modules/simple-git/dist/src/lib/tasks/log.d.ts +3 -3
  116. package/dist/node_modules/simple-git/dist/src/lib/tasks/push.d.ts +1 -1
  117. package/dist/node_modules/simple-git/dist/src/lib/tasks/remote.d.ts +4 -2
  118. package/dist/node_modules/simple-git/dist/src/lib/tasks/reset.d.ts +3 -3
  119. package/dist/node_modules/simple-git/dist/src/lib/tasks/stash-list.d.ts +1 -1
  120. package/dist/node_modules/simple-git/dist/src/lib/tasks/task.d.ts +2 -2
  121. package/dist/node_modules/simple-git/dist/src/lib/types/handlers.d.ts +1 -1
  122. package/dist/node_modules/simple-git/dist/src/lib/types/index.d.ts +9 -13
  123. package/dist/node_modules/simple-git/dist/src/lib/types/tasks.d.ts +5 -6
  124. package/dist/node_modules/simple-git/dist/src/lib/utils/argument-filters.d.ts +5 -7
  125. package/dist/node_modules/simple-git/dist/src/lib/utils/git-output-streams.d.ts +0 -1
  126. package/dist/node_modules/simple-git/dist/src/lib/utils/line-parser.d.ts +1 -1
  127. package/dist/node_modules/simple-git/dist/src/lib/utils/task-options.d.ts +1 -1
  128. package/dist/node_modules/simple-git/dist/src/lib/utils/util.d.ts +11 -10
  129. package/dist/node_modules/simple-git/package.json +6 -6
  130. package/dist/node_modules/simple-git/readme.md +8 -0
  131. package/dist/node_modules/undici-types/dispatcher.d.ts +1 -0
  132. package/dist/node_modules/undici-types/eventsource.d.ts +0 -2
  133. package/dist/node_modules/undici-types/filereader.d.ts +1 -1
  134. package/dist/node_modules/undici-types/interceptors.d.ts +3 -1
  135. package/dist/node_modules/undici-types/package.json +1 -1
  136. package/dist/node_modules/undici-types/patch.d.ts +0 -38
  137. package/dist/node_modules/undici-types/readable.d.ts +5 -0
  138. package/dist/node_modules/undici-types/webidl.d.ts +6 -0
  139. package/dist/node_modules/undici-types/websocket.d.ts +0 -2
  140. package/dist/package-lock.json +969 -1002
  141. package/dist/package.json +1 -1
  142. package/dist/util/getAvailableStarters.js +2 -2
  143. package/package.json +1 -1
  144. package/dist/node_modules/@types/node/dom-events.d.ts +0 -124
  145. package/dist/node_modules/fast-uri/benchmark.js +0 -105
  146. package/dist/node_modules/fast-uri/lib/scopedChars.js +0 -30
  147. package/dist/node_modules/fast-uri/test/.gitkeep +0 -0
  148. package/dist/node_modules/fast-uri/test/compatibility.test.js +0 -131
  149. package/dist/node_modules/jsonfile/CHANGELOG.md +0 -171
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "benchmark",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "private": true,
7
+ "scripts": {
8
+ "bench": "node benchmark.mjs"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "tinybench": "^5.0.0",
15
+ "uri-js": "^4.4.1"
16
+ }
17
+ }
@@ -0,0 +1,24 @@
1
+ import { Bench } from 'tinybench'
2
+ import { stringArrayToHexStripped } from '../lib/utils.js'
3
+
4
+ const benchStringArrayToHexStripped = new Bench({ name: 'stringArrayToHexStripped' })
5
+
6
+ const case1 = ['0', '0', '0', '0']
7
+ const case2 = ['0', '0', '0', '1']
8
+ const case3 = ['0', '0', '1', '0']
9
+ const case4 = ['0', '1', '0', '0']
10
+ const case5 = ['1', '0', '0', '0']
11
+ const case6 = ['1', '0', '0', '1']
12
+
13
+ benchStringArrayToHexStripped.add('stringArrayToHexStripped', function () {
14
+ stringArrayToHexStripped(case1)
15
+ stringArrayToHexStripped(case2)
16
+ stringArrayToHexStripped(case3)
17
+ stringArrayToHexStripped(case4)
18
+ stringArrayToHexStripped(case5)
19
+ stringArrayToHexStripped(case6)
20
+ })
21
+
22
+ await benchStringArrayToHexStripped.run()
23
+ console.log(benchStringArrayToHexStripped.name)
24
+ console.table(benchStringArrayToHexStripped.table())
@@ -0,0 +1,65 @@
1
+ import { Bench } from 'tinybench'
2
+ import { wsIsSecure } from '../lib/schemes.js'
3
+
4
+ const benchWsIsSecure = new Bench({ name: 'wsIsSecure' })
5
+
6
+ const wsComponentAttributeSecureTrue = {
7
+ scheme: 'ws',
8
+ secure: true,
9
+ }
10
+
11
+ const wsComponentAttributeSecureFalse = {
12
+ scheme: 'ws',
13
+ secure: false,
14
+ }
15
+
16
+ const wssComponent = {
17
+ scheme: 'wss',
18
+ }
19
+
20
+ const wssComponentMixedCase = {
21
+ scheme: 'Wss',
22
+ }
23
+
24
+ const wssComponentUpperCase = {
25
+ scheme: 'WSS',
26
+ }
27
+
28
+ const httpComponent = {
29
+ scheme: 'http',
30
+ }
31
+
32
+ console.assert(wsIsSecure(wsComponentAttributeSecureTrue) === true, 'wsComponentAttributeSecureTrue should be secure')
33
+ console.assert(wsIsSecure(wsComponentAttributeSecureFalse) === false, 'wsComponentAttributeSecureFalse should not be secure')
34
+ console.assert(wsIsSecure(wssComponent) === true, 'wssComponent should be secure')
35
+ console.assert(wsIsSecure(wssComponentMixedCase) === true, 'wssComponentMixedCase should be secure')
36
+ console.assert(wsIsSecure(wssComponentUpperCase) === true, 'wssComponentUpperCase should be secure')
37
+ console.assert(wsIsSecure(httpComponent) === false, 'httpComponent should not be secure')
38
+
39
+ benchWsIsSecure.add(JSON.stringify(wsComponentAttributeSecureFalse), function () {
40
+ wsIsSecure(wsComponentAttributeSecureFalse)
41
+ })
42
+
43
+ benchWsIsSecure.add(JSON.stringify(wsComponentAttributeSecureTrue), function () {
44
+ wsIsSecure(wsComponentAttributeSecureTrue)
45
+ })
46
+
47
+ benchWsIsSecure.add(JSON.stringify(wssComponent), function () {
48
+ wsIsSecure(wssComponent)
49
+ })
50
+
51
+ benchWsIsSecure.add(JSON.stringify(wssComponentMixedCase), function () {
52
+ wsIsSecure(wssComponentMixedCase)
53
+ })
54
+
55
+ benchWsIsSecure.add(JSON.stringify(wssComponentUpperCase), function () {
56
+ wsIsSecure(wssComponentUpperCase)
57
+ })
58
+
59
+ benchWsIsSecure.add(JSON.stringify(httpComponent), function () {
60
+ wsIsSecure(httpComponent)
61
+ })
62
+
63
+ await benchWsIsSecure.run()
64
+ console.log(benchWsIsSecure.name)
65
+ console.table(benchWsIsSecure.table())
@@ -0,0 +1,6 @@
1
+ 'use strict'
2
+
3
+ module.exports = require('neostandard')({
4
+ ignores: require('neostandard').resolveIgnoresFromGitignore(),
5
+ ts: true
6
+ })
@@ -1,28 +1,49 @@
1
1
  'use strict'
2
2
 
3
- const { normalizeIPv6, normalizeIPv4, removeDotSegments, recomposeAuthority, normalizeComponentEncoding } = require('./lib/utils')
4
- const SCHEMES = require('./lib/schemes')
5
-
3
+ const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = require('./lib/utils')
4
+ const { SCHEMES, getSchemeHandler } = require('./lib/schemes')
5
+
6
+ /**
7
+ * @template {import('./types/index').URIComponent|string} T
8
+ * @param {T} uri
9
+ * @param {import('./types/index').Options} [options]
10
+ * @returns {T}
11
+ */
6
12
  function normalize (uri, options) {
7
13
  if (typeof uri === 'string') {
8
- uri = serialize(parse(uri, options), options)
14
+ uri = /** @type {T} */ (serialize(parse(uri, options), options))
9
15
  } else if (typeof uri === 'object') {
10
- uri = parse(serialize(uri, options), options)
16
+ uri = /** @type {T} */ (parse(serialize(uri, options), options))
11
17
  }
12
18
  return uri
13
19
  }
14
20
 
21
+ /**
22
+ * @param {string} baseURI
23
+ * @param {string} relativeURI
24
+ * @param {import('./types/index').Options} [options]
25
+ * @returns {string}
26
+ */
15
27
  function resolve (baseURI, relativeURI, options) {
16
- const schemelessOptions = Object.assign({ scheme: 'null' }, options)
17
- const resolved = resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true)
18
- return serialize(resolved, { ...schemelessOptions, skipEscape: true })
28
+ const schemelessOptions = options ? Object.assign({ scheme: 'null' }, options) : { scheme: 'null' }
29
+ const resolved = resolveComponent(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true)
30
+ schemelessOptions.skipEscape = true
31
+ return serialize(resolved, schemelessOptions)
19
32
  }
20
33
 
21
- function resolveComponents (base, relative, options, skipNormalization) {
34
+ /**
35
+ * @param {import ('./types/index').URIComponent} base
36
+ * @param {import ('./types/index').URIComponent} relative
37
+ * @param {import('./types/index').Options} [options]
38
+ * @param {boolean} [skipNormalization=false]
39
+ * @returns {import ('./types/index').URIComponent}
40
+ */
41
+ function resolveComponent (base, relative, options, skipNormalization) {
42
+ /** @type {import('./types/index').URIComponent} */
22
43
  const target = {}
23
44
  if (!skipNormalization) {
24
- base = parse(serialize(base, options), options) // normalize base components
25
- relative = parse(serialize(relative, options), options) // normalize relative components
45
+ base = parse(serialize(base, options), options) // normalize base component
46
+ relative = parse(serialize(relative, options), options) // normalize relative component
26
47
  }
27
48
  options = options || {}
28
49
 
@@ -51,7 +72,7 @@ function resolveComponents (base, relative, options, skipNormalization) {
51
72
  target.query = base.query
52
73
  }
53
74
  } else {
54
- if (relative.path.charAt(0) === '/') {
75
+ if (relative.path[0] === '/') {
55
76
  target.path = removeDotSegments(relative.path)
56
77
  } else {
57
78
  if ((base.userinfo !== undefined || base.host !== undefined || base.port !== undefined) && !base.path) {
@@ -78,6 +99,12 @@ function resolveComponents (base, relative, options, skipNormalization) {
78
99
  return target
79
100
  }
80
101
 
102
+ /**
103
+ * @param {import ('./types/index').URIComponent|string} uriA
104
+ * @param {import ('./types/index').URIComponent|string} uriB
105
+ * @param {import ('./types/index').Options} options
106
+ * @returns {boolean}
107
+ */
81
108
  function equal (uriA, uriB, options) {
82
109
  if (typeof uriA === 'string') {
83
110
  uriA = unescape(uriA)
@@ -96,8 +123,13 @@ function equal (uriA, uriB, options) {
96
123
  return uriA.toLowerCase() === uriB.toLowerCase()
97
124
  }
98
125
 
126
+ /**
127
+ * @param {Readonly<import('./types/index').URIComponent>} cmpts
128
+ * @param {import('./types/index').Options} [opts]
129
+ * @returns {string}
130
+ */
99
131
  function serialize (cmpts, opts) {
100
- const components = {
132
+ const component = {
101
133
  host: cmpts.host,
102
134
  scheme: cmpts.scheme,
103
135
  userinfo: cmpts.userinfo,
@@ -117,28 +149,28 @@ function serialize (cmpts, opts) {
117
149
  const uriTokens = []
118
150
 
119
151
  // find scheme handler
120
- const schemeHandler = SCHEMES[(options.scheme || components.scheme || '').toLowerCase()]
152
+ const schemeHandler = getSchemeHandler(options.scheme || component.scheme)
121
153
 
122
154
  // perform scheme specific serialization
123
- if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options)
155
+ if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options)
124
156
 
125
- if (components.path !== undefined) {
157
+ if (component.path !== undefined) {
126
158
  if (!options.skipEscape) {
127
- components.path = escape(components.path)
159
+ component.path = escape(component.path)
128
160
 
129
- if (components.scheme !== undefined) {
130
- components.path = components.path.split('%3A').join(':')
161
+ if (component.scheme !== undefined) {
162
+ component.path = component.path.split('%3A').join(':')
131
163
  }
132
164
  } else {
133
- components.path = unescape(components.path)
165
+ component.path = unescape(component.path)
134
166
  }
135
167
  }
136
168
 
137
- if (options.reference !== 'suffix' && components.scheme) {
138
- uriTokens.push(components.scheme, ':')
169
+ if (options.reference !== 'suffix' && component.scheme) {
170
+ uriTokens.push(component.scheme, ':')
139
171
  }
140
172
 
141
- const authority = recomposeAuthority(components, options)
173
+ const authority = recomposeAuthority(component)
142
174
  if (authority !== undefined) {
143
175
  if (options.reference !== 'suffix') {
144
176
  uriTokens.push('//')
@@ -146,51 +178,49 @@ function serialize (cmpts, opts) {
146
178
 
147
179
  uriTokens.push(authority)
148
180
 
149
- if (components.path && components.path.charAt(0) !== '/') {
181
+ if (component.path && component.path[0] !== '/') {
150
182
  uriTokens.push('/')
151
183
  }
152
184
  }
153
- if (components.path !== undefined) {
154
- let s = components.path
185
+ if (component.path !== undefined) {
186
+ let s = component.path
155
187
 
156
188
  if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
157
189
  s = removeDotSegments(s)
158
190
  }
159
191
 
160
- if (authority === undefined) {
161
- s = s.replace(/^\/\//u, '/%2F') // don't allow the path to start with "//"
192
+ if (
193
+ authority === undefined &&
194
+ s[0] === '/' &&
195
+ s[1] === '/'
196
+ ) {
197
+ // don't allow the path to start with "//"
198
+ s = '/%2F' + s.slice(2)
162
199
  }
163
200
 
164
201
  uriTokens.push(s)
165
202
  }
166
203
 
167
- if (components.query !== undefined) {
168
- uriTokens.push('?', components.query)
204
+ if (component.query !== undefined) {
205
+ uriTokens.push('?', component.query)
169
206
  }
170
207
 
171
- if (components.fragment !== undefined) {
172
- uriTokens.push('#', components.fragment)
208
+ if (component.fragment !== undefined) {
209
+ uriTokens.push('#', component.fragment)
173
210
  }
174
211
  return uriTokens.join('')
175
212
  }
176
213
 
177
- const hexLookUp = Array.from({ length: 127 }, (v, k) => /[^!"$&'()*+,\-.;=_`a-z{}~]/u.test(String.fromCharCode(k)))
178
-
179
- function nonSimpleDomain (value) {
180
- let code = 0
181
- for (let i = 0, len = value.length; i < len; ++i) {
182
- code = value.charCodeAt(i)
183
- if (code > 126 || hexLookUp[code]) {
184
- return true
185
- }
186
- }
187
- return false
188
- }
189
-
190
214
  const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u
191
215
 
216
+ /**
217
+ * @param {string} uri
218
+ * @param {import('./types/index').Options} [opts]
219
+ * @returns
220
+ */
192
221
  function parse (uri, opts) {
193
222
  const options = Object.assign({}, opts)
223
+ /** @type {import('./types/index').URIComponent} */
194
224
  const parsed = {
195
225
  scheme: undefined,
196
226
  userinfo: undefined,
@@ -200,9 +230,15 @@ function parse (uri, opts) {
200
230
  query: undefined,
201
231
  fragment: undefined
202
232
  }
203
- const gotEncoding = uri.indexOf('%') !== -1
233
+
204
234
  let isIP = false
205
- if (options.reference === 'suffix') uri = (options.scheme ? options.scheme + ':' : '') + '//' + uri
235
+ if (options.reference === 'suffix') {
236
+ if (options.scheme) {
237
+ uri = options.scheme + ':' + uri
238
+ } else {
239
+ uri = '//' + uri
240
+ }
241
+ }
206
242
 
207
243
  const matches = uri.match(URI_PARSE)
208
244
 
@@ -221,17 +257,16 @@ function parse (uri, opts) {
221
257
  parsed.port = matches[5]
222
258
  }
223
259
  if (parsed.host) {
224
- const ipv4result = normalizeIPv4(parsed.host)
225
- if (ipv4result.isIPV4 === false) {
226
- const ipv6result = normalizeIPv6(ipv4result.host, { isIPV4: false })
260
+ const ipv4result = isIPv4(parsed.host)
261
+ if (ipv4result === false) {
262
+ const ipv6result = normalizeIPv6(parsed.host)
227
263
  parsed.host = ipv6result.host.toLowerCase()
228
264
  isIP = ipv6result.isIPV6
229
265
  } else {
230
- parsed.host = ipv4result.host
231
266
  isIP = true
232
267
  }
233
268
  }
234
- if (parsed.scheme === undefined && parsed.userinfo === undefined && parsed.host === undefined && parsed.port === undefined && !parsed.path && parsed.query === undefined) {
269
+ if (parsed.scheme === undefined && parsed.userinfo === undefined && parsed.host === undefined && parsed.port === undefined && parsed.query === undefined && !parsed.path) {
235
270
  parsed.reference = 'same-document'
236
271
  } else if (parsed.scheme === undefined) {
237
272
  parsed.reference = 'relative'
@@ -247,7 +282,7 @@ function parse (uri, opts) {
247
282
  }
248
283
 
249
284
  // find scheme handler
250
- const schemeHandler = SCHEMES[(options.scheme || parsed.scheme || '').toLowerCase()]
285
+ const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme)
251
286
 
252
287
  // check if scheme can't handle IRIs
253
288
  if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
@@ -264,16 +299,18 @@ function parse (uri, opts) {
264
299
  }
265
300
 
266
301
  if (!schemeHandler || (schemeHandler && !schemeHandler.skipNormalize)) {
267
- if (gotEncoding && parsed.scheme !== undefined) {
268
- parsed.scheme = unescape(parsed.scheme)
269
- }
270
- if (gotEncoding && parsed.host !== undefined) {
271
- parsed.host = unescape(parsed.host)
302
+ if (uri.indexOf('%') !== -1) {
303
+ if (parsed.scheme !== undefined) {
304
+ parsed.scheme = unescape(parsed.scheme)
305
+ }
306
+ if (parsed.host !== undefined) {
307
+ parsed.host = unescape(parsed.host)
308
+ }
272
309
  }
273
- if (parsed.path !== undefined && parsed.path.length) {
310
+ if (parsed.path) {
274
311
  parsed.path = escape(unescape(parsed.path))
275
312
  }
276
- if (parsed.fragment !== undefined && parsed.fragment.length) {
313
+ if (parsed.fragment) {
277
314
  parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment))
278
315
  }
279
316
  }
@@ -292,7 +329,7 @@ const fastUri = {
292
329
  SCHEMES,
293
330
  normalize,
294
331
  resolve,
295
- resolveComponents,
332
+ resolveComponent,
296
333
  equal,
297
334
  serialize,
298
335
  parse