cf-workers-native 0.0.0-stage → 0.1.2-beta.local.sha2f5e4e6956f4

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 (629) hide show
  1. package/LICENSE +21 -0
  2. package/Package.swift +25 -0
  3. package/README.md +92 -2
  4. package/dist/android.d.ts +2 -0
  5. package/dist/android.js +1 -0
  6. package/dist/browser/abort/index.d.ts +13 -0
  7. package/dist/browser/abort/index.js +66 -0
  8. package/dist/browser/body/index.d.ts +24 -0
  9. package/dist/browser/body/index.js +116 -0
  10. package/dist/browser/body/stream-body.d.ts +13 -0
  11. package/dist/browser/body/stream-body.js +84 -0
  12. package/dist/browser/documents/body.d.ts +3 -0
  13. package/dist/browser/documents/body.js +48 -0
  14. package/dist/browser/documents/form-body.d.ts +1 -0
  15. package/dist/browser/documents/form-body.js +54 -0
  16. package/dist/browser/documents/host.d.ts +11 -0
  17. package/dist/browser/documents/host.js +256 -0
  18. package/dist/browser/documents/links-source.d.ts +1 -0
  19. package/dist/browser/documents/links-source.js +1 -0
  20. package/dist/browser/documents/links.d.ts +1 -0
  21. package/dist/browser/documents/links.js +33 -0
  22. package/dist/browser/documents/page-config.d.ts +5 -0
  23. package/dist/browser/documents/page-config.js +5 -0
  24. package/dist/browser/documents/page-source.d.ts +1 -0
  25. package/dist/browser/documents/page-source.js +1 -0
  26. package/dist/browser/documents/page.d.ts +2 -0
  27. package/dist/browser/documents/page.js +153 -0
  28. package/dist/browser/documents/registration.d.ts +5 -0
  29. package/dist/browser/documents/registration.js +75 -0
  30. package/dist/browser/documents/runtime.d.ts +7 -0
  31. package/dist/browser/documents/runtime.js +161 -0
  32. package/dist/browser/documents/service-worker.js +285 -0
  33. package/dist/browser/encoding/index.d.ts +7 -0
  34. package/dist/browser/encoding/index.js +3 -0
  35. package/dist/browser/fetch/LICENSE-3RD-PARTY.md +9 -0
  36. package/dist/browser/fetch/LICENSE-APACHE +177 -0
  37. package/dist/browser/fetch/host-call.d.ts +3 -0
  38. package/dist/browser/fetch/host-call.js +67 -0
  39. package/dist/browser/fetch/index.d.ts +5 -0
  40. package/dist/browser/fetch/index.js +96 -0
  41. package/dist/browser/fetch/interop.d.ts +6 -0
  42. package/dist/browser/fetch/interop.js +48 -0
  43. package/dist/browser/fetch/native-network.d.ts +20 -0
  44. package/dist/browser/fetch/native-network.js +233 -0
  45. package/dist/browser/fetch/outbound.d.ts +2 -0
  46. package/dist/browser/fetch/outbound.js +11 -0
  47. package/dist/browser/fetch/relay.d.ts +7 -0
  48. package/dist/browser/fetch/relay.js +100 -0
  49. package/dist/browser/fetch/scope.d.ts +8 -0
  50. package/dist/browser/fetch/scope.js +108 -0
  51. package/dist/browser/fetch/transport.d.ts +39 -0
  52. package/dist/browser/fetch/transport.js +136 -0
  53. package/dist/browser/headers/LICENSE-3RD-PARTY.md +9 -0
  54. package/dist/browser/headers/LICENSE-APACHE +177 -0
  55. package/dist/browser/headers/index.d.ts +20 -0
  56. package/dist/browser/headers/index.js +194 -0
  57. package/dist/browser/isolated/bridge.d.ts +8 -0
  58. package/dist/browser/isolated/bridge.js +267 -0
  59. package/dist/browser/isolated/protocol.d.ts +40 -0
  60. package/dist/browser/isolated/protocol.js +1 -0
  61. package/dist/browser/isolated/transport.d.ts +2 -0
  62. package/dist/browser/isolated/transport.js +157 -0
  63. package/dist/browser/request/LICENSE-3RD-PARTY.md +10 -0
  64. package/dist/browser/request/LICENSE-APACHE +177 -0
  65. package/dist/browser/request/index.d.ts +48 -0
  66. package/dist/browser/request/index.js +182 -0
  67. package/dist/browser/response/LICENSE-3RD-PARTY.md +10 -0
  68. package/dist/browser/response/LICENSE-APACHE +177 -0
  69. package/dist/browser/response/index.d.ts +43 -0
  70. package/dist/browser/response/index.js +192 -0
  71. package/dist/browser/response/status.d.ts +1 -0
  72. package/dist/browser/response/status.js +75 -0
  73. package/dist/browser/structured-clone/index.d.ts +1 -0
  74. package/dist/browser/structured-clone/index.js +479 -0
  75. package/dist/cloudflare/apis/cloudflare-node/index.d.ts +18 -0
  76. package/dist/cloudflare/apis/cloudflare-node/index.js +150 -0
  77. package/dist/cloudflare/apis/cloudflare-workers/index.d.ts +8 -0
  78. package/dist/cloudflare/apis/cloudflare-workers/index.js +37 -0
  79. package/dist/cloudflare/apis/types.d.ts +7 -0
  80. package/dist/cloudflare/apis/types.js +1 -0
  81. package/dist/cloudflare/bindings/config.d.ts +42 -0
  82. package/dist/cloudflare/bindings/config.js +280 -0
  83. package/dist/cloudflare/bindings/kv/contract.d.ts +6 -0
  84. package/dist/cloudflare/bindings/kv/contract.js +181 -0
  85. package/dist/cloudflare/bindings/kv/index.d.ts +18 -0
  86. package/dist/cloudflare/bindings/kv/index.js +61 -0
  87. package/dist/cloudflare/bindings/kv/storage.d.ts +25 -0
  88. package/dist/cloudflare/bindings/kv/storage.js +320 -0
  89. package/dist/cloudflare/bindings/kv/types.d.ts +50 -0
  90. package/dist/cloudflare/bindings/kv/types.js +1 -0
  91. package/dist/cloudflare/bindings/remote.d.ts +8 -0
  92. package/dist/cloudflare/bindings/remote.js +261 -0
  93. package/dist/cloudflare/workers/contract.d.ts +8 -0
  94. package/dist/cloudflare/workers/contract.js +65 -0
  95. package/dist/cloudflare/workers/feature.d.ts +10 -0
  96. package/dist/cloudflare/workers/feature.js +28 -0
  97. package/dist/cloudflare/workers/runtime.d.ts +23 -0
  98. package/dist/cloudflare/workers/runtime.js +121 -0
  99. package/dist/cloudflare/workers/types.d.ts +49 -0
  100. package/dist/cloudflare/workers/types.js +1 -0
  101. package/dist/cloudflare/workers/worker-runtime.d.ts +44 -0
  102. package/dist/cloudflare/workers/worker-runtime.js +267 -0
  103. package/dist/compat/assert/LICENSE-3RD-PARTY.md +5 -0
  104. package/dist/compat/assert/LICENSE-APACHE +177 -0
  105. package/dist/compat/assert/assertion-error.d.ts +26 -0
  106. package/dist/compat/assert/assertion-error.js +468 -0
  107. package/dist/compat/assert/diff.d.ts +26 -0
  108. package/dist/compat/assert/diff.js +329 -0
  109. package/dist/compat/assert/errors.d.ts +11 -0
  110. package/dist/compat/assert/errors.js +55 -0
  111. package/dist/compat/assert/index.cjs +24 -0
  112. package/dist/compat/assert/index.d.cts +43 -0
  113. package/dist/compat/assert/index.d.ts +50 -0
  114. package/dist/compat/assert/index.js +858 -0
  115. package/dist/compat/async-hooks/LICENSE-APACHE +177 -0
  116. package/dist/compat/async-hooks/NOTICE.md +8 -0
  117. package/dist/compat/async-hooks/callbacks.d.ts +7 -0
  118. package/dist/compat/async-hooks/callbacks.js +18 -0
  119. package/dist/compat/async-hooks/hooks.d.ts +10 -0
  120. package/dist/compat/async-hooks/hooks.js +111 -0
  121. package/dist/compat/async-hooks/index.d.ts +41 -0
  122. package/dist/compat/async-hooks/index.js +298 -0
  123. package/dist/compat/buffer/LICENSE-3RD-PARTY.md +15 -0
  124. package/dist/compat/buffer/LICENSE-APACHE +177 -0
  125. package/dist/compat/buffer/blob.d.ts +22 -0
  126. package/dist/compat/buffer/blob.js +210 -0
  127. package/dist/compat/buffer/bytes.d.ts +34 -0
  128. package/dist/compat/buffer/bytes.js +228 -0
  129. package/dist/compat/buffer/errors.d.ts +41 -0
  130. package/dist/compat/buffer/errors.js +265 -0
  131. package/dist/compat/buffer/index.d.ts +25 -0
  132. package/dist/compat/buffer/index.js +24 -0
  133. package/dist/compat/buffer/internal-buffer.d.ts +148 -0
  134. package/dist/compat/buffer/internal-buffer.js +1809 -0
  135. package/dist/compat/buffer/support.d.ts +13 -0
  136. package/dist/compat/buffer/support.js +65 -0
  137. package/dist/compat/child-process/LICENSE-3RD-PARTY.md +8 -0
  138. package/dist/compat/child-process/LICENSE-APACHE +177 -0
  139. package/dist/compat/child-process/errors.d.ts +4 -0
  140. package/dist/compat/child-process/errors.js +6 -0
  141. package/dist/compat/child-process/index.d.ts +49 -0
  142. package/dist/compat/child-process/index.js +96 -0
  143. package/dist/compat/cluster/LICENSE-3RD-PARTY.md +40 -0
  144. package/dist/compat/cluster/LICENSE-APACHE +177 -0
  145. package/dist/compat/cluster/errors.d.ts +4 -0
  146. package/dist/compat/cluster/errors.js +6 -0
  147. package/dist/compat/cluster/index.d.ts +47 -0
  148. package/dist/compat/cluster/index.js +88 -0
  149. package/dist/compat/constants/LICENSE-3RD-PARTY.md +6 -0
  150. package/dist/compat/constants/LICENSE-APACHE +177 -0
  151. package/dist/compat/constants/index.d.ts +481 -0
  152. package/dist/compat/constants/index.js +488 -0
  153. package/dist/compat/dgram/LICENSE-3RD-PARTY.md +8 -0
  154. package/dist/compat/dgram/LICENSE-APACHE +177 -0
  155. package/dist/compat/dgram/index.d.ts +10 -0
  156. package/dist/compat/dgram/index.js +132 -0
  157. package/dist/compat/diagnostics-channel/LICENSE-3RD-PARTY.md +13 -0
  158. package/dist/compat/diagnostics-channel/LICENSE-APACHE +177 -0
  159. package/dist/compat/diagnostics-channel/index.d.ts +73 -0
  160. package/dist/compat/diagnostics-channel/index.js +261 -0
  161. package/dist/compat/diagnostics-channel/native.d.ts +26 -0
  162. package/dist/compat/diagnostics-channel/native.js +154 -0
  163. package/dist/compat/dns/LICENSE-3RD-PARTY.md +5 -0
  164. package/dist/compat/dns/LICENSE-APACHE +177 -0
  165. package/dist/compat/dns/client.d.ts +72 -0
  166. package/dist/compat/dns/client.js +161 -0
  167. package/dist/compat/dns/constants.d.ts +27 -0
  168. package/dist/compat/dns/constants.js +31 -0
  169. package/dist/compat/dns/errors.d.ts +8 -0
  170. package/dist/compat/dns/errors.js +12 -0
  171. package/dist/compat/dns/index.d.ts +97 -0
  172. package/dist/compat/dns/index.js +127 -0
  173. package/dist/compat/dns/parser.d.ts +18 -0
  174. package/dist/compat/dns/parser.js +144 -0
  175. package/dist/compat/dns/promise-resolver.d.ts +82 -0
  176. package/dist/compat/dns/promise-resolver.js +113 -0
  177. package/dist/compat/dns/promises.d.ts +50 -0
  178. package/dist/compat/dns/promises.js +53 -0
  179. package/dist/compat/dns/resolver.d.ts +34 -0
  180. package/dist/compat/dns/resolver.js +415 -0
  181. package/dist/compat/domain/LICENSE-3RD-PARTY.md +5 -0
  182. package/dist/compat/domain/LICENSE-APACHE +177 -0
  183. package/dist/compat/domain/index.d.ts +22 -0
  184. package/dist/compat/domain/index.js +79 -0
  185. package/dist/compat/fs/index.d.ts +85 -0
  186. package/dist/compat/fs/index.js +255 -0
  187. package/dist/compat/fs/promises/index.d.ts +3 -0
  188. package/dist/compat/fs/promises/index.js +3 -0
  189. package/dist/compat/http/index.d.ts +322 -0
  190. package/dist/compat/http/index.js +1356 -0
  191. package/dist/compat/http/registry.d.ts +19 -0
  192. package/dist/compat/http/registry.js +13 -0
  193. package/dist/compat/http-agent/LICENSE-3RD-PARTY.md +5 -0
  194. package/dist/compat/http-agent/LICENSE-APACHE +177 -0
  195. package/dist/compat/http-agent/index.d.ts +7 -0
  196. package/dist/compat/http-agent/index.js +10 -0
  197. package/dist/compat/http-client/LICENSE-3RD-PARTY.md +5 -0
  198. package/dist/compat/http-client/LICENSE-APACHE +177 -0
  199. package/dist/compat/http-client/index.d.ts +6 -0
  200. package/dist/compat/http-client/index.js +7 -0
  201. package/dist/compat/http-incoming/LICENSE-3RD-PARTY.md +5 -0
  202. package/dist/compat/http-incoming/LICENSE-APACHE +177 -0
  203. package/dist/compat/http-incoming/index.d.ts +6 -0
  204. package/dist/compat/http-incoming/index.js +9 -0
  205. package/dist/compat/http2/LICENSE-3RD-PARTY.md +29 -0
  206. package/dist/compat/http2/LICENSE-APACHE +177 -0
  207. package/dist/compat/http2/constants.d.ts +255 -0
  208. package/dist/compat/http2/constants.js +515 -0
  209. package/dist/compat/http2/errors.d.ts +4 -0
  210. package/dist/compat/http2/errors.js +6 -0
  211. package/dist/compat/http2/index.d.ts +283 -0
  212. package/dist/compat/http2/index.js +68 -0
  213. package/dist/compat/https/LICENSE-3RD-PARTY.md +5 -0
  214. package/dist/compat/https/LICENSE-APACHE +177 -0
  215. package/dist/compat/https/agent.d.ts +10 -0
  216. package/dist/compat/https/agent.js +99 -0
  217. package/dist/compat/https/errors.d.ts +4 -0
  218. package/dist/compat/https/errors.js +6 -0
  219. package/dist/compat/https/index.d.ts +20 -0
  220. package/dist/compat/https/index.js +50 -0
  221. package/dist/compat/https/server.d.ts +8 -0
  222. package/dist/compat/https/server.js +27 -0
  223. package/dist/compat/immediate/index.d.ts +11 -0
  224. package/dist/compat/immediate/index.js +58 -0
  225. package/dist/compat/inspector/LICENSE-3RD-PARTY.md +34 -0
  226. package/dist/compat/inspector/LICENSE-APACHE +177 -0
  227. package/dist/compat/inspector/errors.d.ts +4 -0
  228. package/dist/compat/inspector/errors.js +6 -0
  229. package/dist/compat/inspector/index.d.ts +18 -0
  230. package/dist/compat/inspector/index.js +117 -0
  231. package/dist/compat/inspector/promises.d.ts +18 -0
  232. package/dist/compat/inspector/promises.js +114 -0
  233. package/dist/compat/module/index.cjs +2 -0
  234. package/dist/compat/module/index.d.cts +2 -0
  235. package/dist/compat/module/index.d.ts +11 -0
  236. package/dist/compat/module/index.js +44 -0
  237. package/dist/compat/module/resolve-unavailable.d.ts +1 -0
  238. package/dist/compat/module/resolve-unavailable.js +3 -0
  239. package/dist/compat/net/LICENSE-3RD-PARTY.md +15 -0
  240. package/dist/compat/net/LICENSE-APACHE +177 -0
  241. package/dist/compat/net/error-base.d.ts +14 -0
  242. package/dist/compat/net/error-base.js +62 -0
  243. package/dist/compat/net/errors.d.ts +76 -0
  244. package/dist/compat/net/errors.js +333 -0
  245. package/dist/compat/net/index.d.ts +23 -0
  246. package/dist/compat/net/index.js +46 -0
  247. package/dist/compat/net/internal-net.d.ts +236 -0
  248. package/dist/compat/net/internal-net.js +2292 -0
  249. package/dist/compat/net/ports.d.ts +32 -0
  250. package/dist/compat/net/ports.js +149 -0
  251. package/dist/compat/net/reader.d.ts +8 -0
  252. package/dist/compat/net/reader.js +36 -0
  253. package/dist/compat/net/sockets.d.ts +20 -0
  254. package/dist/compat/net/sockets.js +195 -0
  255. package/dist/compat/net/validators.d.ts +18 -0
  256. package/dist/compat/net/validators.js +154 -0
  257. package/dist/compat/os/LICENSE-3RD-PARTY.md +8 -0
  258. package/dist/compat/os/LICENSE-APACHE +177 -0
  259. package/dist/compat/os/index.d.ts +329 -0
  260. package/dist/compat/os/index.js +278 -0
  261. package/dist/compat/path/LICENSE-3RD-PARTY.md +35 -0
  262. package/dist/compat/path/LICENSE-APACHE +177 -0
  263. package/dist/compat/path/index.d.ts +4 -0
  264. package/dist/compat/path/index.js +11 -0
  265. package/dist/compat/path/internal-path.d.ts +95 -0
  266. package/dist/compat/path/internal-path.js +1542 -0
  267. package/dist/compat/path/posix/index.d.ts +4 -0
  268. package/dist/compat/path/posix/index.js +5 -0
  269. package/dist/compat/path/win32/index.d.ts +4 -0
  270. package/dist/compat/path/win32/index.js +5 -0
  271. package/dist/compat/perf-hooks/LICENSE-3RD-PARTY.md +5 -0
  272. package/dist/compat/perf-hooks/LICENSE-APACHE +177 -0
  273. package/dist/compat/perf-hooks/index.d.ts +85 -0
  274. package/dist/compat/perf-hooks/index.js +79 -0
  275. package/dist/compat/perf-hooks/performance.d.ts +96 -0
  276. package/dist/compat/perf-hooks/performance.js +445 -0
  277. package/dist/compat/punycode/LICENSE-3RD-PARTY.md +7 -0
  278. package/dist/compat/punycode/LICENSE-APACHE +177 -0
  279. package/dist/compat/punycode/index.d.ts +93 -0
  280. package/dist/compat/punycode/index.js +410 -0
  281. package/dist/compat/querystring/LICENSE-3RD-PARTY.md +35 -0
  282. package/dist/compat/querystring/LICENSE-APACHE +177 -0
  283. package/dist/compat/querystring/index.d.ts +14 -0
  284. package/dist/compat/querystring/index.js +18 -0
  285. package/dist/compat/querystring/internal-querystring.d.ts +22 -0
  286. package/dist/compat/querystring/internal-querystring.js +498 -0
  287. package/dist/compat/readline/LICENSE-3RD-PARTY.md +37 -0
  288. package/dist/compat/readline/LICENSE-APACHE +177 -0
  289. package/dist/compat/readline/index.d.ts +21 -0
  290. package/dist/compat/readline/index.js +56 -0
  291. package/dist/compat/readline/interface.d.ts +22 -0
  292. package/dist/compat/readline/interface.js +85 -0
  293. package/dist/compat/readline/internal-promises.d.ts +32 -0
  294. package/dist/compat/readline/internal-promises.js +104 -0
  295. package/dist/compat/readline/promises.d.ts +8 -0
  296. package/dist/compat/readline/promises.js +32 -0
  297. package/dist/compat/repl/LICENSE-3RD-PARTY.md +5 -0
  298. package/dist/compat/repl/LICENSE-APACHE +177 -0
  299. package/dist/compat/repl/builtin-modules.d.ts +1 -0
  300. package/dist/compat/repl/builtin-modules.js +101 -0
  301. package/dist/compat/repl/errors.d.ts +4 -0
  302. package/dist/compat/repl/errors.js +6 -0
  303. package/dist/compat/repl/index.d.ts +53 -0
  304. package/dist/compat/repl/index.js +106 -0
  305. package/dist/compat/sqlite/LICENSE-3RD-PARTY.md +6 -0
  306. package/dist/compat/sqlite/LICENSE-APACHE +177 -0
  307. package/dist/compat/sqlite/index.d.ts +12 -0
  308. package/dist/compat/sqlite/index.js +101 -0
  309. package/dist/compat/sqlite/native.d.ts +16 -0
  310. package/dist/compat/sqlite/native.js +33 -0
  311. package/dist/compat/stream/LICENSE-3RD-PARTY.md +13 -0
  312. package/dist/compat/stream/LICENSE-APACHE +177 -0
  313. package/dist/compat/stream/add-abort-signal.d.ts +4 -0
  314. package/dist/compat/stream/add-abort-signal.js +73 -0
  315. package/dist/compat/stream/compose.d.ts +1 -0
  316. package/dist/compat/stream/compose.js +313 -0
  317. package/dist/compat/stream/destroy.d.ts +5 -0
  318. package/dist/compat/stream/destroy.js +315 -0
  319. package/dist/compat/stream/duplex.d.ts +48 -0
  320. package/dist/compat/stream/duplex.js +789 -0
  321. package/dist/compat/stream/end-of-stream.d.ts +16 -0
  322. package/dist/compat/stream/end-of-stream.js +269 -0
  323. package/dist/compat/stream/errors.d.ts +40 -0
  324. package/dist/compat/stream/errors.js +86 -0
  325. package/dist/compat/stream/events.d.ts +6 -0
  326. package/dist/compat/stream/events.js +28 -0
  327. package/dist/compat/stream/index.cjs +27 -0
  328. package/dist/compat/stream/index.d.cts +25 -0
  329. package/dist/compat/stream/index.d.ts +20 -0
  330. package/dist/compat/stream/index.js +55 -0
  331. package/dist/compat/stream/legacy.d.ts +8 -0
  332. package/dist/compat/stream/legacy.js +105 -0
  333. package/dist/compat/stream/once.d.ts +7 -0
  334. package/dist/compat/stream/once.js +13 -0
  335. package/dist/compat/stream/pipeline.d.ts +5 -0
  336. package/dist/compat/stream/pipeline.js +567 -0
  337. package/dist/compat/stream/process.d.ts +1 -0
  338. package/dist/compat/stream/process.js +4 -0
  339. package/dist/compat/stream/promises.d.ts +7 -0
  340. package/dist/compat/stream/promises.js +60 -0
  341. package/dist/compat/stream/readable.d.ts +29 -0
  342. package/dist/compat/stream/readable.js +2267 -0
  343. package/dist/compat/stream/state.d.ts +8 -0
  344. package/dist/compat/stream/state.js +63 -0
  345. package/dist/compat/stream/transform.d.ts +2 -0
  346. package/dist/compat/stream/transform.js +202 -0
  347. package/dist/compat/stream/util.d.ts +55 -0
  348. package/dist/compat/stream/util.js +345 -0
  349. package/dist/compat/stream/validators.d.ts +2 -0
  350. package/dist/compat/stream/validators.js +14 -0
  351. package/dist/compat/stream/writable.d.ts +21 -0
  352. package/dist/compat/stream/writable.js +1325 -0
  353. package/dist/compat/stream-consumers/LICENSE-3RD-PARTY.md +5 -0
  354. package/dist/compat/stream-consumers/LICENSE-APACHE +177 -0
  355. package/dist/compat/stream-consumers/index.d.ts +14 -0
  356. package/dist/compat/stream-consumers/index.js +62 -0
  357. package/dist/compat/stream-consumers/iterable.d.ts +1 -0
  358. package/dist/compat/stream-consumers/iterable.js +34 -0
  359. package/dist/compat/stream-duplex/LICENSE-3RD-PARTY.md +13 -0
  360. package/dist/compat/stream-duplex/LICENSE-APACHE +177 -0
  361. package/dist/compat/stream-duplex/index.cjs +3 -0
  362. package/dist/compat/stream-duplex/index.d.cts +2 -0
  363. package/dist/compat/stream-duplex/index.d.ts +3 -0
  364. package/dist/compat/stream-duplex/index.js +8 -0
  365. package/dist/compat/stream-passthrough/LICENSE-3RD-PARTY.md +13 -0
  366. package/dist/compat/stream-passthrough/LICENSE-APACHE +177 -0
  367. package/dist/compat/stream-passthrough/index.cjs +3 -0
  368. package/dist/compat/stream-passthrough/index.d.cts +2 -0
  369. package/dist/compat/stream-passthrough/index.d.ts +3 -0
  370. package/dist/compat/stream-passthrough/index.js +8 -0
  371. package/dist/compat/stream-promises/LICENSE-3RD-PARTY.md +13 -0
  372. package/dist/compat/stream-promises/LICENSE-APACHE +177 -0
  373. package/dist/compat/stream-promises/index.d.ts +1 -0
  374. package/dist/compat/stream-promises/index.js +1 -0
  375. package/dist/compat/stream-readable/LICENSE-3RD-PARTY.md +13 -0
  376. package/dist/compat/stream-readable/LICENSE-APACHE +177 -0
  377. package/dist/compat/stream-readable/index.cjs +3 -0
  378. package/dist/compat/stream-readable/index.d.cts +2 -0
  379. package/dist/compat/stream-readable/index.d.ts +3 -0
  380. package/dist/compat/stream-readable/index.js +8 -0
  381. package/dist/compat/stream-transform/LICENSE-3RD-PARTY.md +13 -0
  382. package/dist/compat/stream-transform/LICENSE-APACHE +177 -0
  383. package/dist/compat/stream-transform/index.cjs +3 -0
  384. package/dist/compat/stream-transform/index.d.cts +2 -0
  385. package/dist/compat/stream-transform/index.d.ts +3 -0
  386. package/dist/compat/stream-transform/index.js +8 -0
  387. package/dist/compat/stream-web/LICENSE-MIT +22 -0
  388. package/dist/compat/stream-web/NOTICE.md +3 -0
  389. package/dist/compat/stream-web/context.d.ts +2 -0
  390. package/dist/compat/stream-web/context.js +35 -0
  391. package/dist/compat/stream-web/index.d.ts +80 -0
  392. package/dist/compat/stream-web/index.js +129 -0
  393. package/dist/compat/stream-web/interop.d.ts +6 -0
  394. package/dist/compat/stream-web/interop.js +72 -0
  395. package/dist/compat/stream-web/ponyfill.d.ts +1 -0
  396. package/dist/compat/stream-web/ponyfill.js +2093 -0
  397. package/dist/compat/stream-web/runtime.d.ts +16 -0
  398. package/dist/compat/stream-web/runtime.js +51 -0
  399. package/dist/compat/stream-writable/LICENSE-3RD-PARTY.md +13 -0
  400. package/dist/compat/stream-writable/LICENSE-APACHE +177 -0
  401. package/dist/compat/stream-writable/index.cjs +3 -0
  402. package/dist/compat/stream-writable/index.d.cts +2 -0
  403. package/dist/compat/stream-writable/index.d.ts +3 -0
  404. package/dist/compat/stream-writable/index.js +8 -0
  405. package/dist/compat/string-decoder/LICENSE-3RD-PARTY.md +38 -0
  406. package/dist/compat/string-decoder/LICENSE-APACHE +177 -0
  407. package/dist/compat/string-decoder/index.d.ts +33 -0
  408. package/dist/compat/string-decoder/index.js +518 -0
  409. package/dist/compat/test/LICENSE-3RD-PARTY.md +37 -0
  410. package/dist/compat/test/LICENSE-APACHE +177 -0
  411. package/dist/compat/test/index.d.ts +9 -0
  412. package/dist/compat/test/index.js +11 -0
  413. package/dist/compat/test/mock.d.ts +103 -0
  414. package/dist/compat/test/mock.js +397 -0
  415. package/dist/compat/test/validators.d.ts +2 -0
  416. package/dist/compat/test/validators.js +14 -0
  417. package/dist/compat/timers/LICENSE-3RD-PARTY.md +7 -0
  418. package/dist/compat/timers/LICENSE-APACHE +177 -0
  419. package/dist/compat/timers/errors.d.ts +28 -0
  420. package/dist/compat/timers/errors.js +206 -0
  421. package/dist/compat/timers/host.d.ts +11 -0
  422. package/dist/compat/timers/host.js +60 -0
  423. package/dist/compat/timers/index.cjs +3 -0
  424. package/dist/compat/timers/index.d.cts +23 -0
  425. package/dist/compat/timers/index.d.ts +36 -0
  426. package/dist/compat/timers/index.js +20 -0
  427. package/dist/compat/timers/installation.d.ts +4 -0
  428. package/dist/compat/timers/installation.js +61 -0
  429. package/dist/compat/timers/internal-promises.d.ts +19 -0
  430. package/dist/compat/timers/internal-promises.js +173 -0
  431. package/dist/compat/timers/promises.cjs +2 -0
  432. package/dist/compat/timers/promises.d.cts +12 -0
  433. package/dist/compat/timers/promises.d.ts +14 -0
  434. package/dist/compat/timers/promises.js +3 -0
  435. package/dist/compat/timers/timers.d.ts +32 -0
  436. package/dist/compat/timers/timers.js +147 -0
  437. package/dist/compat/timers/validation.d.ts +5 -0
  438. package/dist/compat/timers/validation.js +22 -0
  439. package/dist/compat/timers/wait.d.ts +4 -0
  440. package/dist/compat/timers/wait.js +91 -0
  441. package/dist/compat/tls-common/LICENSE-3RD-PARTY.md +11 -0
  442. package/dist/compat/tls-common/LICENSE-APACHE +177 -0
  443. package/dist/compat/tls-common/index.d.ts +14 -0
  444. package/dist/compat/tls-common/index.js +88 -0
  445. package/dist/compat/trace-events/LICENSE-3RD-PARTY.md +5 -0
  446. package/dist/compat/trace-events/LICENSE-APACHE +177 -0
  447. package/dist/compat/trace-events/index.d.ts +18 -0
  448. package/dist/compat/trace-events/index.js +88 -0
  449. package/dist/compat/tty/LICENSE-3RD-PARTY.md +8 -0
  450. package/dist/compat/tty/LICENSE-APACHE +177 -0
  451. package/dist/compat/tty/index.d.ts +17 -0
  452. package/dist/compat/tty/index.js +101 -0
  453. package/dist/compat/url/LICENSE-3RD-PARTY.md +63 -0
  454. package/dist/compat/url/LICENSE-ADA +18 -0
  455. package/dist/compat/url/LICENSE-APACHE +177 -0
  456. package/dist/compat/url/LICENSE-UNICODE +39 -0
  457. package/dist/compat/url/LICENSE-WHATWG-URL +21 -0
  458. package/dist/compat/url/brand.d.ts +4 -0
  459. package/dist/compat/url/brand.js +10 -0
  460. package/dist/compat/url/constants.d.ts +27 -0
  461. package/dist/compat/url/constants.js +28 -0
  462. package/dist/compat/url/errors.d.ts +44 -0
  463. package/dist/compat/url/errors.js +248 -0
  464. package/dist/compat/url/idna-data.d.ts +3958 -0
  465. package/dist/compat/url/idna-data.js +22 -0
  466. package/dist/compat/url/idna.d.ts +9 -0
  467. package/dist/compat/url/idna.js +47 -0
  468. package/dist/compat/url/index.d.ts +48 -0
  469. package/dist/compat/url/index.js +39 -0
  470. package/dist/compat/url/installation.d.ts +4 -0
  471. package/dist/compat/url/installation.js +61 -0
  472. package/dist/compat/url/internal-url.d.ts +34 -0
  473. package/dist/compat/url/internal-url.js +264 -0
  474. package/dist/compat/url/legacy-url.d.ts +28 -0
  475. package/dist/compat/url/legacy-url.js +870 -0
  476. package/dist/compat/url/parser-platform.d.ts +3 -0
  477. package/dist/compat/url/parser-platform.js +26 -0
  478. package/dist/compat/url/standard-url.d.ts +2 -0
  479. package/dist/compat/url/standard-url.js +3189 -0
  480. package/dist/compat/url/unicode.d.ts +2 -0
  481. package/dist/compat/url/unicode.js +119 -0
  482. package/dist/compat/url/validation.d.ts +2 -0
  483. package/dist/compat/url/validation.js +9 -0
  484. package/dist/compat/url/web-url.d.ts +27 -0
  485. package/dist/compat/url/web-url.js +119 -0
  486. package/dist/compat/util/LICENSE-3RD-PARTY.md +5 -0
  487. package/dist/compat/util/LICENSE-APACHE +177 -0
  488. package/dist/compat/util/additional.d.ts +11 -0
  489. package/dist/compat/util/additional.js +121 -0
  490. package/dist/compat/util/comparison-types.d.ts +16 -0
  491. package/dist/compat/util/comparison-types.js +50 -0
  492. package/dist/compat/util/comparisons.d.ts +1 -0
  493. package/dist/compat/util/comparisons.js +527 -0
  494. package/dist/compat/util/core.d.ts +18 -0
  495. package/dist/compat/util/core.js +265 -0
  496. package/dist/compat/util/debuglog.d.ts +1 -0
  497. package/dist/compat/util/debuglog.js +78 -0
  498. package/dist/compat/util/index.d.ts +35 -0
  499. package/dist/compat/util/index.js +77 -0
  500. package/dist/compat/util/inspect-binding.d.ts +13 -0
  501. package/dist/compat/util/inspect-binding.js +39 -0
  502. package/dist/compat/util/inspect-types.d.ts +13 -0
  503. package/dist/compat/util/inspect-types.js +30 -0
  504. package/dist/compat/util/inspect.d.ts +152 -0
  505. package/dist/compat/util/inspect.js +2503 -0
  506. package/dist/compat/util/mime.d.ts +24 -0
  507. package/dist/compat/util/mime.js +284 -0
  508. package/dist/compat/util/properties.d.ts +9 -0
  509. package/dist/compat/util/properties.js +76 -0
  510. package/dist/compat/v8/LICENSE-3RD-PARTY.md +6 -0
  511. package/dist/compat/v8/LICENSE-APACHE +177 -0
  512. package/dist/compat/v8/errors.d.ts +5 -0
  513. package/dist/compat/v8/errors.js +7 -0
  514. package/dist/compat/v8/index.d.ts +106 -0
  515. package/dist/compat/v8/index.js +280 -0
  516. package/dist/compat/vm/LICENSE-3RD-PARTY.md +39 -0
  517. package/dist/compat/vm/LICENSE-APACHE +177 -0
  518. package/dist/compat/vm/errors.d.ts +5 -0
  519. package/dist/compat/vm/errors.js +7 -0
  520. package/dist/compat/vm/index.d.ts +47 -0
  521. package/dist/compat/vm/index.js +231 -0
  522. package/dist/compat/vm/validation.d.ts +3 -0
  523. package/dist/compat/vm/validation.js +14 -0
  524. package/dist/compat/wasi/LICENSE-3RD-PARTY.md +8 -0
  525. package/dist/compat/wasi/LICENSE-APACHE +177 -0
  526. package/dist/compat/wasi/errors.d.ts +4 -0
  527. package/dist/compat/wasi/errors.js +6 -0
  528. package/dist/compat/wasi/index.d.ts +15 -0
  529. package/dist/compat/wasi/index.js +44 -0
  530. package/dist/compat/worker-threads/LICENSE-3RD-PARTY.md +5 -0
  531. package/dist/compat/worker-threads/LICENSE-APACHE +177 -0
  532. package/dist/compat/worker-threads/errors.d.ts +4 -0
  533. package/dist/compat/worker-threads/errors.js +6 -0
  534. package/dist/compat/worker-threads/index.d.ts +71 -0
  535. package/dist/compat/worker-threads/index.js +138 -0
  536. package/dist/compat/worker-threads/message-channel.d.ts +18 -0
  537. package/dist/compat/worker-threads/message-channel.js +157 -0
  538. package/dist/configured.d.ts +3 -0
  539. package/dist/configured.js +4 -0
  540. package/dist/environment.d.ts +4 -0
  541. package/dist/environment.js +18 -0
  542. package/dist/index.d.ts +11 -0
  543. package/dist/index.js +107 -0
  544. package/dist/ios.d.ts +2 -0
  545. package/dist/ios.js +1 -0
  546. package/dist/native-entry.d.ts +8 -0
  547. package/dist/native-entry.js +67 -0
  548. package/dist/shared/brotli/LICENSE-APACHE +201 -0
  549. package/dist/shared/brotli/LICENSE-MIT +9 -0
  550. package/dist/shared/brotli/NOTICE +3 -0
  551. package/dist/shared/brotli/index.d.ts +2 -0
  552. package/dist/shared/brotli/index.js +288 -0
  553. package/dist/shared/contracts/index.d.ts +42 -0
  554. package/dist/shared/contracts/index.js +88 -0
  555. package/dist/shared/contracts/testing.d.ts +22 -0
  556. package/dist/shared/contracts/testing.js +57 -0
  557. package/dist/shared/globals/index.d.ts +3 -0
  558. package/dist/shared/globals/index.js +87 -0
  559. package/dist/shared/globals/inject.d.ts +2 -0
  560. package/dist/shared/globals/inject.js +3 -0
  561. package/dist/shared/globals/install.d.ts +1 -0
  562. package/dist/shared/globals/install.js +15 -0
  563. package/dist/shared/globals/node-install.d.ts +1 -0
  564. package/dist/shared/globals/node-install.js +4 -0
  565. package/dist/shared/globals/platform.d.ts +104 -0
  566. package/dist/shared/globals/platform.js +37 -0
  567. package/dist/shared/globals/runtime.d.ts +6 -0
  568. package/dist/shared/globals/runtime.js +8 -0
  569. package/dist/shared/globals/symbols.d.ts +4 -0
  570. package/dist/shared/globals/symbols.js +35 -0
  571. package/dist/shared/globals/web.d.ts +4 -0
  572. package/dist/shared/globals/web.js +108 -0
  573. package/dist/shared/http-wire/LICENSE.llhttp +22 -0
  574. package/dist/shared/http-wire/LICENSE.undici +21 -0
  575. package/dist/shared/http-wire/NOTICE.md +14 -0
  576. package/dist/shared/http-wire/index.d.ts +27 -0
  577. package/dist/shared/http-wire/index.js +132 -0
  578. package/dist/shared/http-wire/wasm.d.ts +2 -0
  579. package/dist/shared/http-wire/wasm.js +2 -0
  580. package/dist/tooling/async.d.ts +7 -0
  581. package/dist/tooling/async.js +99 -0
  582. package/dist/tooling/build-isolation.d.ts +4 -0
  583. package/dist/tooling/build-isolation.js +34 -0
  584. package/dist/tooling/documents.d.ts +7 -0
  585. package/dist/tooling/documents.js +26 -0
  586. package/dist/tooling/esbuild.d.ts +15 -0
  587. package/dist/tooling/esbuild.js +193 -0
  588. package/dist/tooling/files.d.ts +2 -0
  589. package/dist/tooling/files.js +18 -0
  590. package/dist/tooling/opennext/build.d.ts +1 -0
  591. package/dist/tooling/opennext/build.js +121 -0
  592. package/dist/tooling/opennext/index.d.ts +3 -0
  593. package/dist/tooling/opennext/index.js +213 -0
  594. package/dist/tooling/opennext/plan.d.ts +9 -0
  595. package/dist/tooling/opennext/plan.js +36 -0
  596. package/dist/tooling/opennext/safety.d.ts +4 -0
  597. package/dist/tooling/opennext/safety.js +36 -0
  598. package/dist/tooling/route-permissions.d.ts +3 -0
  599. package/dist/tooling/route-permissions.js +15 -0
  600. package/dist/tooling/server-modules.d.ts +30 -0
  601. package/dist/tooling/server-modules.js +98 -0
  602. package/dist/tooling/server-only-html.d.ts +1 -0
  603. package/dist/tooling/server-only-html.js +66 -0
  604. package/dist/tooling/server-only.d.ts +6 -0
  605. package/dist/tooling/server-only.js +53 -0
  606. package/dist/tooling/server.d.ts +25 -0
  607. package/dist/tooling/server.js +981 -0
  608. package/dist/tooling/shared.d.ts +13 -0
  609. package/dist/tooling/shared.js +130 -0
  610. package/dist/tooling/vite.d.ts +18 -0
  611. package/dist/tooling/vite.js +448 -0
  612. package/dist/tooling/void/index.d.ts +3 -0
  613. package/dist/tooling/void/index.js +205 -0
  614. package/dist/tooling/void/plan.d.ts +17 -0
  615. package/dist/tooling/void/plan.js +288 -0
  616. package/native/android/build.gradle +68 -0
  617. package/native/android/consumer-rules.pro +2 -0
  618. package/native/android/src/main/AndroidManifest.xml +6 -0
  619. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +202 -0
  620. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +256 -0
  621. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNative.java +22 -0
  622. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeActivity.java +178 -0
  623. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeBridge.java +45 -0
  624. package/native/ios/DocumentBridge.swift +330 -0
  625. package/native/ios/NetworkBridge.swift +51 -0
  626. package/native/ios/SocketBridge.swift +180 -0
  627. package/native/ios/WorkersCapacitorPlugin.swift +152 -0
  628. package/native/ios-host/WorkersView.swift +194 -0
  629. package/package.json +154 -4
