exacturi 1.0.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 (80) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +2 -0
  3. package/dist/cjs/errors.d.ts +11 -0
  4. package/dist/cjs/errors.d.ts.map +1 -0
  5. package/dist/cjs/errors.js +39 -0
  6. package/dist/cjs/errors.js.map +1 -0
  7. package/dist/cjs/exacturi.d.ts +91 -0
  8. package/dist/cjs/exacturi.d.ts.map +1 -0
  9. package/dist/cjs/exacturi.js +332 -0
  10. package/dist/cjs/exacturi.js.map +1 -0
  11. package/dist/cjs/index.d.ts +29 -0
  12. package/dist/cjs/index.d.ts.map +1 -0
  13. package/dist/cjs/index.js +19 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/cjs/parts.d.ts +15 -0
  16. package/dist/cjs/parts.d.ts.map +1 -0
  17. package/dist/cjs/parts.js +3 -0
  18. package/dist/cjs/parts.js.map +1 -0
  19. package/dist/cjs/reuri.d.ts +92 -0
  20. package/dist/cjs/reuri.d.ts.map +1 -0
  21. package/dist/cjs/reuri.js +345 -0
  22. package/dist/cjs/reuri.js.map +1 -0
  23. package/dist/cjs/utils.d.ts +3 -0
  24. package/dist/cjs/utils.d.ts.map +1 -0
  25. package/dist/cjs/utils.js +45 -0
  26. package/dist/cjs/utils.js.map +1 -0
  27. package/dist/esm/errors.d.ts +11 -0
  28. package/dist/esm/errors.d.ts.map +1 -0
  29. package/dist/esm/errors.js +28 -0
  30. package/dist/esm/errors.js.map +1 -0
  31. package/dist/esm/exacturi.d.ts +91 -0
  32. package/dist/esm/exacturi.d.ts.map +1 -0
  33. package/dist/esm/exacturi.js +328 -0
  34. package/dist/esm/exacturi.js.map +1 -0
  35. package/dist/esm/index.d.ts +29 -0
  36. package/dist/esm/index.d.ts.map +1 -0
  37. package/dist/esm/index.js +13 -0
  38. package/dist/esm/index.js.map +1 -0
  39. package/dist/esm/parts.d.ts +15 -0
  40. package/dist/esm/parts.d.ts.map +1 -0
  41. package/dist/esm/parts.js +2 -0
  42. package/dist/esm/parts.js.map +1 -0
  43. package/dist/esm/reuri.d.ts +92 -0
  44. package/dist/esm/reuri.d.ts.map +1 -0
  45. package/dist/esm/reuri.js +341 -0
  46. package/dist/esm/reuri.js.map +1 -0
  47. package/dist/esm/utils.d.ts +3 -0
  48. package/dist/esm/utils.d.ts.map +1 -0
  49. package/dist/esm/utils.js +41 -0
  50. package/dist/esm/utils.js.map +1 -0
  51. package/dist/lib/errors.d.ts +14 -0
  52. package/dist/lib/errors.d.ts.map +1 -0
  53. package/dist/lib/errors.js +52 -0
  54. package/dist/lib/index.d.ts +31 -0
  55. package/dist/lib/index.d.ts.map +1 -0
  56. package/dist/lib/index.js +20 -0
  57. package/dist/lib/parts.d.ts +18 -0
  58. package/dist/lib/parts.d.ts.map +1 -0
  59. package/dist/lib/parts.js +3 -0
  60. package/dist/lib/payload.d.ts +17 -0
  61. package/dist/lib/payload.d.ts.map +1 -0
  62. package/dist/lib/payload.js +126 -0
  63. package/dist/lib/reuri.d.ts +127 -0
  64. package/dist/lib/reuri.d.ts.map +1 -0
  65. package/dist/lib/reuri.js +457 -0
  66. package/dist/lib/utils.d.ts +2 -0
  67. package/dist/lib/utils.d.ts.map +1 -0
  68. package/dist/lib/utils.js +26 -0
  69. package/dist/test/basic.test.js +319 -0
  70. package/dist/test/basic.test.js.map +1 -0
  71. package/dist/test/extras.test.js +77 -0
  72. package/dist/test/extras.test.js.map +1 -0
  73. package/dist/test/matching.test.js +80 -0
  74. package/dist/test/matching.test.js.map +1 -0
  75. package/package.json +101 -0
  76. package/src/errors.ts +31 -0
  77. package/src/exacturi.ts +444 -0
  78. package/src/index.ts +37 -0
  79. package/src/parts.ts +29 -0
  80. package/src/utils.ts +42 -0