@@ -0,0 +1,870 @@
1
+ import { isURLInstance } from "./web-url.js";
2
+ // Copyright (c) 2026 Cloudflare, Inc.
3
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
4
+ // https://opensource.org/licenses/Apache-2.0
5
+ import { validateString, validateObject } from "./validation.js";
6
+ import { CHAR_SPACE, CHAR_TAB, CHAR_CARRIAGE_RETURN, CHAR_LINE_FEED, CHAR_NO_BREAK_SPACE, CHAR_ZERO_WIDTH_NOBREAK_SPACE, CHAR_HASH, CHAR_FORWARD_SLASH, CHAR_LEFT_SQUARE_BRACKET, CHAR_RIGHT_SQUARE_BRACKET, CHAR_LEFT_ANGLE_BRACKET, CHAR_RIGHT_ANGLE_BRACKET, CHAR_LEFT_CURLY_BRACKET, CHAR_RIGHT_CURLY_BRACKET, CHAR_QUESTION_MARK, CHAR_DOUBLE_QUOTE, CHAR_SINGLE_QUOTE, CHAR_PERCENT, CHAR_SEMICOLON, CHAR_BACKWARD_SLASH, CHAR_CIRCUMFLEX_ACCENT, CHAR_GRAVE_ACCENT, CHAR_VERTICAL_LINE, CHAR_AT, CHAR_COLON, } from "./constants.js";
7
+ import { parse as querystringParse, stringify as querystringStringify, encodeStr, hexTable, } from "../querystring/internal-querystring.js";
8
+ import { slashedProtocol, hostlessProtocol, unsafeProtocol, } from "./internal-url.js";
9
+ import { ERR_INVALID_URL, ERR_INVALID_ARG_TYPE } from "./errors.js";
10
+ import { default as urlUtil } from "./idna.js";
11
+ function spliceOne(array, index) {
12
+ array.splice(index, 1);
13
+ }
14
+ // Reference: RFC 3986, RFC 1808, RFC 2396
15
+ // define these here so at least they only have to be
16
+ // compiled once on the first module load.
17
+ const protocolPattern = /^[a-z0-9.+-]+:/i;
18
+ const portPattern = /:[0-9]*$/;
19
+ const hostPattern = /^\/\/[^@/]+@[^@/]+/;
20
+ // Special case for a simple path URL
21
+ const simplePathPattern = /^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/;
22
+ const hostnameMaxLen = 255;
23
+ // This prevents some common spoofing bugs due to our use of IDNA toASCII. For
24
+ // compatibility, the set of characters we use here is the *intersection* of
25
+ // "forbidden host code point" in the WHATWG URL Standard [1] and the
26
+ // characters in the host parsing loop in Url.prototype.parse, with the
27
+ // following additions:
28
+ //
29
+ // - ':' since this could cause a "protocol spoofing" bug
30
+ // - '@' since this could cause parts of the hostname to be confused with auth
31
+ // - '[' and ']' since this could cause a non-IPv6 hostname to be interpreted
32
+ // as IPv6 by isIpv6Hostname above
33
+ //
34
+ // [1]: https://url.spec.whatwg.org/#forbidden-host-code-point
35
+ const forbiddenHostChars = /[\0\t\n\r #%/:<>?@[\\\]^|]/;
36
+ // For IPv6, permit '[', ']', and ':'.
37
+ const forbiddenHostCharsIpv6 = /[\0\t\n\r #%/<>?@\\^|]/;
38
+ function getHostname(self, rest, hostname) {
39
+ for (let i = 0; i < hostname.length; ++i) {
40
+ const code = hostname.charCodeAt(i);
41
+ const isValid = code !== CHAR_FORWARD_SLASH &&
42
+ code !== CHAR_BACKWARD_SLASH &&
43
+ code !== CHAR_HASH &&
44
+ code !== CHAR_QUESTION_MARK &&
45
+ code !== CHAR_COLON;
46
+ if (!isValid) {
47
+ self.hostname = hostname.slice(0, i);
48
+ return `/${hostname.slice(i)}${rest}`;
49
+ }
50
+ }
51
+ return rest;
52
+ }
53
+ function isIpv6Hostname(hostname) {
54
+ return (hostname.charCodeAt(0) === CHAR_LEFT_SQUARE_BRACKET &&
55
+ hostname.charCodeAt(hostname.length - 1) === CHAR_RIGHT_SQUARE_BRACKET);
56
+ }
57
+ // Escaped characters. Use empty strings to fill up unused entries.
58
+ // Using Array is faster than Object/Map
59
+ // prettier-ignore
60
+ const escapedCodes = [
61
+ /* 0 - 9 */ '', '', '', '', '', '', '', '', '', '%09',
62
+ /* 10 - 19 */ '%0A', '', '', '%0D', '', '', '', '', '', '',
63
+ /* 20 - 29 */ '', '', '', '', '', '', '', '', '', '',
64
+ /* 30 - 39 */ '', '', '%20', '', '%22', '', '', '', '', '%27',
65
+ /* 40 - 49 */ '', '', '', '', '', '', '', '', '', '',
66
+ /* 50 - 59 */ '', '', '', '', '', '', '', '', '', '',
67
+ /* 60 - 69 */ '%3C', '', '%3E', '', '', '', '', '', '', '',
68
+ /* 70 - 79 */ '', '', '', '', '', '', '', '', '', '',
69
+ /* 80 - 89 */ '', '', '', '', '', '', '', '', '', '',
70
+ /* 90 - 99 */ '', '', '%5C', '', '%5E', '', '%60', '', '', '',
71
+ /* 100 - 109 */ '', '', '', '', '', '', '', '', '', '',
72
+ /* 110 - 119 */ '', '', '', '', '', '', '', '', '', '',
73
+ /* 120 - 125 */ '', '', '', '%7B', '%7C', '%7D',
74
+ ];
75
+ // Automatically escape all delimiters and unwise characters from RFC 2396.
76
+ // Also escape single quotes in case of an XSS attack.
77
+ // Return the escaped string.
78
+ function autoEscapeStr(rest) {
79
+ let escaped = "";
80
+ let lastEscapedPos = 0;
81
+ for (let i = 0; i < rest.length; ++i) {
82
+ // `escaped` contains substring up to the last escaped character.
83
+ const escapedChar = escapedCodes[rest.charCodeAt(i)];
84
+ if (escapedChar) {
85
+ // Concat if there are ordinary characters in the middle.
86
+ if (i > lastEscapedPos)
87
+ escaped += rest.slice(lastEscapedPos, i);
88
+ escaped += escapedChar;
89
+ lastEscapedPos = i + 1;
90
+ }
91
+ }
92
+ if (lastEscapedPos === 0)
93
+ // Nothing has been escaped.
94
+ return rest;
95
+ // There are ordinary characters at the end.
96
+ if (lastEscapedPos < rest.length)
97
+ escaped += rest.slice(lastEscapedPos);
98
+ return escaped;
99
+ }
100
+ export const Url = function Url() {
101
+ this.protocol = null;
102
+ this.slashes = null;
103
+ this.auth = null;
104
+ this.host = null;
105
+ this.port = null;
106
+ this.hostname = null;
107
+ this.hash = null;
108
+ this.search = null;
109
+ this.query = null;
110
+ this.pathname = null;
111
+ this.path = null;
112
+ this.href = null;
113
+ };
114
+ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
115
+ validateString(url, "url");
116
+ // Copy chrome, IE, opera backslash-handling behavior.
117
+ // Backslashes before the query string get converted to forward slashes
118
+ // See: https://code.google.com/p/chromium/issues/detail?id=25916
119
+ let hasHash = false;
120
+ let hasAt = false;
121
+ let start = -1;
122
+ let end = -1;
123
+ let rest = "";
124
+ let lastPos = 0;
125
+ for (let i = 0, inWs = false, split = false; i < url.length; ++i) {
126
+ const code = url.charCodeAt(i);
127
+ // Find first and last non-whitespace characters for trimming
128
+ const isWs = code < 33 ||
129
+ code === CHAR_NO_BREAK_SPACE ||
130
+ code === CHAR_ZERO_WIDTH_NOBREAK_SPACE;
131
+ if (start === -1) {
132
+ if (isWs)
133
+ continue;
134
+ lastPos = start = i;
135
+ }
136
+ else if (inWs) {
137
+ if (!isWs) {
138
+ end = -1;
139
+ inWs = false;
140
+ }
141
+ }
142
+ else if (isWs) {
143
+ end = i;
144
+ inWs = true;
145
+ }
146
+ // Only convert backslashes while we haven't seen a split character
147
+ if (!split) {
148
+ switch (code) {
149
+ case CHAR_AT:
150
+ hasAt = true;
151
+ break;
152
+ case CHAR_HASH:
153
+ hasHash = true;
154
+ split = true;
155
+ break;
156
+ case CHAR_QUESTION_MARK:
157
+ split = true;
158
+ break;
159
+ case CHAR_BACKWARD_SLASH:
160
+ if (i - lastPos > 0)
161
+ rest += url.slice(lastPos, i);
162
+ rest += "/";
163
+ lastPos = i + 1;
164
+ break;
165
+ }
166
+ }
167
+ else if (!hasHash && code === CHAR_HASH) {
168
+ hasHash = true;
169
+ }
170
+ }
171
+ // Check if string was non-empty (including strings with only whitespace)
172
+ if (start !== -1) {
173
+ if (lastPos === start) {
174
+ // We didn't convert any backslashes
175
+ if (end === -1) {
176
+ if (start === 0)
177
+ rest = url;
178
+ else
179
+ rest = url.slice(start);
180
+ }
181
+ else {
182
+ rest = url.slice(start, end);
183
+ }
184
+ }
185
+ else if (end === -1 && lastPos < url.length) {
186
+ // We converted some backslashes and have only part of the entire string
187
+ rest += url.slice(lastPos);
188
+ }
189
+ else if (end !== -1 && lastPos < end) {
190
+ // We converted some backslashes and have only part of the entire string
191
+ rest += url.slice(lastPos, end);
192
+ }
193
+ }
194
+ if (!slashesDenoteHost && !hasHash && !hasAt) {
195
+ // Try fast path regexp
196
+ const simplePath = simplePathPattern.exec(rest);
197
+ if (simplePath) {
198
+ this.path = rest;
199
+ this.href = rest;
200
+ this.pathname = simplePath[1];
201
+ if (simplePath[2]) {
202
+ this.search = simplePath[2];
203
+ if (parseQueryString) {
204
+ this.query = querystringParse(this.search.slice(1));
205
+ }
206
+ else {
207
+ this.query = this.search.slice(1);
208
+ }
209
+ }
210
+ else if (parseQueryString) {
211
+ this.search = null;
212
+ this.query = { __proto__: null };
213
+ }
214
+ return this;
215
+ }
216
+ }
217
+ let proto = protocolPattern.exec(rest);
218
+ let lowerProto;
219
+ if (proto) {
220
+ proto = proto[0];
221
+ lowerProto = proto.toLowerCase();
222
+ this.protocol = lowerProto;
223
+ rest = rest.slice(proto.length);
224
+ }
225
+ // Figure out if it's got a host
226
+ // user@server is *always* interpreted as a hostname, and url
227
+ // resolution will treat //foo/bar as host=foo,path=bar because that's
228
+ // how the browser resolves relative URLs.
229
+ let slashes;
230
+ if (slashesDenoteHost || proto || hostPattern.test(rest)) {
231
+ slashes =
232
+ rest.charCodeAt(0) === CHAR_FORWARD_SLASH &&
233
+ rest.charCodeAt(1) === CHAR_FORWARD_SLASH;
234
+ if (slashes && !(proto && hostlessProtocol.has(lowerProto))) {
235
+ rest = rest.slice(2);
236
+ this.slashes = true;
237
+ }
238
+ }
239
+ if (!hostlessProtocol.has(lowerProto) &&
240
+ (slashes || (proto && !slashedProtocol.has(proto)))) {
241
+ // there's a hostname.
242
+ // the first instance of /, ?, ;, or # ends the host.
243
+ //
244
+ // If there is an @ in the hostname, then non-host chars *are* allowed
245
+ // to the left of the last @ sign, unless some host-ending character
246
+ // comes *before* the @-sign.
247
+ // URLs are obnoxious.
248
+ //
249
+ // ex:
250
+ // http://a@b@c/ => user:a@b host:c
251
+ // http://a@b?@c => user:a host:b path:/?@c
252
+ let hostEnd = -1;
253
+ let atSign = -1;
254
+ let nonHost = -1;
255
+ for (let i = 0; i < rest.length; ++i) {
256
+ switch (rest.charCodeAt(i)) {
257
+ case CHAR_TAB:
258
+ case CHAR_LINE_FEED:
259
+ case CHAR_CARRIAGE_RETURN:
260
+ // WHATWG URL removes tabs, newlines, and carriage returns. Let's do that too.
261
+ rest = rest.slice(0, i) + rest.slice(i + 1);
262
+ i -= 1;
263
+ break;
264
+ case CHAR_SPACE:
265
+ case CHAR_DOUBLE_QUOTE:
266
+ case CHAR_PERCENT:
267
+ case CHAR_SINGLE_QUOTE:
268
+ case CHAR_SEMICOLON:
269
+ case CHAR_LEFT_ANGLE_BRACKET:
270
+ case CHAR_RIGHT_ANGLE_BRACKET:
271
+ case CHAR_BACKWARD_SLASH:
272
+ case CHAR_CIRCUMFLEX_ACCENT:
273
+ case CHAR_GRAVE_ACCENT:
274
+ case CHAR_LEFT_CURLY_BRACKET:
275
+ case CHAR_VERTICAL_LINE:
276
+ case CHAR_RIGHT_CURLY_BRACKET:
277
+ // Characters that are never ever allowed in a hostname from RFC 2396
278
+ if (nonHost === -1)
279
+ nonHost = i;
280
+ break;
281
+ case CHAR_HASH:
282
+ case CHAR_FORWARD_SLASH:
283
+ case CHAR_QUESTION_MARK:
284
+ // Find the first instance of any host-ending characters
285
+ if (nonHost === -1)
286
+ nonHost = i;
287
+ hostEnd = i;
288
+ break;
289
+ case CHAR_AT:
290
+ // At this point, either we have an explicit point where the
291
+ // auth portion cannot go past, or the last @ char is the decider.
292
+ atSign = i;
293
+ nonHost = -1;
294
+ break;
295
+ }
296
+ if (hostEnd !== -1)
297
+ break;
298
+ }
299
+ start = 0;
300
+ if (atSign !== -1) {
301
+ this.auth = decodeURIComponent(rest.slice(0, atSign));
302
+ start = atSign + 1;
303
+ }
304
+ if (nonHost === -1) {
305
+ this.host = rest.slice(start);
306
+ rest = "";
307
+ }
308
+ else {
309
+ this.host = rest.slice(start, nonHost);
310
+ rest = rest.slice(nonHost);
311
+ }
312
+ // pull out port.
313
+ this.parseHost();
314
+ // We've indicated that there is a hostname,
315
+ // so even if it's empty, it has to be present.
316
+ if (typeof this.hostname !== "string")
317
+ this.hostname = "";
318
+ const hostname = this.hostname;
319
+ // If hostname begins with [ and ends with ]
320
+ // assume that it's an IPv6 address.
321
+ const ipv6Hostname = isIpv6Hostname(hostname);
322
+ // validate a little.
323
+ if (!ipv6Hostname) {
324
+ rest = getHostname(this, rest, hostname);
325
+ }
326
+ if (this.hostname.length > hostnameMaxLen) {
327
+ this.hostname = "";
328
+ }
329
+ else {
330
+ // Hostnames are always lower case.
331
+ this.hostname = this.hostname.toLowerCase();
332
+ }
333
+ if (this.hostname !== "") {
334
+ if (ipv6Hostname) {
335
+ if (forbiddenHostCharsIpv6.test(this.hostname)) {
336
+ throw new ERR_INVALID_URL(url);
337
+ }
338
+ }
339
+ else {
340
+ // IDNA Support: Returns a punycoded representation of "domain".
341
+ // It only converts parts of the domain name that
342
+ // have non-ASCII characters, i.e. it doesn't matter if
343
+ // you call it with a domain that already is ASCII-only.
344
+ this.hostname = urlUtil.toASCII(this.hostname);
345
+ // Prevent two potential routes of hostname spoofing.
346
+ // 1. If this.hostname is empty, it must have become empty due to toASCII
347
+ // since we checked this.hostname above.
348
+ // 2. If any of forbiddenHostChars appears in this.hostname, it must have
349
+ // also gotten in due to toASCII. This is since getHostname would have
350
+ // filtered them out otherwise.
351
+ // Rather than trying to correct this by moving the non-host part into
352
+ // the pathname as we've done in getHostname, throw an exception to
353
+ // convey the severity of this issue.
354
+ if (this.hostname === "" || forbiddenHostChars.test(this.hostname)) {
355
+ throw new ERR_INVALID_URL(url);
356
+ }
357
+ }
358
+ }
359
+ const p = this.port ? ":" + this.port : "";
360
+ const h = this.hostname || "";
361
+ this.host = h + p;
362
+ // strip [ and ] from the hostname
363
+ // the host field still retains them, though
364
+ if (ipv6Hostname) {
365
+ this.hostname = this.hostname.slice(1, -1);
366
+ if (rest[0] !== "/") {
367
+ rest = "/" + rest;
368
+ }
369
+ }
370
+ }
371
+ // Now rest is set to the post-host stuff.
372
+ // Chop off any delim chars.
373
+ if (!unsafeProtocol.has(lowerProto)) {
374
+ // First, make 100% sure that any "autoEscape" chars get
375
+ // escaped, even if encodeURIComponent doesn't think they
376
+ // need to be.
377
+ rest = autoEscapeStr(rest);
378
+ }
379
+ let questionIdx = -1;
380
+ let hashIdx = -1;
381
+ for (let i = 0; i < rest.length; ++i) {
382
+ const code = rest.charCodeAt(i);
383
+ if (code === CHAR_HASH) {
384
+ this.hash = rest.slice(i);
385
+ hashIdx = i;
386
+ break;
387
+ }
388
+ else if (code === CHAR_QUESTION_MARK && questionIdx === -1) {
389
+ questionIdx = i;
390
+ }
391
+ }
392
+ if (questionIdx !== -1) {
393
+ if (hashIdx === -1) {
394
+ this.search = rest.slice(questionIdx);
395
+ this.query = rest.slice(questionIdx + 1);
396
+ }
397
+ else {
398
+ this.search = rest.slice(questionIdx, hashIdx);
399
+ this.query = rest.slice(questionIdx + 1, hashIdx);
400
+ }
401
+ if (parseQueryString) {
402
+ this.query = querystringParse(this.query);
403
+ }
404
+ }
405
+ else if (parseQueryString) {
406
+ // No query string, but parseQueryString still requested
407
+ this.search = null;
408
+ this.query = { __proto__: null };
409
+ }
410
+ const useQuestionIdx = questionIdx !== -1 && (hashIdx === -1 || questionIdx < hashIdx);
411
+ const firstIdx = useQuestionIdx ? questionIdx : hashIdx;
412
+ if (firstIdx === -1) {
413
+ if (rest.length > 0)
414
+ this.pathname = rest;
415
+ }
416
+ else if (firstIdx > 0) {
417
+ this.pathname = rest.slice(0, firstIdx);
418
+ }
419
+ if (slashedProtocol.has(lowerProto) &&
420
+ this.hostname &&
421
+ !this.pathname) {
422
+ this.pathname = "/";
423
+ }
424
+ // To support http.request
425
+ if (this.pathname || this.search) {
426
+ const p = this.pathname || "";
427
+ const s = this.search || "";
428
+ this.path = p + s;
429
+ }
430
+ // Finally, reconstruct the href based on what has been validated.
431
+ this.href = this.format();
432
+ return this;
433
+ };
434
+ // These characters do not need escaping:
435
+ // ! - . _ ~
436
+ // ' ( ) * :
437
+ // digits
438
+ // alpha (uppercase)
439
+ // alpha (lowercase)
440
+ // prettier-ignore
441
+ const noEscapeAuth = new Int8Array([
442
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x00 - 0x0F
443
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x10 - 0x1F
444
+ 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 0x20 - 0x2F
445
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 0x30 - 0x3F
446
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 - 0x4F
447
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 0x50 - 0x5F
448
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6F
449
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, // 0x70 - 0x7F
450
+ ]);
451
+ Url.prototype.format = function format() {
452
+ let auth = this.auth || "";
453
+ if (auth) {
454
+ auth = encodeStr(auth, noEscapeAuth, hexTable);
455
+ auth += "@";
456
+ }
457
+ let protocol = this.protocol || "";
458
+ let pathname = this.pathname || "";
459
+ let hash = this.hash || "";
460
+ let host = "";
461
+ let query = "";
462
+ if (this.host) {
463
+ host = auth + this.host;
464
+ }
465
+ else if (this.hostname) {
466
+ host =
467
+ auth +
468
+ (this.hostname.includes(":") && !isIpv6Hostname(this.hostname)
469
+ ? "[" + this.hostname + "]"
470
+ : this.hostname);
471
+ if (this.port) {
472
+ host += ":" + this.port;
473
+ }
474
+ }
475
+ if (this.query !== null && typeof this.query === "object") {
476
+ query = querystringStringify(this.query);
477
+ }
478
+ let search = this.search || (query && "?" + query) || "";
479
+ if (protocol && protocol.charCodeAt(protocol.length - 1) !== 58 /* : */)
480
+ protocol += ":";
481
+ let newPathname = "";
482
+ let lastPos = 0;
483
+ for (let i = 0; i < pathname.length; ++i) {
484
+ switch (pathname.charCodeAt(i)) {
485
+ case CHAR_HASH:
486
+ if (i - lastPos > 0)
487
+ newPathname += pathname.slice(lastPos, i);
488
+ newPathname += "%23";
489
+ lastPos = i + 1;
490
+ break;
491
+ case CHAR_QUESTION_MARK:
492
+ if (i - lastPos > 0)
493
+ newPathname += pathname.slice(lastPos, i);
494
+ newPathname += "%3F";
495
+ lastPos = i + 1;
496
+ break;
497
+ }
498
+ }
499
+ if (lastPos > 0) {
500
+ if (lastPos !== pathname.length)
501
+ pathname = newPathname + pathname.slice(lastPos);
502
+ else
503
+ pathname = newPathname;
504
+ }
505
+ // Only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
506
+ // unless they had them to begin with.
507
+ if (this.slashes || slashedProtocol.has(protocol)) {
508
+ if (this.slashes || host) {
509
+ if (pathname && pathname.charCodeAt(0) !== CHAR_FORWARD_SLASH)
510
+ pathname = "/" + pathname;
511
+ host = "//" + host;
512
+ }
513
+ else if (protocol.length >= 4 &&
514
+ protocol.charCodeAt(0) === 102 /* f */ &&
515
+ protocol.charCodeAt(1) === 105 /* i */ &&
516
+ protocol.charCodeAt(2) === 108 /* l */ &&
517
+ protocol.charCodeAt(3) === 101 /* e */) {
518
+ host = "//";
519
+ }
520
+ }
521
+ search = search.replace(/#/g, "%23");
522
+ if (hash && hash.charCodeAt(0) !== CHAR_HASH)
523
+ hash = "#" + hash;
524
+ if (search && search.charCodeAt(0) !== CHAR_QUESTION_MARK)
525
+ search = "?" + search;
526
+ return protocol + host + pathname + search + hash;
527
+ };
528
+ export function resolve(source, relative) {
529
+ return parse(source, false, true).resolve(relative);
530
+ }
531
+ Url.prototype.resolveObject = function resolveObject(relative) {
532
+ if (typeof relative === "string") {
533
+ const rel = new Url();
534
+ rel.parse(relative, false, true);
535
+ relative = rel;
536
+ }
537
+ const result = new Url();
538
+ Object.assign(result, this);
539
+ // Hash is always overridden, no matter what.
540
+ // even href="" will remove it.
541
+ result.hash = relative.hash;
542
+ // If the relative url is empty, then there's nothing left to do here.
543
+ if (relative.href === "") {
544
+ result.href = result.format();
545
+ return result;
546
+ }
547
+ // Hrefs like //foo/bar always cut to the protocol.
548
+ if (relative.slashes && !relative.protocol) {
549
+ // Take everything except the protocol from relative
550
+ const relativeWithoutProtocol = Object.keys(relative).reduce((acc, key) => {
551
+ if (key !== "protocol") {
552
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
553
+ // @ts-expect-error
554
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
555
+ acc[key] = relative[key];
556
+ }
557
+ return acc;
558
+ }, {});
559
+ Object.assign(result, relativeWithoutProtocol);
560
+ // urlParse appends trailing / to urls like http://www.example.com
561
+ if (slashedProtocol.has(result.protocol) &&
562
+ result.hostname &&
563
+ !result.pathname) {
564
+ result.path = result.pathname = "/";
565
+ }
566
+ result.href = result.format();
567
+ return result;
568
+ }
569
+ if (relative.protocol && relative.protocol !== result.protocol) {
570
+ // If it's a known url protocol, then changing
571
+ // the protocol does weird things
572
+ // first, if it's not file:, then we MUST have a host,
573
+ // and if there was a path
574
+ // to begin with, then we MUST have a path.
575
+ // if it is file:, then the host is dropped,
576
+ // because that's known to be hostless.
577
+ // anything else is assumed to be absolute.
578
+ if (!slashedProtocol.has(relative.protocol)) {
579
+ Object.assign(result, relative);
580
+ result.href = result.format();
581
+ return result;
582
+ }
583
+ result.protocol = relative.protocol;
584
+ if (!relative.host &&
585
+ !/^file:?$/.test(relative.protocol) &&
586
+ !hostlessProtocol.has(relative.protocol)) {
587
+ const relPath = (relative.pathname || "").split("/");
588
+ while (relPath.length && !(relative.host = relPath.shift())) {
589
+ // keep this empty.
590
+ }
591
+ relative.host ||= "";
592
+ relative.hostname ||= "";
593
+ if (relPath[0] !== "")
594
+ relPath.unshift("");
595
+ if (relPath.length < 2)
596
+ relPath.unshift("");
597
+ result.pathname = relPath.join("/");
598
+ }
599
+ else {
600
+ result.pathname = relative.pathname;
601
+ }
602
+ result.search = relative.search;
603
+ result.query = relative.query;
604
+ result.host = relative.host || "";
605
+ result.auth = relative.auth;
606
+ result.hostname = relative.hostname || relative.host;
607
+ result.port = relative.port;
608
+ // To support http.request
609
+ if (result.pathname || result.search) {
610
+ const p = result.pathname || "";
611
+ const s = result.search || "";
612
+ result.path = p + s;
613
+ }
614
+ result.slashes ||= relative.slashes;
615
+ result.href = result.format();
616
+ return result;
617
+ }
618
+ const isSourceAbs = result.pathname && result.pathname.charAt(0) === "/";
619
+ const isRelAbs = relative.host || (relative.pathname && relative.pathname.charAt(0) === "/");
620
+ let mustEndAbs = !!isRelAbs ||
621
+ !!isSourceAbs ||
622
+ (!!result.host && !!relative.pathname) ||
623
+ false;
624
+ const removeAllDots = mustEndAbs;
625
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
626
+ let srcPath = (result.pathname && result.pathname.split("/")) || [];
627
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
628
+ const relPath = (relative.pathname && relative.pathname.split("/")) || [];
629
+ const noLeadingSlashes = result.protocol && !slashedProtocol.has(result.protocol);
630
+ // If the url is a non-slashed url, then relative
631
+ // links like ../.. should be able
632
+ // to crawl up to the hostname, as well. This is strange.
633
+ // result.protocol has already been set by now.
634
+ // Later on, put the first path part into the host field.
635
+ if (noLeadingSlashes) {
636
+ result.hostname = "";
637
+ result.port = null;
638
+ if (result.host) {
639
+ if (srcPath[0] === "")
640
+ srcPath[0] = result.host;
641
+ else
642
+ srcPath.unshift(result.host);
643
+ }
644
+ result.host = "";
645
+ if (relative.protocol) {
646
+ relative.hostname = null;
647
+ relative.port = null;
648
+ result.auth = null;
649
+ if (relative.host) {
650
+ if (relPath[0] === "")
651
+ relPath[0] = relative.host;
652
+ else
653
+ relPath.unshift(relative.host);
654
+ }
655
+ relative.host = null;
656
+ }
657
+ mustEndAbs &&= relPath[0] === "" || srcPath[0] === "";
658
+ }
659
+ if (isRelAbs) {
660
+ // it's absolute.
661
+ if (relative.host || relative.host === "") {
662
+ if (result.host !== relative.host)
663
+ result.auth = null;
664
+ result.host = relative.host;
665
+ result.port = relative.port;
666
+ }
667
+ if (relative.hostname || relative.hostname === "") {
668
+ if (result.hostname !== relative.hostname)
669
+ result.auth = null;
670
+ result.hostname = relative.hostname;
671
+ }
672
+ result.search = relative.search;
673
+ result.query = relative.query;
674
+ srcPath = relPath;
675
+ // Fall through to the dot-handling below.
676
+ }
677
+ else if (relPath.length) {
678
+ // it's relative
679
+ // throw away the existing file, and take the new path instead.
680
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
681
+ srcPath ||= [];
682
+ srcPath.pop();
683
+ srcPath = srcPath.concat(relPath);
684
+ result.search = relative.search;
685
+ result.query = relative.query;
686
+ }
687
+ else if (relative.search !== null && relative.search !== undefined) {
688
+ // Just pull out the search.
689
+ // like href='?foo'.
690
+ // Put this after the other two cases because it simplifies the booleans
691
+ if (noLeadingSlashes) {
692
+ result.hostname = result.host = srcPath.shift();
693
+ // Occasionally the auth can get stuck only in host.
694
+ // This especially happens in cases like
695
+ // url.resolveObject('mailto:local1@domain1', 'local2@domain2')
696
+ const authInHost = result.host && result.host.indexOf("@") > 0 && result.host.split("@");
697
+ if (authInHost) {
698
+ result.auth = authInHost.shift();
699
+ result.host = result.hostname = authInHost.shift();
700
+ }
701
+ }
702
+ result.search = relative.search;
703
+ result.query = relative.query;
704
+ // To support http.request
705
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
706
+ if (result.pathname !== null || result.search !== null) {
707
+ result.path =
708
+ (result.pathname ? result.pathname : "") +
709
+ (result.search ? result.search : "");
710
+ }
711
+ result.href = result.format();
712
+ return result;
713
+ }
714
+ if (!srcPath.length) {
715
+ // No path at all. All other things were already handled above.
716
+ result.pathname = null;
717
+ // To support http.request
718
+ if (result.search) {
719
+ result.path = "/" + result.search;
720
+ }
721
+ else {
722
+ result.path = null;
723
+ }
724
+ result.href = result.format();
725
+ return result;
726
+ }
727
+ // If a url ENDs in . or .., then it must get a trailing slash.
728
+ // however, if it ends in anything else non-slashy,
729
+ // then it must NOT get a trailing slash.
730
+ let last = srcPath.slice(-1)[0];
731
+ const hasTrailingSlash = ((result.host || relative.host || srcPath.length > 1) &&
732
+ (last === "." || last === "..")) ||
733
+ last === "";
734
+ // Strip single dots, resolve double dots to parent dir
735
+ // if the path tries to go above the root, `up` ends up > 0
736
+ let up = 0;
737
+ for (let i = srcPath.length - 1; i >= 0; i--) {
738
+ last = srcPath[i];
739
+ if (last === ".") {
740
+ spliceOne(srcPath, i);
741
+ }
742
+ else if (last === "..") {
743
+ spliceOne(srcPath, i);
744
+ up++;
745
+ }
746
+ else if (up) {
747
+ spliceOne(srcPath, i);
748
+ up--;
749
+ }
750
+ }
751
+ // If the path is allowed to go above the root, restore leading ..s
752
+ if (!mustEndAbs && !removeAllDots) {
753
+ while (up--) {
754
+ srcPath.unshift("..");
755
+ }
756
+ }
757
+ if (mustEndAbs &&
758
+ srcPath[0] !== "" &&
759
+ (!srcPath[0] || srcPath[0].charAt(0) !== "/")) {
760
+ srcPath.unshift("");
761
+ }
762
+ if (hasTrailingSlash && srcPath.join("/").slice(-1) !== "/") {
763
+ srcPath.push("");
764
+ }
765
+ const isAbsolute = srcPath[0] === "" || (srcPath[0] && srcPath[0].charAt(0) === "/");
766
+ // put the host back
767
+ if (noLeadingSlashes) {
768
+ result.hostname = result.host = isAbsolute
769
+ ? ""
770
+ : srcPath.length
771
+ ? srcPath.shift()
772
+ : "";
773
+ // Occasionally the auth can get stuck only in host.
774
+ // This especially happens in cases like
775
+ // url.resolveObject('mailto:local1@domain1', 'local2@domain2')
776
+ const authInHost = result.host && result.host.indexOf("@") > 0
777
+ ? result.host.split("@")
778
+ : false;
779
+ if (authInHost) {
780
+ result.auth = authInHost.shift();
781
+ result.host = result.hostname = authInHost.shift();
782
+ }
783
+ }
784
+ mustEndAbs ||= Boolean(result.host && srcPath.length);
785
+ if (mustEndAbs && !isAbsolute) {
786
+ srcPath.unshift("");
787
+ }
788
+ if (!srcPath.length) {
789
+ result.pathname = null;
790
+ result.path = null;
791
+ }
792
+ else {
793
+ result.pathname = srcPath.join("/");
794
+ }
795
+ // To support request.http
796
+ if (result.pathname !== null || result.search !== null) {
797
+ result.path =
798
+ (result.pathname ? result.pathname : "") +
799
+ (result.search ? result.search : "");
800
+ }
801
+ result.auth = relative.auth || result.auth;
802
+ result.slashes ||= relative.slashes;
803
+ result.href = result.format();
804
+ return result;
805
+ };
806
+ Url.prototype.resolve = function resolve(relative) {
807
+ return this.resolveObject(parse(relative, false, true)).format();
808
+ };
809
+ Url.prototype.parseHost = function parseHost() {
810
+ let host = this.host;
811
+ let port = portPattern.exec(host);
812
+ if (port) {
813
+ port = port[0];
814
+ if (port !== ":") {
815
+ this.port = port.slice(1);
816
+ }
817
+ host = host.slice(0, host.length - port.length);
818
+ }
819
+ if (host)
820
+ this.hostname = host;
821
+ };
822
+ export function parse(url, parseQueryString, slashesDenoteHost) {
823
+ if (url instanceof Url)
824
+ return url;
825
+ const urlObject = new Url();
826
+ urlObject.parse(url, parseQueryString, slashesDenoteHost);
827
+ return urlObject;
828
+ }
829
+ // Format a parsed object into a url string
830
+ export function format(urlObject, options) {
831
+ // Ensure it's an object, and not a string url.
832
+ // If it's an object, this is a no-op.
833
+ // this way, you can call urlParse() on strings
834
+ // to clean up potentially wonky urls.
835
+ if (typeof urlObject === "string") {
836
+ urlObject = parse(urlObject);
837
+ }
838
+ else if (typeof urlObject !== "object" || urlObject === null) {
839
+ throw new ERR_INVALID_ARG_TYPE("urlObject", ["Object", "string"], urlObject);
840
+ }
841
+ else if (isURLInstance(urlObject)) {
842
+ let fragment = true;
843
+ let unicode = false;
844
+ let search = true;
845
+ let auth = true;
846
+ if (options) {
847
+ validateObject(options, "options");
848
+ if (options.fragment != null) {
849
+ fragment = Boolean(options.fragment); // eslint-disable-line @typescript-eslint/no-unnecessary-type-conversion
850
+ }
851
+ if (options.unicode != null) {
852
+ unicode = Boolean(options.unicode); // eslint-disable-line @typescript-eslint/no-unnecessary-type-conversion
853
+ }
854
+ if (options.search != null) {
855
+ search = Boolean(options.search); // eslint-disable-line @typescript-eslint/no-unnecessary-type-conversion
856
+ }
857
+ if (options.auth != null) {
858
+ auth = Boolean(options.auth); // eslint-disable-line @typescript-eslint/no-unnecessary-type-conversion
859
+ }
860
+ }
861
+ return urlUtil.format(urlObject.href, fragment, unicode, search, auth);
862
+ }
863
+ return Url.prototype.format.call(urlObject);
864
+ }
865
+ export function resolveObject(source, relative) {
866
+ if (!source) {
867
+ return relative;
868
+ }
869
+ return parse(source, false, true).resolveObject(relative);
870
+ }