@@ -0,0 +1,92 @@
1
+ import { ExactUriParts, ExactUriPathKey, Protocol } from "./parts.js";
2
+ /**
3
+ * Represents a URI and allows performing operations and inspecting it.
4
+ *
5
+ * This class is immutable.
6
+ */
7
+ export declare class ExactUri {
8
+ private _protocol;
9
+ private _hostname;
10
+ private _path;
11
+ private _query;
12
+ private _hash;
13
+ private _parsed;
14
+ private _port;
15
+ private 0;
16
+ constructor(_protocol: Protocol | undefined, _hostname: string | undefined, _path: string, _query: string | undefined, _hash: string | undefined, _parsed: string | undefined, _port: string | undefined);
17
+ static isExactUri(other: unknown): boolean;
18
+ segments(): string[];
19
+ segments(overwrite: string[]): ExactUri;
20
+ merge(other: string): ExactUri;
21
+ merge(other: ExactUri): ExactUri;
22
+ pick(...keys: ExactUriPathKey[]): ExactUri;
23
+ parts(): ExactUriParts;
24
+ parts(overwrite: Partial<ExactUriParts>): ExactUri;
25
+ part(key: ExactUriPathKey): string | undefined;
26
+ part(key: ExactUriPathKey, value: string | undefined): ExactUri;
27
+ address(address: string | undefined | null): ExactUri;
28
+ address(): string | undefined;
29
+ resource(resource: string | undefined | null): ExactUri;
30
+ resource(): string | undefined;
31
+ origin(origin: string | undefined | null): ExactUri;
32
+ origin(): string | undefined;
33
+ segment(index: number): string;
34
+ segment(index: number, value: string): ExactUri;
35
+ path(): string;
36
+ path(path: string | undefined | null): ExactUri;
37
+ port(): number | undefined;
38
+ port(raw: true): string | undefined;
39
+ port(port: number | undefined | string | null): ExactUri;
40
+ protocol(): Protocol | undefined;
41
+ protocol(proto: Protocol | null | undefined): ExactUri;
42
+ host(): string | undefined;
43
+ host(host: string | undefined | null): ExactUri;
44
+ hostname(): string | undefined;
45
+ hostname(hostname: string | undefined | null): ExactUri;
46
+ query(): string | undefined;
47
+ query(query: string | null | undefined): ExactUri;
48
+ hash(): string;
49
+ hash(hash: string | null | undefined): ExactUri;
50
+ private _noCopyClone;
51
+ get isWeb(): boolean;
52
+ /**
53
+ * Gets a clone of this instance.
54
+ */
55
+ clone(): ExactUri;
56
+ static empty(): ExactUri;
57
+ static parse(input: null | undefined): ExactUri;
58
+ static parse(input: string | ExactUri | Partial<ExactUriParts>): ExactUri;
59
+ /**
60
+ * Checks if this URI (CHILD) matches another URI (PARENT). The parent can be a string,
61
+ * an {@link ExactUri}, or an object describing the parts of a URI -- an {@link ExactUriParts}.
62
+ *
63
+ * CHILD is considered to be a child of PARENT if:
64
+ * 1. If PARENT has a protocol, it must equal CHILD protocol.
65
+ * 2. If PARENT has a hostname, it must be a parent of CHILD's hostname.
66
+ * 3. If PARENT has a port, it must equal CHILD's port.
67
+ * 4. If PARENT has a path, it must be a parent of CHILD's path.
68
+ * 5. If PARENT has a query, it must equal CHILD's query.
69
+ * 6. If PARENT has a hash, it must equal CHILD's hash.
70
+ * @param parent The parent URI to check against.
71
+ */
72
+ matches(parent: Partial<ExactUriParts> | ExactUri | string): boolean;
73
+ /**
74
+ * Checks if this URI equals another URI, which can be given as a string, an
75
+ * {@link ExactUri}, or an object describing the parts of a URI -- an {@link ExactUriParts}.
76
+ * @param other The other URI to check against.
77
+ */
78
+ equal(other: string | ExactUri | Partial<ExactUriParts>): boolean;
79
+ get isArtificial(): boolean;
80
+ /**
81
+ * Does this URL have a non-web protocol?
82
+ */
83
+ get isNonWeb(): boolean;
84
+ /**
85
+ * Gets the full URI.
86
+ */
87
+ get href(): string;
88
+ private _print;
89
+ get [Symbol.toStringTag](): string;
90
+ toString(): string;
91
+ }
92
+ //# sourceMappingURL=reuri.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reuri.d.ts","sourceRoot":"","sources":["../../src/reuri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyB,aAAa,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE7F;;;;GAIG;AACH,qBAAa,QAAQ;IAKb,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,KAAK;IAVjB,OAAO,CAAC,CAAC,CAAS;gBAIN,SAAS,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AG,MAAM,GAAG,OAAO;IA6BpE;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO;IAgBjE,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED;;OAEG;IACH,IAAI,QAAQ,YAEX;IAED;;OAEG;IACH,IAAI,IAAI,WAEP;IAED,OAAO,CAAC,MAAM;IAWd,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAED,QAAQ;CAGX"}
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExactUri = void 0;
4
+ const errors_js_1 = require("./errors.js");
5
+ const utils_js_1 = require("./utils.js");
6
+ /**
7
+ * Represents a URI and allows performing operations and inspecting it.
8
+ *
9
+ * This class is immutable.
10
+ */
11
+ class ExactUri {
12
+ // Lots of params needed here
13
+ // eslint-disable-next-line max-params
14
+ constructor(_protocol, _hostname, _path, _query, _hash, _parsed, _port) {
15
+ this._protocol = _protocol;
16
+ this._hostname = _hostname;
17
+ this._path = _path;
18
+ this._query = _query;
19
+ this._hash = _hash;
20
+ this._parsed = _parsed;
21
+ this._port = _port;
22
+ if (_hostname) {
23
+ this._hostname = _hostname.replace("_", ".");
24
+ if (this._hostname.includes("_")) {
25
+ console.warn(`The hostname contains multiple underscores, which might not be intended. Current hostname: ${this._hostname}`);
26
+ }
27
+ }
28
+ this[0] = this._print();
29
+ }
30
+ static isExactUri(other) {
31
+ return !!(other &&
32
+ typeof other === "object" &&
33
+ other.constructor &&
34
+ "__isExactUri" in other.constructor);
35
+ }
36
+ segments(overwrite) {
37
+ if (arguments.length === 0) {
38
+ return this._path.split("/");
39
+ }
40
+ const clone = this._noCopyClone();
41
+ clone._path = overwrite.join("/");
42
+ return clone;
43
+ }
44
+ merge(other) {
45
+ if (typeof other === "string") {
46
+ return this.merge(ExactUri.parse(other));
47
+ }
48
+ return this.parts({
49
+ hash: other._hash || this._hash,
50
+ hostname: other._hostname || this._hostname,
51
+ path: other._path || this._path,
52
+ port: other._port || this._port,
53
+ protocol: other._protocol || this._protocol,
54
+ query: other._query || this._query
55
+ });
56
+ }
57
+ pick(...keys) {
58
+ let result = ExactUri.empty();
59
+ for (const key of keys) {
60
+ result = result.part(key, this.part(key));
61
+ }
62
+ return result;
63
+ }
64
+ parts(overwrite) {
65
+ if (arguments.length === 0) {
66
+ return {
67
+ protocol: this._protocol,
68
+ hostname: this._hostname,
69
+ port: this._port,
70
+ path: this._path,
71
+ query: this._query,
72
+ hash: this._hash
73
+ };
74
+ }
75
+ if (!overwrite) {
76
+ return this;
77
+ }
78
+ const clone = this._noCopyClone();
79
+ clone._protocol = "protocol" in overwrite ? overwrite.protocol : clone._protocol;
80
+ clone._hostname = "hostname" in overwrite ? overwrite.hostname : clone._hostname;
81
+ clone._port = "port" in overwrite ? overwrite.port : clone._port;
82
+ clone._path = "path" in overwrite ? overwrite.path : clone._path;
83
+ clone._query = "query" in overwrite ? overwrite.query : clone._query;
84
+ clone._hash = "hash" in overwrite ? overwrite.hash : clone._hash;
85
+ return clone;
86
+ }
87
+ part(key, value) {
88
+ if (arguments.length === 1) {
89
+ const result = this[key]();
90
+ return result != null ? String(result) : undefined;
91
+ }
92
+ return this[key](value);
93
+ }
94
+ address(address) {
95
+ if (arguments.length === 1) {
96
+ const parsed = ExactUri.parse(address);
97
+ return parsed.parts({
98
+ protocol: this._protocol
99
+ });
100
+ }
101
+ return this.parts({
102
+ protocol: undefined
103
+ }).href;
104
+ }
105
+ resource(resource) {
106
+ if (arguments.length === 1) {
107
+ const parsed = ExactUri.parse(resource);
108
+ return parsed.parts({
109
+ protocol: this._protocol,
110
+ hostname: this._hostname,
111
+ port: this._port
112
+ });
113
+ }
114
+ return this.parts({
115
+ protocol: undefined,
116
+ hostname: undefined,
117
+ port: undefined
118
+ }).href;
119
+ }
120
+ origin(origin) {
121
+ if (arguments.length === 1) {
122
+ const parsed = ExactUri.parse(origin);
123
+ return this.parts({
124
+ protocol: parsed._protocol,
125
+ hostname: parsed._hostname,
126
+ port: parsed._port
127
+ });
128
+ }
129
+ const parts = this.parts();
130
+ return (ExactUri.empty().parts({
131
+ protocol: parts.protocol,
132
+ hostname: parts.hostname,
133
+ port: parts.port
134
+ }).href || undefined);
135
+ }
136
+ segment(index, value) {
137
+ if (arguments.length === 0) {
138
+ throw new errors_js_1.ExactUriError(`You must provide an index.`);
139
+ }
140
+ if (arguments.length === 1) {
141
+ return this._path.split("/")[index];
142
+ }
143
+ const segments = this.segments();
144
+ segments[index] = value;
145
+ return this.segments(segments);
146
+ }
147
+ path(path) {
148
+ if (arguments.length === 0) {
149
+ return this._path;
150
+ }
151
+ const clone = this._noCopyClone();
152
+ clone._path = path ?? "";
153
+ return clone;
154
+ }
155
+ port(port) {
156
+ if (arguments.length === 0) {
157
+ return this._port != null ? Number(this._port) : undefined;
158
+ }
159
+ if (port === true) {
160
+ return this._port;
161
+ }
162
+ const clone = this._noCopyClone();
163
+ clone._port = port != null ? String(port) : undefined;
164
+ return clone;
165
+ }
166
+ protocol(proto) {
167
+ if (arguments.length === 0) {
168
+ return this._protocol;
169
+ }
170
+ const clone = this._noCopyClone();
171
+ clone._protocol = proto ?? undefined;
172
+ return clone;
173
+ }
174
+ host(host) {
175
+ if (arguments.length === 0) {
176
+ return (ExactUri.empty().hostname(this._hostname).port(this._port).href.slice(2) ||
177
+ undefined);
178
+ }
179
+ if (host == null) {
180
+ return this.hostname(null).port(null);
181
+ }
182
+ const parsed = ExactUri.parse(`//${host}`);
183
+ return this.hostname(parsed._hostname).port(parsed._port);
184
+ }
185
+ hostname(hostname) {
186
+ if (arguments.length === 0) {
187
+ return this._hostname;
188
+ }
189
+ const clone = this._noCopyClone();
190
+ clone._hostname = hostname ?? undefined;
191
+ return clone;
192
+ }
193
+ query(query) {
194
+ if (arguments.length === 0) {
195
+ return this._query;
196
+ }
197
+ const clone = this._noCopyClone();
198
+ clone._query = query ?? undefined;
199
+ return clone;
200
+ }
201
+ hash(hash) {
202
+ if (arguments.length === 0) {
203
+ return this._hash;
204
+ }
205
+ const clone = this._noCopyClone();
206
+ clone._hash = hash ?? undefined;
207
+ return clone;
208
+ }
209
+ _noCopyClone() {
210
+ return new ExactUri(this._protocol, this._hostname, this._path, this._query, this._hash, this._parsed, this._port);
211
+ }
212
+ // Does this URL have a web protocol?
213
+ get isWeb() {
214
+ return !!this._protocol && webProtocols.has(this._protocol);
215
+ }
216
+ /**
217
+ * Gets a clone of this instance.
218
+ */
219
+ clone() {
220
+ return new ExactUri(this._protocol, this._hostname, this._path, this._query, this._hash, this._parsed, this._port);
221
+ }
222
+ static empty() {
223
+ return new ExactUri(undefined, undefined, "", undefined, undefined, undefined, undefined);
224
+ }
225
+ static parse(input) {
226
+ if (input == null) {
227
+ return ExactUri.empty();
228
+ }
229
+ if (input instanceof ExactUri) {
230
+ return input;
231
+ }
232
+ if (typeof input === "object") {
233
+ return ExactUri.empty().parts(input);
234
+ }
235
+ if (typeof input !== "string") {
236
+ throw (0, errors_js_1.inputMustBeString)(input);
237
+ }
238
+ const r = urlRegexp.exec(input);
239
+ if (!r) {
240
+ throw (0, errors_js_1.inputMustBeUrl)(input);
241
+ }
242
+ const [, proto, hostname, port, path, query, fragment] = r;
243
+ if (port != null && (Number.isNaN(+port) || port === "")) {
244
+ throw (0, errors_js_1.portMustBeNumeric)(input);
245
+ }
246
+ return new ExactUri(proto?.trim(), hostname?.trim(), path?.trim() ?? "", query?.trim(), fragment?.trim(), input, port);
247
+ }
248
+ /**
249
+ * Checks if this URI (CHILD) matches another URI (PARENT). The parent can be a string,
250
+ * an {@link ExactUri}, or an object describing the parts of a URI -- an {@link ExactUriParts}.
251
+ *
252
+ * CHILD is considered to be a child of PARENT if:
253
+ * 1. If PARENT has a protocol, it must equal CHILD protocol.
254
+ * 2. If PARENT has a hostname, it must be a parent of CHILD's hostname.
255
+ * 3. If PARENT has a port, it must equal CHILD's port.
256
+ * 4. If PARENT has a path, it must be a parent of CHILD's path.
257
+ * 5. If PARENT has a query, it must equal CHILD's query.
258
+ * 6. If PARENT has a hash, it must equal CHILD's hash.
259
+ * @param parent The parent URI to check against.
260
+ */
261
+ matches(parent) {
262
+ parent = ExactUri.parse(parent);
263
+ if (parent._protocol && parent._protocol !== this._protocol) {
264
+ return false;
265
+ }
266
+ if (parent._hostname && !(0, utils_js_1.hostnameContains)(this._hostname, parent._hostname)) {
267
+ return false;
268
+ }
269
+ if (parent._port && parent._port !== this._port) {
270
+ return false;
271
+ }
272
+ if (parent._query && parent._query !== this._query) {
273
+ return false;
274
+ }
275
+ if (parent._hash && parent._hash !== this._hash) {
276
+ return false;
277
+ }
278
+ const parentSegments = parent.segments();
279
+ const childSegments = this.segments();
280
+ for (let i = 0; i < parentSegments.length; i++) {
281
+ if (parentSegments[i] !== childSegments[i]) {
282
+ return false;
283
+ }
284
+ }
285
+ return true;
286
+ }
287
+ /**
288
+ * Checks if this URI equals another URI, which can be given as a string, an
289
+ * {@link ExactUri}, or an object describing the parts of a URI -- an {@link ExactUriParts}.
290
+ * @param other The other URI to check against.
291
+ */
292
+ equal(other) {
293
+ if (this === other) {
294
+ return true;
295
+ }
296
+ other = ExactUri.parse(other);
297
+ const myParts = this.parts();
298
+ const otherParts = other.parts();
299
+ for (const key of ["protocol", "hostname", "port", "path", "query", "hash"]) {
300
+ if (myParts[key] !== otherParts[key]) {
301
+ return false;
302
+ }
303
+ }
304
+ return true;
305
+ }
306
+ // An artificial URI is one that can't have been parsed from a string due to an invalid combination of components.
307
+ get isArtificial() {
308
+ return !ExactUri.parse(this._print()).equal(this);
309
+ }
310
+ /**
311
+ * Does this URL have a non-web protocol?
312
+ */
313
+ get isNonWeb() {
314
+ return !!this._protocol && !webProtocols.has(this._protocol);
315
+ }
316
+ /**
317
+ * Gets the full URI.
318
+ */
319
+ get href() {
320
+ return this._print();
321
+ }
322
+ _print() {
323
+ let { _protocol, _hostname, _query, _hash } = this;
324
+ const { _port } = this;
325
+ _protocol = _protocol != null ? `${_protocol}:` : _protocol;
326
+ _hostname = _hostname != null ? `//${_hostname}` : "";
327
+ _query = _query != null ? `?${_query}` : "";
328
+ _hash = _hash != null ? `#${_hash}` : "";
329
+ const strPort = _port != null ? `:${_port}` : "";
330
+ return [_protocol, _hostname, strPort, this._path, _query, _hash].join("");
331
+ }
332
+ get [Symbol.toStringTag]() {
333
+ return this.href;
334
+ }
335
+ toString() {
336
+ return this.href;
337
+ }
338
+ }
339
+ exports.ExactUri = ExactUri;
340
+ const urlRegexp = /^(?:([a-zA-Z][A-Za-z\d+-.]*):)?(?:\/\/([^/?#:]*)(?::([^/?#]*))?)?([^?#]*)?(?:\?([^#]*))?(?:#(.*))?$/;
341
+ const webProtocols = new Set(["http", "ws", "https", "wss"]);
342
+ Object.defineProperty(ExactUri, "__isExactUri", {
343
+ value: true
344
+ });
345
+ //# sourceMappingURL=reuri.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reuri.js","sourceRoot":"","sources":["../../src/reuri.ts"],"names":[],"mappings":";;;AAAA,2CAAkG;AAClG,yCAA8C;AAG9C;;;;GAIG;AACH,MAAa,QAAQ;IAEjB,6BAA6B;IAC7B,sCAAsC;IACtC,YACY,SAA+B,EAC/B,SAA6B,EAC7B,KAAa,EACb,MAA0B,EAC1B,KAAyB,EACzB,OAA2B,EAC3B,KAAyB;QANzB,cAAS,GAAT,SAAS,CAAsB;QAC/B,cAAS,GAAT,SAAS,CAAoB;QAC7B,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAoB;QAC1B,UAAK,GAAL,KAAK,CAAoB;QACzB,YAAO,GAAP,OAAO,CAAoB;QAC3B,UAAK,GAAL,KAAK,CAAoB;QAEjC,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAC7C,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,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AO,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;CACJ;AAzbD,4BAybC;AAED,MAAM,SAAS,GACX,qGAAqG,CAAC;AAE1G,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAE7D,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,cAAc,EAAE;IAC5C,KAAK,EAAE,IAAI;CACd,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function hostnameContains(child: string | undefined, parent: string): boolean;
2
+ export declare function equal(a: any, b: any): boolean;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,WAmBzE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,OAAO,CAoB7C"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hostnameContains = hostnameContains;
4
+ exports.equal = equal;
5
+ function hostnameContains(child, parent) {
6
+ if (!child) {
7
+ return false;
8
+ }
9
+ const parentParts = parent.split(".").reverse();
10
+ const childParts = child.split(".").reverse();
11
+ if (parentParts.length > childParts.length) {
12
+ return false;
13
+ }
14
+ for (let i = 0; i < parentParts.length; i++) {
15
+ if (!parentParts[i]) {
16
+ continue;
17
+ }
18
+ if (childParts[i] !== parentParts[i]) {
19
+ return false;
20
+ }
21
+ }
22
+ return true;
23
+ }
24
+ function equal(a, b) {
25
+ if (!a || typeof a !== "object" || !b || typeof b !== "object") {
26
+ return a === b;
27
+ }
28
+ const aProto = Object.getPrototypeOf(a);
29
+ const bProto = Object.getPrototypeOf(b);
30
+ if (aProto !== bProto) {
31
+ return false;
32
+ }
33
+ const aKeys = Object.keys(a);
34
+ const bKeys = Object.keys(b);
35
+ if (aKeys.length !== bKeys.length) {
36
+ return false;
37
+ }
38
+ for (const key of aKeys) {
39
+ if (a[key] !== b[key]) {
40
+ return false;
41
+ }
42
+ }
43
+ return true;
44
+ }
45
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;AAAA,4CAmBC;AAED,sBAoBC;AAzCD,SAAgB,gBAAgB,CAAC,KAAyB,EAAE,MAAc;IACtE,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;IAChD,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;IAC9C,IAAI,WAAW,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;YAClB,SAAS;QACb,CAAC;QACD,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAgB,KAAK,CAAC,CAAM,EAAE,CAAM;IAChC,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC7D,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IACxC,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare class ExactUriError extends Error {
2
+ name: string;
3
+ }
4
+ export declare function badInputError(input: any, reason: string): ExactUriError;
5
+ export declare function inputMustBeString(input: unknown): ExactUriError;
6
+ export declare function cantSerializeArtificialUrl(url: string): ExactUriError;
7
+ export declare function invalidCharacter(input: string, char: string, reason: string): ExactUriError;
8
+ export declare function portMustBeNumeric(input: string): ExactUriError;
9
+ export declare function inputMustBeUrl(input: string): ExactUriError;
10
+ export declare function cantCompareType(value: unknown): ExactUriError;
11
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACpC,IAAI,SAAmB;CAC1B;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,iBAEvD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,iBAE/C;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,iBAErD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAE3E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,iBAE9C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,iBAE3C;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,iBAE7C"}
@@ -0,0 +1,28 @@
1
+ export class ExactUriError extends Error {
2
+ constructor() {
3
+ super(...arguments);
4
+ this.name = "ExactUriError";
5
+ }
6
+ }
7
+ export function badInputError(input, reason) {
8
+ return new ExactUriError(`Received bad input ${input}. ${reason}`);
9
+ }
10
+ export function inputMustBeString(input) {
11
+ return badInputError(input, `Input must be a string, but was a ${typeof input}`);
12
+ }
13
+ export function cantSerializeArtificialUrl(url) {
14
+ return new ExactUriError(`This URL is artificial and can't be serialized. Looks like: ${url}`);
15
+ }
16
+ export function invalidCharacter(input, char, reason) {
17
+ return badInputError(input, `The character ${char} was unexpected because ${reason}.`);
18
+ }
19
+ export function portMustBeNumeric(input) {
20
+ return badInputError(input, "Port must be numeric.");
21
+ }
22
+ export function inputMustBeUrl(input) {
23
+ return badInputError(input, "Input failed to parse.");
24
+ }
25
+ export function cantCompareType(value) {
26
+ return new ExactUriError(`Can't compare this URI to a value ${value}`);
27
+ }
28
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IAAxC;;QACI,SAAI,GAAG,eAAe,CAAC;IAC3B,CAAC;CAAA;AAED,MAAM,UAAU,aAAa,CAAC,KAAU,EAAE,MAAc;IACpD,OAAO,IAAI,aAAa,CAAC,sBAAsB,KAAK,KAAK,MAAM,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC5C,OAAO,aAAa,CAAC,KAAK,EAAE,qCAAqC,OAAO,KAAK,EAAE,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,GAAW;IAClD,OAAO,IAAI,aAAa,CAAC,+DAA+D,GAAG,EAAE,CAAC,CAAC;AACnG,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,IAAY,EAAE,MAAc;IACxE,OAAO,aAAa,CAAC,KAAK,EAAE,iBAAiB,IAAI,2BAA2B,MAAM,GAAG,CAAC,CAAC;AAC3F,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC3C,OAAO,aAAa,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa;IACxC,OAAO,aAAa,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAc;IAC1C,OAAO,IAAI,aAAa,CAAC,qCAAqC,KAAK,EAAE,CAAC,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,91 @@
1
+ import { ExactUri_Parts, ExactUri_PathKey, ExactUri_Protocol } from "./parts.js";
2
+ /**
3
+ * Represents a URI and allows performing operations and inspecting it.
4
+ *
5
+ * This class is immutable.
6
+ */
7
+ export declare class ExactUri {
8
+ private _protocol;
9
+ private _hostname;
10
+ private _path;
11
+ private _query;
12
+ private _hash;
13
+ private _parsed;
14
+ private _port;
15
+ constructor(_protocol: ExactUri_Protocol | undefined, _hostname: string | undefined, _path: string, _query: string | undefined, _hash: string | undefined, _parsed: string | undefined, _port: string | undefined);
16
+ static is(other: unknown): other is ExactUri;
17
+ segments(): string[];
18
+ segments(overwrite: string[]): ExactUri;
19
+ merge(other: string): ExactUri;
20
+ merge(other: ExactUri): ExactUri;
21
+ pick(...keys: ExactUri_PathKey[]): ExactUri;
22
+ parts(): ExactUri_Parts;
23
+ parts(overwrite: Partial<ExactUri_Parts>): ExactUri;
24
+ part(key: ExactUri_PathKey): string | undefined;
25
+ part(key: ExactUri_PathKey, value: string | undefined): ExactUri;
26
+ address(address: string | undefined | null): ExactUri;
27
+ address(): string | undefined;
28
+ resource(resource: string | undefined | null): ExactUri;
29
+ resource(): string | undefined;
30
+ origin(origin: string | undefined | null): ExactUri;
31
+ origin(): string | undefined;
32
+ segment(index: number): string;
33
+ segment(index: number, value: string): ExactUri;
34
+ path(): string;
35
+ path(path: string | undefined | null): ExactUri;
36
+ port(): number | undefined;
37
+ port(raw: true): string | undefined;
38
+ port(port: number | undefined | string | null): ExactUri;
39
+ protocol(): ExactUri_Protocol | undefined;
40
+ protocol(proto: ExactUri_Protocol | null | undefined): ExactUri;
41
+ host(): string | undefined;
42
+ host(host: string | undefined | null): ExactUri;
43
+ hostname(): string | undefined;
44
+ hostname(hostname: string | undefined | null): ExactUri;
45
+ query(): string | undefined;
46
+ query(query: string | null | undefined): ExactUri;
47
+ hash(): string;
48
+ hash(hash: string | null | undefined): ExactUri;
49
+ private _noCopyClone;
50
+ get isWeb(): boolean;
51
+ /**
52
+ * Gets a clone of this instance.
53
+ */
54
+ clone(): ExactUri;
55
+ static empty(): ExactUri;
56
+ static parse(input: null | undefined): ExactUri;
57
+ static parse(input: string | ExactUri | Partial<ExactUri_Parts>): ExactUri;
58
+ /**
59
+ * Checks if this URI (CHILD) matches another URI (PARENT). The parent can be a string,
60
+ * an {@link ExactUri}, or an object describing the parts of a URI -- an {@link ExactUri_Parts}.
61
+ *
62
+ * CHILD is considered to be a child of PARENT if:
63
+ * 1. If PARENT has a protocol, it must equal CHILD protocol.
64
+ * 2. If PARENT has a hostname, it must be a parent of CHILD's hostname.
65
+ * 3. If PARENT has a port, it must equal CHILD's port.
66
+ * 4. If PARENT has a path, it must be a parent of CHILD's path.
67
+ * 5. If PARENT has a query, it must equal CHILD's query.
68
+ * 6. If PARENT has a hash, it must equal CHILD's hash.
69
+ * @param parent The parent URI to check against.
70
+ */
71
+ matches(parent: Partial<ExactUri_Parts> | ExactUri | string): boolean;
72
+ /**
73
+ * Checks if this URI equals another URI, which can be given as a string, an
74
+ * {@link ExactUri}, or an object describing the parts of a URI -- an {@link ExactUri_Parts}.
75
+ * @param other The other URI to check against.
76
+ */
77
+ equal(other: string | ExactUri | Partial<ExactUri_Parts>): boolean;
78
+ get isArtificial(): boolean;
79
+ /**
80
+ * Does this URL have a non-web protocol?
81
+ */
82
+ get isNonWeb(): boolean;
83
+ /**
84
+ * Gets the full URI.
85
+ */
86
+ get href(): string;
87
+ private _print;
88
+ get [Symbol.toStringTag](): string;
89
+ toString(): string;
90
+ }
91
+ //# sourceMappingURL=exacturi.d.ts.map