@svta/cml-utils 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -20
- package/dist/index.d.ts +370 -368
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -81
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/arrayBufferToHex.ts","../src/arrayBufferToUuid.ts","../src/decodeBase64.ts","../src/base64decode.ts","../src/encodeBase64.ts","../src/base64encode.ts","../src/convertUint8ToUint16.ts","../src/UTF_16.ts","../src/UTF_16_BE.ts","../src/UTF_16_LE.ts","../src/UTF_8.ts","../src/ValueOf.ts","../src/Encoding.ts","../src/DecodeTextOptions.ts","../src/decodeText.ts","../src/DeepReadonly.ts","../src/encodeText.ts","../src/ExclusiveRecord.ts","../src/ResourceTiming.ts","../src/getBandwidthBps.ts","../src/getBaseUrl.ts","../src/hexToArrayBuffer.ts","../src/isArrayBufferLike.ts","../src/RequestResponseType.ts","../src/HttpRequest.ts","../src/XmlNode.ts","../src/ResponseTypeMap.ts","../src/HttpResponse.ts","../src/Request.ts","../src/roundToEven.ts","../src/stringToUint16.ts","../src/TypedResult.ts","../src/unescapeHtml.ts","../src/urlToRelativePath.ts","../src/uuid.ts","../src/uuidToArrayBuffer.ts","../src/ValueOrArray.ts"],"mappings":";;;;;;;;;;;;wBAWgB,iBAAiB,QAAQ;;;;;;;;;;;;;;wBCEzB,kBAAkB,QAAQ;;;;;;;;;;;wBCL1B,aAAa,cAAc;;;;;;;;;;;;;;;qBCM9B,qBAAqB;;;;;;;;;;;;;;wBCDlB,aAAa,QAAQ;;;;;;;;;;;;;;;qBCCxB,qBAAqB;;;;;;;;;;;wBCNlB,qBAAqB,OAAO,aAAa;;;;;;;;qBCH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EAKhD,SAAS;;;;EAKT;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA,UAAU;;;;EAKV,OAAO,gBAAgB;;;;EAKvB,iBAAiB;;;;;;;;;;KC9CN,UAAU;;;;;;;;;;;;;wBCEN,YAAY,eAAe;;;;;;;;;;;;;;wBCC3B,eAAe,cAAc;;;;;;;;YCNjC,YAAY,GAAG;EAC1B,MAAM;EACN,MAAM;;;;;;;;;;;;;;;wBCMS,aAAa;;;;;;;;;;;;;;;;;wBCKb,kBAAkB,aAAa;;;;;;;;;;;;;wBCN/B;;;;;;;;;;;;;;wBCCA,kBAAkB,eAAe;;;;;;;;YCRrC,aAAa,KAAK,IAAI"}
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
function arrayBufferToHex(buffer) {
|
|
14
14
|
return new Uint8Array(buffer).reduce((result, byte) => result + byte.toString(16).padStart(2, "0"), "");
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
//#endregion
|
|
18
17
|
//#region src/arrayBufferToUuid.ts
|
|
19
18
|
/**
|
|
@@ -30,7 +29,6 @@ function arrayBufferToHex(buffer) {
|
|
|
30
29
|
function arrayBufferToUuid(buffer) {
|
|
31
30
|
return arrayBufferToHex(buffer).replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
//#endregion
|
|
35
33
|
//#region src/decodeBase64.ts
|
|
36
34
|
/**
|
|
@@ -44,7 +42,6 @@ function arrayBufferToUuid(buffer) {
|
|
|
44
42
|
function decodeBase64(str) {
|
|
45
43
|
return new Uint8Array([...atob(str)].map((a) => a.charCodeAt(0)));
|
|
46
44
|
}
|
|
47
|
-
|
|
48
45
|
//#endregion
|
|
49
46
|
//#region src/base64decode.ts
|
|
50
47
|
/**
|
|
@@ -60,9 +57,9 @@ function decodeBase64(str) {
|
|
|
60
57
|
* @see {@link decodeBase64}
|
|
61
58
|
*/
|
|
62
59
|
const base64decode = decodeBase64;
|
|
63
|
-
|
|
64
60
|
//#endregion
|
|
65
61
|
//#region src/encodeBase64.ts
|
|
62
|
+
const CHUNK_SIZE = 32768;
|
|
66
63
|
/**
|
|
67
64
|
* Encodes binary data to base64
|
|
68
65
|
*
|
|
@@ -70,11 +67,18 @@ const base64decode = decodeBase64;
|
|
|
70
67
|
* @returns The base64 encoded string
|
|
71
68
|
*
|
|
72
69
|
* @public
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* {@includeCode ../test/encodeBase64.test.ts#example}
|
|
73
73
|
*/
|
|
74
74
|
function encodeBase64(binary) {
|
|
75
|
-
|
|
75
|
+
let text = "";
|
|
76
|
+
for (let i = 0; i < binary.length; i += CHUNK_SIZE) {
|
|
77
|
+
const chunk = binary.subarray(i, i + CHUNK_SIZE);
|
|
78
|
+
text += String.fromCharCode.apply(null, chunk);
|
|
79
|
+
}
|
|
80
|
+
return btoa(text);
|
|
76
81
|
}
|
|
77
|
-
|
|
78
82
|
//#endregion
|
|
79
83
|
//#region src/base64encode.ts
|
|
80
84
|
/**
|
|
@@ -90,7 +94,6 @@ function encodeBase64(binary) {
|
|
|
90
94
|
* @see {@link encodeBase64}
|
|
91
95
|
*/
|
|
92
96
|
const base64encode = encodeBase64;
|
|
93
|
-
|
|
94
97
|
//#endregion
|
|
95
98
|
//#region src/convertUint8ToUint16.ts
|
|
96
99
|
/**
|
|
@@ -109,16 +112,14 @@ function convertUint8ToUint16(input) {
|
|
|
109
112
|
}
|
|
110
113
|
return new Uint16Array(input.buffer);
|
|
111
114
|
}
|
|
112
|
-
|
|
113
115
|
//#endregion
|
|
114
116
|
//#region src/isArrayBufferLike.ts
|
|
115
117
|
/**
|
|
116
|
-
* Checks if the given value is `ArrayBufferLike
|
|
117
|
-
*
|
|
118
|
+
* Checks if the given value is `ArrayBufferLike`: an `ArrayBuffer` or a
|
|
119
|
+
* `SharedArrayBuffer`.
|
|
118
120
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* isolated browser contexts.
|
|
121
|
+
* The function also works where `SharedArrayBuffer` is not defined, such as
|
|
122
|
+
* browser contexts without cross-origin isolation.
|
|
122
123
|
*
|
|
123
124
|
* @param value - The value to check.
|
|
124
125
|
* @returns `true` if the value is an `ArrayBuffer` or `SharedArrayBuffer`.
|
|
@@ -131,7 +132,6 @@ function convertUint8ToUint16(input) {
|
|
|
131
132
|
function isArrayBufferLike(value) {
|
|
132
133
|
return value instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
|
|
133
134
|
}
|
|
134
|
-
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region src/UTF_16.ts
|
|
137
137
|
/**
|
|
@@ -140,7 +140,6 @@ function isArrayBufferLike(value) {
|
|
|
140
140
|
* @public
|
|
141
141
|
*/
|
|
142
142
|
const UTF_16 = "utf-16";
|
|
143
|
-
|
|
144
143
|
//#endregion
|
|
145
144
|
//#region src/UTF_16_BE.ts
|
|
146
145
|
/**
|
|
@@ -149,7 +148,6 @@ const UTF_16 = "utf-16";
|
|
|
149
148
|
* @public
|
|
150
149
|
*/
|
|
151
150
|
const UTF_16_BE = "utf-16be";
|
|
152
|
-
|
|
153
151
|
//#endregion
|
|
154
152
|
//#region src/UTF_16_LE.ts
|
|
155
153
|
/**
|
|
@@ -158,7 +156,6 @@ const UTF_16_BE = "utf-16be";
|
|
|
158
156
|
* @public
|
|
159
157
|
*/
|
|
160
158
|
const UTF_16_LE = "utf-16le";
|
|
161
|
-
|
|
162
159
|
//#endregion
|
|
163
160
|
//#region src/UTF_8.ts
|
|
164
161
|
/**
|
|
@@ -167,12 +164,11 @@ const UTF_16_LE = "utf-16le";
|
|
|
167
164
|
* @public
|
|
168
165
|
*/
|
|
169
166
|
const UTF_8 = "utf-8";
|
|
170
|
-
|
|
171
167
|
//#endregion
|
|
172
168
|
//#region src/decodeText.ts
|
|
173
169
|
/**
|
|
174
|
-
* Converts an ArrayBuffer or ArrayBufferView to a string.
|
|
175
|
-
*
|
|
170
|
+
* Converts an ArrayBuffer or ArrayBufferView to a string. The function works like
|
|
171
|
+
* `TextDecoder.decode` and also supports environments without `TextDecoder`.
|
|
176
172
|
*
|
|
177
173
|
* @param data - The data to decode.
|
|
178
174
|
* @param options - The options for the decoding.
|
|
@@ -213,49 +209,50 @@ function decodeText(data, options = {}) {
|
|
|
213
209
|
case UTF_8:
|
|
214
210
|
char = view.getUint8(byteOffset);
|
|
215
211
|
if (char < 128) byteOffset++;
|
|
216
|
-
else if (char >= 194 && char <= 223)
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
212
|
+
else if (char >= 194 && char <= 223) {
|
|
213
|
+
if (byteOffset + 1 < byteLength) {
|
|
214
|
+
const byte2 = view.getUint8(byteOffset + 1);
|
|
215
|
+
if (byte2 >= 128 && byte2 <= 191) {
|
|
216
|
+
char = (char & 31) << 6 | byte2 & 63;
|
|
217
|
+
byteOffset += 2;
|
|
218
|
+
} else byteOffset++;
|
|
221
219
|
} else byteOffset++;
|
|
222
|
-
} else
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
220
|
+
} else if (char >= 224 && char <= 239) {
|
|
221
|
+
if (byteOffset + 2 <= byteLength - 1) {
|
|
222
|
+
const byte2 = view.getUint8(byteOffset + 1);
|
|
223
|
+
const byte3 = view.getUint8(byteOffset + 2);
|
|
224
|
+
if (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191) {
|
|
225
|
+
char = (char & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
|
|
226
|
+
byteOffset += 3;
|
|
227
|
+
} else byteOffset++;
|
|
229
228
|
} else byteOffset++;
|
|
230
|
-
} else
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
229
|
+
} else if (char >= 240 && char <= 244) {
|
|
230
|
+
if (byteOffset + 3 <= byteLength - 1) {
|
|
231
|
+
const byte2 = view.getUint8(byteOffset + 1);
|
|
232
|
+
const byte3 = view.getUint8(byteOffset + 2);
|
|
233
|
+
const byte4 = view.getUint8(byteOffset + 3);
|
|
234
|
+
if (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191 && byte4 >= 128 && byte4 <= 191) {
|
|
235
|
+
char = (char & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
|
|
236
|
+
byteOffset += 4;
|
|
237
|
+
} else byteOffset++;
|
|
238
238
|
} else byteOffset++;
|
|
239
239
|
} else byteOffset++;
|
|
240
|
-
else byteOffset++;
|
|
241
240
|
break;
|
|
242
241
|
case UTF_16_BE:
|
|
243
242
|
case UTF_16:
|
|
244
243
|
case UTF_16_LE:
|
|
245
244
|
char = view.getUint16(byteOffset, endian);
|
|
246
245
|
byteOffset += 2;
|
|
247
|
-
break;
|
|
248
246
|
}
|
|
249
247
|
str += String.fromCodePoint(char);
|
|
250
248
|
}
|
|
251
249
|
return str;
|
|
252
250
|
}
|
|
253
|
-
|
|
254
251
|
//#endregion
|
|
255
252
|
//#region src/encodeText.ts
|
|
256
253
|
/**
|
|
257
|
-
* Converts a string to a Uint8Array.
|
|
258
|
-
*
|
|
254
|
+
* Converts a string to a Uint8Array. The function works like
|
|
255
|
+
* `TextEncoder.encode` and also supports environments without `TextEncoder`.
|
|
259
256
|
*
|
|
260
257
|
* @param data - The string to encode.
|
|
261
258
|
* @returns The Uint8Array representation of the string.
|
|
@@ -268,7 +265,6 @@ function decodeText(data, options = {}) {
|
|
|
268
265
|
function encodeText(data) {
|
|
269
266
|
return new TextEncoder().encode(data);
|
|
270
267
|
}
|
|
271
|
-
|
|
272
268
|
//#endregion
|
|
273
269
|
//#region src/Encoding.ts
|
|
274
270
|
/**
|
|
@@ -282,14 +278,13 @@ const Encoding = {
|
|
|
282
278
|
UTF16BE: UTF_16_BE,
|
|
283
279
|
UTF16LE: UTF_16_LE
|
|
284
280
|
};
|
|
285
|
-
|
|
286
281
|
//#endregion
|
|
287
282
|
//#region src/getBandwidthBps.ts
|
|
288
283
|
/**
|
|
289
|
-
* Converts a ResourceTiming sample to bandwidth in bits per second
|
|
284
|
+
* Converts a ResourceTiming sample to bandwidth in bits per second.
|
|
290
285
|
*
|
|
291
286
|
* @param sample - A ResourceTiming sample
|
|
292
|
-
* @returns
|
|
287
|
+
* @returns The bandwidth in bits per second.
|
|
293
288
|
*
|
|
294
289
|
* @public
|
|
295
290
|
*/
|
|
@@ -297,11 +292,10 @@ function getBandwidthBps(sample) {
|
|
|
297
292
|
const durationSeconds = sample.duration / 1e3;
|
|
298
293
|
return sample.encodedBodySize * 8 / durationSeconds;
|
|
299
294
|
}
|
|
300
|
-
|
|
301
295
|
//#endregion
|
|
302
296
|
//#region src/getBaseUrl.ts
|
|
303
297
|
/**
|
|
304
|
-
*
|
|
298
|
+
* Gets the base URL from a full URL or a URL object.
|
|
305
299
|
*
|
|
306
300
|
* @param fullUrl - The full URL or URL object.
|
|
307
301
|
* @returns The base URL.
|
|
@@ -315,7 +309,6 @@ function getBaseUrl(fullUrl) {
|
|
|
315
309
|
const url = typeof fullUrl === "string" ? new URL(fullUrl) : fullUrl;
|
|
316
310
|
return url.origin + url.pathname.substring(0, url.pathname.lastIndexOf("/") + 1);
|
|
317
311
|
}
|
|
318
|
-
|
|
319
312
|
//#endregion
|
|
320
313
|
//#region src/hexToArrayBuffer.ts
|
|
321
314
|
/**
|
|
@@ -335,7 +328,6 @@ function hexToArrayBuffer(hex) {
|
|
|
335
328
|
for (let i = 0; i < hex.length; i += 2) view[i / 2] = parseInt(hex.slice(i, i + 2), 16);
|
|
336
329
|
return buffer;
|
|
337
330
|
}
|
|
338
|
-
|
|
339
331
|
//#endregion
|
|
340
332
|
//#region src/RequestResponseType.ts
|
|
341
333
|
/**
|
|
@@ -353,12 +345,11 @@ const RequestResponseType = {
|
|
|
353
345
|
DOCUMENT: "document",
|
|
354
346
|
STREAM: "stream"
|
|
355
347
|
};
|
|
356
|
-
|
|
357
348
|
//#endregion
|
|
358
349
|
//#region src/roundToEven.ts
|
|
359
350
|
/**
|
|
360
|
-
*
|
|
361
|
-
*
|
|
351
|
+
* Rounds a value with the procedure from step 2 of the "Serializing a Decimal" specification.
|
|
352
|
+
* The style is known as "even rounding", "banker's rounding", or "commercial rounding".
|
|
362
353
|
*
|
|
363
354
|
* @param value - The value to round
|
|
364
355
|
* @param precision - The number of decimal places to round to
|
|
@@ -374,7 +365,6 @@ function roundToEven(value, precision) {
|
|
|
374
365
|
return (flooredValue % 2 === 0 ? flooredValue : flooredValue + 1) / decimalShift;
|
|
375
366
|
} else return Math.round(value * decimalShift) / decimalShift;
|
|
376
367
|
}
|
|
377
|
-
|
|
378
368
|
//#endregion
|
|
379
369
|
//#region src/stringToUint16.ts
|
|
380
370
|
/**
|
|
@@ -394,7 +384,6 @@ function stringToUint16(str) {
|
|
|
394
384
|
for (let i = 0; i < str.length; i++) view.setUint16(i * 2, str.charCodeAt(i), true);
|
|
395
385
|
return new Uint16Array(buffer);
|
|
396
386
|
}
|
|
397
|
-
|
|
398
387
|
//#endregion
|
|
399
388
|
//#region src/unescapeHtml.ts
|
|
400
389
|
const escapedHtml = /&(?:amp|lt|gt|quot|apos|nbsp|lrm|rlm|#[xX]?[0-9a-fA-F]+);/g;
|
|
@@ -430,13 +419,13 @@ function unescapeHtml(text) {
|
|
|
430
419
|
}
|
|
431
420
|
});
|
|
432
421
|
}
|
|
433
|
-
|
|
434
422
|
//#endregion
|
|
435
423
|
//#region src/urlToRelativePath.ts
|
|
424
|
+
const SCHEME_REGEX = /^[\0-\x20]*[a-z][a-z0-9+.\t\n\r-]*:/i;
|
|
436
425
|
/**
|
|
437
426
|
* Constructs a relative path from a URL.
|
|
438
427
|
*
|
|
439
|
-
* If `url` is already
|
|
428
|
+
* If `url` is already relative, or its origin differs from `base`, the function returns `url` unchanged.
|
|
440
429
|
*
|
|
441
430
|
* @param url - The destination URL
|
|
442
431
|
* @param base - The base URL
|
|
@@ -448,6 +437,7 @@ function unescapeHtml(text) {
|
|
|
448
437
|
* {@includeCode ../test/urlToRelativePath.test.ts#example}
|
|
449
438
|
*/
|
|
450
439
|
function urlToRelativePath(url, base) {
|
|
440
|
+
if (!SCHEME_REGEX.test(url)) return url;
|
|
451
441
|
let to;
|
|
452
442
|
try {
|
|
453
443
|
to = new URL(url);
|
|
@@ -458,23 +448,17 @@ function urlToRelativePath(url, base) {
|
|
|
458
448
|
if (to.origin !== from.origin) return url;
|
|
459
449
|
const toPath = to.pathname.split("/").slice(1);
|
|
460
450
|
const fromPath = from.pathname.split("/").slice(1, -1);
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
while (fromPath.length) {
|
|
468
|
-
fromPath.shift();
|
|
469
|
-
toPath.unshift("..");
|
|
470
|
-
}
|
|
471
|
-
return toPath.join("/") + to.search + to.hash;
|
|
451
|
+
let common = 0;
|
|
452
|
+
while (common < toPath.length - 1 && common < fromPath.length && toPath[common] === fromPath[common]) common++;
|
|
453
|
+
const ups = fromPath.length - common;
|
|
454
|
+
let relativePath = "../".repeat(ups) + toPath.slice(common).join("/");
|
|
455
|
+
if (ups === 0 && (relativePath === "" || relativePath.startsWith("/") || toPath[common].includes(":"))) relativePath = "./" + relativePath;
|
|
456
|
+
return relativePath + to.search + to.hash;
|
|
472
457
|
}
|
|
473
|
-
|
|
474
458
|
//#endregion
|
|
475
459
|
//#region src/uuid.ts
|
|
476
460
|
/**
|
|
477
|
-
*
|
|
461
|
+
* Generates a random v4 UUID
|
|
478
462
|
*
|
|
479
463
|
* @returns A random v4 UUID
|
|
480
464
|
*
|
|
@@ -488,19 +472,18 @@ function uuid() {
|
|
|
488
472
|
return crypto.randomUUID();
|
|
489
473
|
} catch (error) {
|
|
490
474
|
try {
|
|
491
|
-
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
475
|
+
const bytes = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
492
476
|
bytes[6] = bytes[6] & 15 | 64;
|
|
493
477
|
bytes[8] = bytes[8] & 63 | 128;
|
|
494
478
|
return arrayBufferToUuid(bytes.buffer);
|
|
495
|
-
} catch (error
|
|
479
|
+
} catch (error) {
|
|
496
480
|
const url = URL.createObjectURL(new Blob());
|
|
497
|
-
const uuid
|
|
481
|
+
const uuid = url.toString();
|
|
498
482
|
URL.revokeObjectURL(url);
|
|
499
|
-
return uuid
|
|
483
|
+
return uuid.slice(uuid.lastIndexOf("/") + 1);
|
|
500
484
|
}
|
|
501
485
|
}
|
|
502
486
|
}
|
|
503
|
-
|
|
504
487
|
//#endregion
|
|
505
488
|
//#region src/uuidToArrayBuffer.ts
|
|
506
489
|
/**
|
|
@@ -514,10 +497,10 @@ function uuid() {
|
|
|
514
497
|
* @example
|
|
515
498
|
* {@includeCode ../test/uuidToArrayBuffer.test.ts#example}
|
|
516
499
|
*/
|
|
517
|
-
function uuidToArrayBuffer(uuid
|
|
518
|
-
return hexToArrayBuffer(uuid
|
|
500
|
+
function uuidToArrayBuffer(uuid) {
|
|
501
|
+
return hexToArrayBuffer(uuid.replace(/-/g, ""));
|
|
519
502
|
}
|
|
520
|
-
|
|
521
503
|
//#endregion
|
|
522
504
|
export { Encoding, RequestResponseType, UTF_16, UTF_16_BE, UTF_16_LE, UTF_8, arrayBufferToHex, arrayBufferToUuid, base64decode, base64encode, convertUint8ToUint16, decodeBase64, decodeText, encodeBase64, encodeText, getBandwidthBps, getBaseUrl, hexToArrayBuffer, isArrayBufferLike, roundToEven, stringToUint16, unescapeHtml, urlToRelativePath, uuid, uuidToArrayBuffer };
|
|
505
|
+
|
|
523
506
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["base64decode: typeof decodeBase64","base64encode: typeof encodeBase64","view: DataView","char!: number","to: URL","error","uuid","uuid"],"sources":["../src/arrayBufferToHex.ts","../src/arrayBufferToUuid.ts","../src/decodeBase64.ts","../src/base64decode.ts","../src/encodeBase64.ts","../src/base64encode.ts","../src/convertUint8ToUint16.ts","../src/isArrayBufferLike.ts","../src/UTF_16.ts","../src/UTF_16_BE.ts","../src/UTF_16_LE.ts","../src/UTF_8.ts","../src/decodeText.ts","../src/encodeText.ts","../src/Encoding.ts","../src/getBandwidthBps.ts","../src/getBaseUrl.ts","../src/hexToArrayBuffer.ts","../src/RequestResponseType.ts","../src/roundToEven.ts","../src/stringToUint16.ts","../src/unescapeHtml.ts","../src/urlToRelativePath.ts","../src/uuid.ts","../src/uuidToArrayBuffer.ts"],"sourcesContent":["/**\n * Encodes an ArrayBuffer as a hexadecimal string.\n *\n * @param buffer - The ArrayBuffer to encode.\n * @returns The hexadecimal string representation.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/arrayBufferToHex.test.ts#example}\n */\nexport function arrayBufferToHex(buffer: ArrayBuffer): string {\n\tconst view = new Uint8Array(buffer)\n\treturn view.reduce((result, byte) => result + byte.toString(16).padStart(2, '0'), '')\n}\n","import { arrayBufferToHex } from './arrayBufferToHex.ts'\n\n/**\n * Converts an ArrayBuffer to a UUID string.\n *\n * @param buffer - The ArrayBuffer to convert.\n * @returns The UUID string representation.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/arrayBufferToUuid.test.ts#example}\n */\nexport function arrayBufferToUuid(buffer: ArrayBuffer): string {\n\tconst hex = arrayBufferToHex(buffer)\n\treturn hex.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '$1-$2-$3-$4-$5')\n}\n","/**\n * Decodes a base64 encoded string into binary data\n *\n * @param str - The base64 encoded string to decode\n * @returns The decoded binary data\n *\n * @public\n */\nexport function decodeBase64(str: string): Uint8Array {\n\treturn new Uint8Array([...atob(str)].map((a) => a.charCodeAt(0)))\n}\n","import { decodeBase64 } from './decodeBase64.ts'\n\n/**\n * Decodes a base64 encoded string into binary data\n *\n * @param str - The base64 encoded string to decode\n * @returns The decoded binary data\n *\n * @public\n *\n * @deprecated Use {@link decodeBase64} instead.\n *\n * @see {@link decodeBase64}\n */\nexport const base64decode: typeof decodeBase64 = decodeBase64\n","/**\n * Encodes binary data to base64\n *\n * @param binary - The binary data to encode\n * @returns The base64 encoded string\n *\n * @public\n */\nexport function encodeBase64(binary: Uint8Array): string {\n\treturn btoa(String.fromCharCode(...binary))\n}\n","import { encodeBase64 } from './encodeBase64.ts'\n\n/**\n * Encodes binary data to base64\n *\n * @param binary - The binary data to encode\n * @returns The base64 encoded string\n *\n * @public\n *\n * @deprecated Use {@link encodeBase64} instead.\n *\n * @see {@link encodeBase64}\n */\nexport const base64encode: typeof encodeBase64 = encodeBase64\n","/**\n * Converts a Uint8Array to a Uint16Array by aligning its buffer.\n *\n * @param input - The Uint8Array to convert\n * @returns A properly aligned Uint16Array\n *\n * @public\n */\nexport function convertUint8ToUint16(input: Uint8Array): Uint16Array {\n\tif (input.length % 2 !== 0) {\n\t\tconst padded = new Uint8Array(input.length + 1)\n\t\tpadded.set(input)\n\t\treturn new Uint16Array(padded.buffer)\n\t}\n\treturn new Uint16Array(input.buffer)\n}\n","/**\n * Checks if the given value is `ArrayBufferLike` (i.e. an `ArrayBuffer`\n * or a `SharedArrayBuffer`).\n *\n * This function safely handles environments where\n * `SharedArrayBuffer` is not defined, such as non-cross-origin\n * isolated browser contexts.\n *\n * @param value - The value to check.\n * @returns `true` if the value is an `ArrayBuffer` or `SharedArrayBuffer`.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/isArrayBufferLike.test.ts#example}\n */\nexport function isArrayBufferLike(value: unknown): value is ArrayBufferLike {\n\treturn value instanceof ArrayBuffer\n\t\t|| (typeof SharedArrayBuffer !== 'undefined' && value instanceof SharedArrayBuffer)\n}\n","/**\n * UTF-16 Encoding.\n *\n * @public\n */\nexport const UTF_16 = 'utf-16'\n","/**\n * UTF-16 Big Endian Encoding.\n *\n * @public\n */\nexport const UTF_16_BE = 'utf-16be'\n","/**\n * UTF-16 Little Endian Encoding.\n *\n * @public\n */\nexport const UTF_16_LE = 'utf-16le'\n","/**\n * UTF-8 Encoding.\n *\n * @public\n */\nexport const UTF_8 = 'utf-8'\n","import type { DecodeTextOptions } from './DecodeTextOptions.ts'\nimport { isArrayBufferLike } from './isArrayBufferLike.ts'\nimport { UTF_16 } from './UTF_16.ts'\nimport { UTF_16_BE } from './UTF_16_BE.ts'\nimport { UTF_16_LE } from './UTF_16_LE.ts'\nimport { UTF_8 } from './UTF_8.ts'\n\n/**\n * Converts an ArrayBuffer or ArrayBufferView to a string. Similar to `TextDecoder.decode`\n * but with a fallback for environments that don't support `TextDecoder`.\n *\n * @param data - The data to decode.\n * @param options - The options for the decoding.\n * @returns The string representation of the ArrayBuffer.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/decodeText.test.ts#example}\n */\nexport function decodeText(data: ArrayBufferLike | ArrayBufferView, options: DecodeTextOptions = {}): string {\n\tlet view: DataView\n\n\tif (isArrayBufferLike(data)) {\n\t\tview = new DataView(data)\n\t}\n\telse {\n\t\tview = new DataView(data.buffer, data.byteOffset, data.byteLength)\n\t}\n\n\tlet byteOffset = 0\n\tlet { encoding } = options\n\n\t// If no encoding is provided, try to detect it from the BOM\n\tif (!encoding) {\n\t\tconst first = view.getUint8(0)\n\t\tconst second = view.getUint8(1)\n\n\t\t// UTF-8 BOM\n\t\tif (first == 0xef && second == 0xbb && view.getUint8(2) == 0xbf) {\n\t\t\tencoding = UTF_8\n\t\t\tbyteOffset = 3\n\t\t}\n\t\t// UTF-16 BE BOM\n\t\telse if (first == 0xfe && second == 0xff) {\n\t\t\tencoding = UTF_16_BE\n\t\t\tbyteOffset = 2\n\t\t}\n\t\t// UTF-16 LE BOM\n\t\telse if (first == 0xff && second == 0xfe) {\n\t\t\tencoding = UTF_16_LE\n\t\t\tbyteOffset = 2\n\t\t}\n\t\telse {\n\t\t\tencoding = UTF_8\n\t\t}\n\t}\n\n\tif (typeof TextDecoder !== 'undefined') {\n\t\treturn new TextDecoder(encoding).decode(view)\n\t}\n\n\tconst { byteLength } = view\n\tconst endian = encoding !== UTF_16_BE\n\tlet str = ''\n\tlet char!: number\n\n\twhile (byteOffset < byteLength) {\n\t\tswitch (encoding) {\n\t\t\tcase UTF_8:\n\t\t\t\tchar = view.getUint8(byteOffset)\n\n\t\t\t\t// Single byte (ASCII)\n\t\t\t\tif (char < 128) {\n\t\t\t\t\tbyteOffset++\n\t\t\t\t}\n\t\t\t\t// 2-byte sequence\n\t\t\t\telse if (char >= 194 && char <= 223) {\n\t\t\t\t\tif (byteOffset + 1 < byteLength) {\n\t\t\t\t\t\tconst byte2 = view.getUint8(byteOffset + 1)\n\t\t\t\t\t\tif (byte2 >= 128 && byte2 <= 191) {\n\t\t\t\t\t\t\tchar = ((char & 0x1F) << 6) | (byte2 & 0x3F)\n\t\t\t\t\t\t\tbyteOffset += 2\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t// Invalid sequence, skip\n\t\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Incomplete sequence, skip\n\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// 3-byte sequence\n\t\t\t\telse if (char >= 224 && char <= 239) {\n\t\t\t\t\tif (byteOffset + 2 <= byteLength - 1) {\n\t\t\t\t\t\tconst byte2 = view.getUint8(byteOffset + 1)\n\t\t\t\t\t\tconst byte3 = view.getUint8(byteOffset + 2)\n\t\t\t\t\t\tif (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191) {\n\t\t\t\t\t\t\tchar = ((char & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F)\n\t\t\t\t\t\t\tbyteOffset += 3\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t// Invalid sequence, skip\n\t\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Incomplete sequence, skip\n\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// 4-byte sequence\n\t\t\t\telse if (char >= 240 && char <= 244) {\n\t\t\t\t\tif (byteOffset + 3 <= byteLength - 1) {\n\t\t\t\t\t\tconst byte2 = view.getUint8(byteOffset + 1)\n\t\t\t\t\t\tconst byte3 = view.getUint8(byteOffset + 2)\n\t\t\t\t\t\tconst byte4 = view.getUint8(byteOffset + 3)\n\t\t\t\t\t\tif (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191 && byte4 >= 128 && byte4 <= 191) {\n\t\t\t\t\t\t\tchar = ((char & 0x07) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F)\n\t\t\t\t\t\t\tbyteOffset += 4\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t// Invalid sequence, skip\n\t\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Incomplete sequence, skip\n\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Invalid byte, skip\n\t\t\t\telse {\n\t\t\t\t\tbyteOffset++\n\t\t\t\t}\n\t\t\t\tbreak\n\n\t\t\tcase UTF_16_BE:\n\t\t\tcase UTF_16:\n\t\t\tcase UTF_16_LE:\n\t\t\t\tchar = view.getUint16(byteOffset, endian)\n\t\t\t\tbyteOffset += 2\n\t\t\t\tbreak\n\t\t}\n\n\t\tstr += String.fromCodePoint(char)\n\t}\n\n\treturn str\n}\n","\n/**\n * Converts a string to a Uint8Array. Similar to `TextEncoder.encode`\n * but with a fallback for environments that don't support `TextEncoder`.\n *\n * @param data - The string to encode.\n * @returns The Uint8Array representation of the string.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/encodeText.test.ts#example}\n */\nexport function encodeText(data: string): Uint8Array {\n\treturn new TextEncoder().encode(data)\n}\n","import { UTF_16 } from './UTF_16.ts'\nimport { UTF_16_BE } from './UTF_16_BE.ts'\nimport { UTF_16_LE } from './UTF_16_LE.ts'\nimport { UTF_8 } from './UTF_8.ts'\nimport type { ValueOf } from './ValueOf.ts'\n\n/**\n * Text encoding types.\n *\n * @public\n */\nexport const Encoding = {\n\tUTF8: UTF_8 as typeof UTF_8,\n\tUTF16: UTF_16 as typeof UTF_16,\n\tUTF16BE: UTF_16_BE as typeof UTF_16_BE,\n\tUTF16LE: UTF_16_LE as typeof UTF_16_LE,\n} as const\n\n/**\n * Text encoding types.\n *\n * @public\n */\nexport type Encoding = ValueOf<typeof Encoding>;\n","import type { ResourceTiming } from './ResourceTiming.ts'\n\n/**\n * Converts a ResourceTiming sample to bandwidth in bits per second (bps).\n *\n * @param sample - A ResourceTiming sample\n * @returns\n *\n * @public\n */\nexport function getBandwidthBps(sample: ResourceTiming): number {\n\tconst durationSeconds = sample.duration / 1000\n\tconst bandwidthBps = sample.encodedBodySize * 8 / durationSeconds\n\treturn bandwidthBps\n}\n","/**\n * Get the base URL from a full URL or a URL object.\n *\n * @param fullUrl - The full URL or URL object.\n * @returns The base URL.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/getBaseUrl.test.ts#example}\n */\nexport function getBaseUrl(fullUrl: string | URL): string {\n\tconst url = typeof fullUrl === 'string' ? new URL(fullUrl) : fullUrl\n\treturn url.origin + url.pathname.substring(0, url.pathname.lastIndexOf('/') + 1)\n}\n","/**\n * Decodes a hexadecimal string into an ArrayBuffer.\n *\n * @param hex - The hexadecimal string to decode.\n * @returns The decoded ArrayBuffer.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/hexToArrayBuffer.test.ts#example}\n */\nexport function hexToArrayBuffer(hex: string): ArrayBuffer {\n\tconst buffer = new ArrayBuffer(hex.length / 2)\n\tconst view = new Uint8Array(buffer)\n\tfor (let i = 0; i < hex.length; i += 2) {\n\t\tview[i / 2] = parseInt(hex.slice(i, i + 2), 16)\n\t}\n\treturn buffer\n}\n","import type { ValueOf } from './ValueOf.ts'\n\n/**\n * The response type of the request.\n *\n * @enum\n *\n * @public\n */\nexport const RequestResponseType = {\n\tTEXT: 'text' as const,\n\tJSON: 'json' as const,\n\tBLOB: 'blob' as const,\n\tARRAY_BUFFER: 'arrayBuffer' as const,\n\tDOCUMENT: 'document' as const,\n\tSTREAM: 'stream' as const,\n} as const\n\n/**\n * @public\n */\nexport type RequestResponseType = ValueOf<typeof RequestResponseType>;\n","/**\n * This implements the rounding procedure described in step 2 of the \"Serializing a Decimal\" specification.\n * This rounding style is known as \"even rounding\", \"banker's rounding\", or \"commercial rounding\".\n *\n * @param value - The value to round\n * @param precision - The number of decimal places to round to\n * @returns The rounded value\n *\n * @public\n */\nexport function roundToEven(value: number, precision: number): number {\n\tif (value < 0) {\n\t\treturn -roundToEven(-value, precision)\n\t}\n\n\tconst decimalShift = Math.pow(10, precision)\n\tconst isEquidistant = Math.abs(((value * decimalShift) % 1) - 0.5) < Number.EPSILON\n\n\tif (isEquidistant) {\n\t\t// If the tail of the decimal place is 'equidistant' we round to the nearest even value\n\t\tconst flooredValue = Math.floor(value * decimalShift)\n\t\treturn (flooredValue % 2 === 0 ? flooredValue : flooredValue + 1) / decimalShift\n\t}\n\telse {\n\t\t// Otherwise, proceed as normal\n\t\treturn Math.round(value * decimalShift) / decimalShift\n\t}\n}\n","/**\n * Converts a string to a Uint16Array.\n *\n * @param str - The string to convert\n * @returns A Uint16Array representation of the string\n *\n * @public\n *\n * @example\n * {@includeCode ../test/stringToUint16.test.ts#example}\n */\nexport function stringToUint16(str: string): Uint16Array {\n\tconst buffer = new ArrayBuffer(str.length * 2)\n\tconst view = new DataView(buffer)\n\n\tfor (let i = 0; i < str.length; i++) {\n\t\tview.setUint16(i * 2, str.charCodeAt(i), true) // true for little-endian\n\t}\n\n\treturn new Uint16Array(buffer)\n}\n","const escapedHtml = /&(?:amp|lt|gt|quot|apos|nbsp|lrm|rlm|#[xX]?[0-9a-fA-F]+);/g\n\n/**\n * Unescapes HTML entities\n *\n * @param text - The text to unescape\n * @returns The unescaped text\n *\n * @public\n *\n * @example\n * {@includeCode ../test/unescapeHtml.test.ts#example}\n */\nexport function unescapeHtml(text: string): string {\n\tif (text.indexOf('&') === -1) {\n\t\treturn text\n\t}\n\n\treturn text.replace(escapedHtml, (match) => {\n\t\tswitch (match) {\n\t\t\tcase '&': return '&'\n\t\t\tcase '<': return '<'\n\t\t\tcase '>': return '>'\n\t\t\tcase '"': return '\"'\n\t\t\tcase ''': return '\\''\n\t\t\tcase ' ': return '\\u{a0}'\n\t\t\tcase '‎': return '\\u{200e}'\n\t\t\tcase '‏': return '\\u{200f}'\n\t\t\tdefault: {\n\t\t\t\tif (match[1] === '#') {\n\t\t\t\t\tconst code = match[2] === 'x' || match[2] === 'X' ? parseInt(match.slice(3), 16) : parseInt(match.slice(2), 10)\n\t\t\t\t\treturn String.fromCodePoint(code)\n\t\t\t\t}\n\t\t\t\treturn match\n\t\t\t}\n\t\t}\n\t})\n}\n","/**\n * Constructs a relative path from a URL.\n *\n * If `url` is already a relative path, or its origin differs from `base`, it is returned unchanged.\n *\n * @param url - The destination URL\n * @param base - The base URL\n * @returns The relative path\n *\n * @public\n *\n * @example\n * {@includeCode ../test/urlToRelativePath.test.ts#example}\n */\nexport function urlToRelativePath(url: string, base: string): string {\n\tlet to: URL\n\ttry {\n\t\tto = new URL(url)\n\t}\n\tcatch {\n\t\treturn url\n\t}\n\n\tconst from = new URL(base)\n\n\tif (to.origin !== from.origin) {\n\t\treturn url\n\t}\n\n\tconst toPath = to.pathname.split('/').slice(1)\n\tconst fromPath = from.pathname.split('/').slice(1, -1)\n\n\t// remove common parents\n\tconst length = Math.min(toPath.length, fromPath.length)\n\n\tfor (let i = 0; i < length; i++) {\n\t\tif (toPath[i] !== fromPath[i]) {\n\t\t\tbreak\n\t\t}\n\n\t\ttoPath.shift()\n\t\tfromPath.shift()\n\t}\n\n\t// add back paths\n\twhile (fromPath.length) {\n\t\tfromPath.shift()\n\t\ttoPath.unshift('..')\n\t}\n\n\tconst relativePath = toPath.join('/')\n\n\t// preserve query parameters and hash of the destination url\n\treturn relativePath + to.search + to.hash\n}\n","import { arrayBufferToUuid } from './arrayBufferToUuid.ts'\n\n/**\n * Generate a random v4 UUID\n *\n * @returns A random v4 UUID\n *\n * @public\n *\n * @example\n * {@includeCode ../test/uuid.test.ts#example}\n */\nexport function uuid(): string {\n\ttry {\n\t\treturn crypto.randomUUID()\n\t}\n\tcatch (error) {\n\t\ttry {\n\t\t\tconst bytes = crypto.getRandomValues(new Uint8Array(16))\n\n\t\t\t// Set the version (4) and variant (RFC 4122) bits\n\t\t\tbytes[6] = (bytes[6] & 0x0f) | 0x40\n\t\t\tbytes[8] = (bytes[8] & 0x3f) | 0x80\n\n\t\t\treturn arrayBufferToUuid(bytes.buffer)\n\t\t}\n\t\tcatch (error) {\n\t\t\tconst url = URL.createObjectURL(new Blob())\n\t\t\tconst uuid = url.toString()\n\t\t\tURL.revokeObjectURL(url)\n\t\t\treturn uuid.slice(uuid.lastIndexOf('/') + 1)\n\t\t}\n\t}\n}\n","import { hexToArrayBuffer } from './hexToArrayBuffer.ts'\n\n/**\n * Converts a UUID string to an ArrayBuffer.\n *\n * @param uuid - The UUID string to convert.\n * @returns The ArrayBuffer representation.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/uuidToArrayBuffer.test.ts#example}\n */\nexport function uuidToArrayBuffer(uuid: string): ArrayBuffer {\n\tconst hex = uuid.replace(/-/g, '')\n\treturn hexToArrayBuffer(hex)\n}\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,iBAAiB,QAA6B;AAE7D,QADa,IAAI,WAAW,OAAO,CACvB,QAAQ,QAAQ,SAAS,SAAS,KAAK,SAAS,GA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src/base64encode.ts","../src/convertUint8ToUint16.ts","../src/isArrayBufferLike.ts","../src/UTF_16.ts","../src/UTF_16_BE.ts","../src/UTF_16_LE.ts","../src/UTF_8.ts","../src/decodeText.ts","../src/encodeText.ts","../src/Encoding.ts","../src/getBandwidthBps.ts","../src/getBaseUrl.ts","../src/hexToArrayBuffer.ts","../src/RequestResponseType.ts","../src/roundToEven.ts","../src/stringToUint16.ts","../src/unescapeHtml.ts","../src/urlToRelativePath.ts","../src/uuid.ts","../src/uuidToArrayBuffer.ts"],"sourcesContent":["/**\n * Encodes an ArrayBuffer as a hexadecimal string.\n *\n * @param buffer - The ArrayBuffer to encode.\n * @returns The hexadecimal string representation.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/arrayBufferToHex.test.ts#example}\n */\nexport function arrayBufferToHex(buffer: ArrayBuffer): string {\n\tconst view = new Uint8Array(buffer)\n\treturn view.reduce((result, byte) => result + byte.toString(16).padStart(2, '0'), '')\n}\n","import { arrayBufferToHex } from './arrayBufferToHex.ts'\n\n/**\n * Converts an ArrayBuffer to a UUID string.\n *\n * @param buffer - The ArrayBuffer to convert.\n * @returns The UUID string representation.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/arrayBufferToUuid.test.ts#example}\n */\nexport function arrayBufferToUuid(buffer: ArrayBuffer): string {\n\tconst hex = arrayBufferToHex(buffer)\n\treturn hex.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '$1-$2-$3-$4-$5')\n}\n","/**\n * Decodes a base64 encoded string into binary data\n *\n * @param str - The base64 encoded string to decode\n * @returns The decoded binary data\n *\n * @public\n */\nexport function decodeBase64(str: string): Uint8Array {\n\treturn new Uint8Array([...atob(str)].map((a) => a.charCodeAt(0)))\n}\n","import { decodeBase64 } from './decodeBase64.ts'\n\n/**\n * Decodes a base64 encoded string into binary data\n *\n * @param str - The base64 encoded string to decode\n * @returns The decoded binary data\n *\n * @public\n *\n * @deprecated Use {@link decodeBase64} instead.\n *\n * @see {@link decodeBase64}\n */\nexport const base64decode: typeof decodeBase64 = decodeBase64\n","const CHUNK_SIZE = 0x8000\n\n/**\n * Encodes binary data to base64\n *\n * @param binary - The binary data to encode\n * @returns The base64 encoded string\n *\n * @public\n *\n * @example\n * {@includeCode ../test/encodeBase64.test.ts#example}\n */\nexport function encodeBase64(binary: Uint8Array): string {\n\tlet text = ''\n\n\tfor (let i = 0; i < binary.length; i += CHUNK_SIZE) {\n\t\tconst chunk: ArrayLike<number> = binary.subarray(i, i + CHUNK_SIZE)\n\t\ttext += String.fromCharCode.apply(null, chunk as number[])\n\t}\n\n\treturn btoa(text)\n}\n","import { encodeBase64 } from './encodeBase64.ts'\n\n/**\n * Encodes binary data to base64\n *\n * @param binary - The binary data to encode\n * @returns The base64 encoded string\n *\n * @public\n *\n * @deprecated Use {@link encodeBase64} instead.\n *\n * @see {@link encodeBase64}\n */\nexport const base64encode: typeof encodeBase64 = encodeBase64\n","/**\n * Converts a Uint8Array to a Uint16Array by aligning its buffer.\n *\n * @param input - The Uint8Array to convert\n * @returns A properly aligned Uint16Array\n *\n * @public\n */\nexport function convertUint8ToUint16(input: Uint8Array): Uint16Array {\n\tif (input.length % 2 !== 0) {\n\t\tconst padded = new Uint8Array(input.length + 1)\n\t\tpadded.set(input)\n\t\treturn new Uint16Array(padded.buffer)\n\t}\n\treturn new Uint16Array(input.buffer)\n}\n","/**\n * Checks if the given value is `ArrayBufferLike`: an `ArrayBuffer` or a\n * `SharedArrayBuffer`.\n *\n * The function also works where `SharedArrayBuffer` is not defined, such as\n * browser contexts without cross-origin isolation.\n *\n * @param value - The value to check.\n * @returns `true` if the value is an `ArrayBuffer` or `SharedArrayBuffer`.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/isArrayBufferLike.test.ts#example}\n */\nexport function isArrayBufferLike(value: unknown): value is ArrayBufferLike {\n\treturn value instanceof ArrayBuffer\n\t\t|| (typeof SharedArrayBuffer !== 'undefined' && value instanceof SharedArrayBuffer)\n}\n","/**\n * UTF-16 Encoding.\n *\n * @public\n */\nexport const UTF_16 = 'utf-16'\n","/**\n * UTF-16 Big Endian Encoding.\n *\n * @public\n */\nexport const UTF_16_BE = 'utf-16be'\n","/**\n * UTF-16 Little Endian Encoding.\n *\n * @public\n */\nexport const UTF_16_LE = 'utf-16le'\n","/**\n * UTF-8 Encoding.\n *\n * @public\n */\nexport const UTF_8 = 'utf-8'\n","import type { DecodeTextOptions } from './DecodeTextOptions.ts'\nimport { isArrayBufferLike } from './isArrayBufferLike.ts'\nimport { UTF_16 } from './UTF_16.ts'\nimport { UTF_16_BE } from './UTF_16_BE.ts'\nimport { UTF_16_LE } from './UTF_16_LE.ts'\nimport { UTF_8 } from './UTF_8.ts'\n\n/**\n * Converts an ArrayBuffer or ArrayBufferView to a string. The function works like\n * `TextDecoder.decode` and also supports environments without `TextDecoder`.\n *\n * @param data - The data to decode.\n * @param options - The options for the decoding.\n * @returns The string representation of the ArrayBuffer.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/decodeText.test.ts#example}\n */\nexport function decodeText(data: ArrayBufferLike | ArrayBufferView, options: DecodeTextOptions = {}): string {\n\tlet view: DataView\n\n\tif (isArrayBufferLike(data)) {\n\t\tview = new DataView(data)\n\t}\n\telse {\n\t\tview = new DataView(data.buffer, data.byteOffset, data.byteLength)\n\t}\n\n\tlet byteOffset = 0\n\tlet { encoding } = options\n\n\t// If no encoding is provided, try to detect it from the BOM\n\tif (!encoding) {\n\t\tconst first = view.getUint8(0)\n\t\tconst second = view.getUint8(1)\n\n\t\t// UTF-8 BOM\n\t\tif (first == 0xef && second == 0xbb && view.getUint8(2) == 0xbf) {\n\t\t\tencoding = UTF_8\n\t\t\tbyteOffset = 3\n\t\t}\n\t\t// UTF-16 BE BOM\n\t\telse if (first == 0xfe && second == 0xff) {\n\t\t\tencoding = UTF_16_BE\n\t\t\tbyteOffset = 2\n\t\t}\n\t\t// UTF-16 LE BOM\n\t\telse if (first == 0xff && second == 0xfe) {\n\t\t\tencoding = UTF_16_LE\n\t\t\tbyteOffset = 2\n\t\t}\n\t\telse {\n\t\t\tencoding = UTF_8\n\t\t}\n\t}\n\n\tif (typeof TextDecoder !== 'undefined') {\n\t\treturn new TextDecoder(encoding).decode(view)\n\t}\n\n\tconst { byteLength } = view\n\tconst endian = encoding !== UTF_16_BE\n\tlet str = ''\n\tlet char!: number\n\n\twhile (byteOffset < byteLength) {\n\t\tswitch (encoding) {\n\t\t\tcase UTF_8:\n\t\t\t\tchar = view.getUint8(byteOffset)\n\n\t\t\t\t// Single byte (ASCII)\n\t\t\t\tif (char < 128) {\n\t\t\t\t\tbyteOffset++\n\t\t\t\t}\n\t\t\t\t// 2-byte sequence\n\t\t\t\telse if (char >= 194 && char <= 223) {\n\t\t\t\t\tif (byteOffset + 1 < byteLength) {\n\t\t\t\t\t\tconst byte2 = view.getUint8(byteOffset + 1)\n\t\t\t\t\t\tif (byte2 >= 128 && byte2 <= 191) {\n\t\t\t\t\t\t\tchar = ((char & 0x1F) << 6) | (byte2 & 0x3F)\n\t\t\t\t\t\t\tbyteOffset += 2\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t// Invalid sequence, skip\n\t\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Incomplete sequence, skip\n\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// 3-byte sequence\n\t\t\t\telse if (char >= 224 && char <= 239) {\n\t\t\t\t\tif (byteOffset + 2 <= byteLength - 1) {\n\t\t\t\t\t\tconst byte2 = view.getUint8(byteOffset + 1)\n\t\t\t\t\t\tconst byte3 = view.getUint8(byteOffset + 2)\n\t\t\t\t\t\tif (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191) {\n\t\t\t\t\t\t\tchar = ((char & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F)\n\t\t\t\t\t\t\tbyteOffset += 3\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t// Invalid sequence, skip\n\t\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Incomplete sequence, skip\n\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// 4-byte sequence\n\t\t\t\telse if (char >= 240 && char <= 244) {\n\t\t\t\t\tif (byteOffset + 3 <= byteLength - 1) {\n\t\t\t\t\t\tconst byte2 = view.getUint8(byteOffset + 1)\n\t\t\t\t\t\tconst byte3 = view.getUint8(byteOffset + 2)\n\t\t\t\t\t\tconst byte4 = view.getUint8(byteOffset + 3)\n\t\t\t\t\t\tif (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191 && byte4 >= 128 && byte4 <= 191) {\n\t\t\t\t\t\t\tchar = ((char & 0x07) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F)\n\t\t\t\t\t\t\tbyteOffset += 4\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t// Invalid sequence, skip\n\t\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\t// Incomplete sequence, skip\n\t\t\t\t\t\tbyteOffset++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Invalid byte, skip\n\t\t\t\telse {\n\t\t\t\t\tbyteOffset++\n\t\t\t\t}\n\t\t\t\tbreak\n\n\t\t\tcase UTF_16_BE:\n\t\t\tcase UTF_16:\n\t\t\tcase UTF_16_LE:\n\t\t\t\tchar = view.getUint16(byteOffset, endian)\n\t\t\t\tbyteOffset += 2\n\t\t\t\tbreak\n\t\t}\n\n\t\tstr += String.fromCodePoint(char)\n\t}\n\n\treturn str\n}\n","\n/**\n * Converts a string to a Uint8Array. The function works like\n * `TextEncoder.encode` and also supports environments without `TextEncoder`.\n *\n * @param data - The string to encode.\n * @returns The Uint8Array representation of the string.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/encodeText.test.ts#example}\n */\nexport function encodeText(data: string): Uint8Array {\n\treturn new TextEncoder().encode(data)\n}\n","import { UTF_16 } from './UTF_16.ts'\nimport { UTF_16_BE } from './UTF_16_BE.ts'\nimport { UTF_16_LE } from './UTF_16_LE.ts'\nimport { UTF_8 } from './UTF_8.ts'\nimport type { ValueOf } from './ValueOf.ts'\n\n/**\n * Text encoding types.\n *\n * @public\n */\nexport const Encoding = {\n\tUTF8: UTF_8 as typeof UTF_8,\n\tUTF16: UTF_16 as typeof UTF_16,\n\tUTF16BE: UTF_16_BE as typeof UTF_16_BE,\n\tUTF16LE: UTF_16_LE as typeof UTF_16_LE,\n} as const\n\n/**\n * Text encoding types.\n *\n * @public\n */\nexport type Encoding = ValueOf<typeof Encoding>;\n","import type { ResourceTiming } from './ResourceTiming.ts'\n\n/**\n * Converts a ResourceTiming sample to bandwidth in bits per second.\n *\n * @param sample - A ResourceTiming sample\n * @returns The bandwidth in bits per second.\n *\n * @public\n */\nexport function getBandwidthBps(sample: ResourceTiming): number {\n\tconst durationSeconds = sample.duration / 1000\n\tconst bandwidthBps = sample.encodedBodySize * 8 / durationSeconds\n\treturn bandwidthBps\n}\n","/**\n * Gets the base URL from a full URL or a URL object.\n *\n * @param fullUrl - The full URL or URL object.\n * @returns The base URL.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/getBaseUrl.test.ts#example}\n */\nexport function getBaseUrl(fullUrl: string | URL): string {\n\tconst url = typeof fullUrl === 'string' ? new URL(fullUrl) : fullUrl\n\treturn url.origin + url.pathname.substring(0, url.pathname.lastIndexOf('/') + 1)\n}\n","/**\n * Decodes a hexadecimal string into an ArrayBuffer.\n *\n * @param hex - The hexadecimal string to decode.\n * @returns The decoded ArrayBuffer.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/hexToArrayBuffer.test.ts#example}\n */\nexport function hexToArrayBuffer(hex: string): ArrayBuffer {\n\tconst buffer = new ArrayBuffer(hex.length / 2)\n\tconst view = new Uint8Array(buffer)\n\tfor (let i = 0; i < hex.length; i += 2) {\n\t\tview[i / 2] = parseInt(hex.slice(i, i + 2), 16)\n\t}\n\treturn buffer\n}\n","import type { ValueOf } from './ValueOf.ts'\n\n/**\n * The response type of the request.\n *\n * @enum\n *\n * @public\n */\nexport const RequestResponseType = {\n\tTEXT: 'text' as const,\n\tJSON: 'json' as const,\n\tBLOB: 'blob' as const,\n\tARRAY_BUFFER: 'arrayBuffer' as const,\n\tDOCUMENT: 'document' as const,\n\tSTREAM: 'stream' as const,\n} as const\n\n/**\n * @public\n */\nexport type RequestResponseType = ValueOf<typeof RequestResponseType>;\n","/**\n * Rounds a value with the procedure from step 2 of the \"Serializing a Decimal\" specification.\n * The style is known as \"even rounding\", \"banker's rounding\", or \"commercial rounding\".\n *\n * @param value - The value to round\n * @param precision - The number of decimal places to round to\n * @returns The rounded value\n *\n * @public\n */\nexport function roundToEven(value: number, precision: number): number {\n\tif (value < 0) {\n\t\treturn -roundToEven(-value, precision)\n\t}\n\n\tconst decimalShift = Math.pow(10, precision)\n\tconst isEquidistant = Math.abs(((value * decimalShift) % 1) - 0.5) < Number.EPSILON\n\n\tif (isEquidistant) {\n\t\t// If the tail of the decimal place is 'equidistant' we round to the nearest even value\n\t\tconst flooredValue = Math.floor(value * decimalShift)\n\t\treturn (flooredValue % 2 === 0 ? flooredValue : flooredValue + 1) / decimalShift\n\t}\n\telse {\n\t\t// Otherwise, proceed as normal\n\t\treturn Math.round(value * decimalShift) / decimalShift\n\t}\n}\n","/**\n * Converts a string to a Uint16Array.\n *\n * @param str - The string to convert\n * @returns A Uint16Array representation of the string\n *\n * @public\n *\n * @example\n * {@includeCode ../test/stringToUint16.test.ts#example}\n */\nexport function stringToUint16(str: string): Uint16Array {\n\tconst buffer = new ArrayBuffer(str.length * 2)\n\tconst view = new DataView(buffer)\n\n\tfor (let i = 0; i < str.length; i++) {\n\t\tview.setUint16(i * 2, str.charCodeAt(i), true) // true for little-endian\n\t}\n\n\treturn new Uint16Array(buffer)\n}\n","const escapedHtml = /&(?:amp|lt|gt|quot|apos|nbsp|lrm|rlm|#[xX]?[0-9a-fA-F]+);/g\n\n/**\n * Unescapes HTML entities\n *\n * @param text - The text to unescape\n * @returns The unescaped text\n *\n * @public\n *\n * @example\n * {@includeCode ../test/unescapeHtml.test.ts#example}\n */\nexport function unescapeHtml(text: string): string {\n\tif (text.indexOf('&') === -1) {\n\t\treturn text\n\t}\n\n\treturn text.replace(escapedHtml, (match) => {\n\t\tswitch (match) {\n\t\t\tcase '&': return '&'\n\t\t\tcase '<': return '<'\n\t\t\tcase '>': return '>'\n\t\t\tcase '"': return '\"'\n\t\t\tcase ''': return '\\''\n\t\t\tcase ' ': return '\\u{a0}'\n\t\t\tcase '‎': return '\\u{200e}'\n\t\t\tcase '‏': return '\\u{200f}'\n\t\t\tdefault: {\n\t\t\t\tif (match[1] === '#') {\n\t\t\t\t\tconst code = match[2] === 'x' || match[2] === 'X' ? parseInt(match.slice(3), 16) : parseInt(match.slice(2), 10)\n\t\t\t\t\treturn String.fromCodePoint(code)\n\t\t\t\t}\n\t\t\t\treturn match\n\t\t\t}\n\t\t}\n\t})\n}\n","// RFC 3986 section 3.1 scheme and \":\".\n// The WHATWG URL parser first removes leading C0 control or space and every ASCII tab or newline.\nconst SCHEME_REGEX = /^[\\0-\\x20]*[a-z][a-z0-9+.\\t\\n\\r-]*:/i\n\n/**\n * Constructs a relative path from a URL.\n *\n * If `url` is already relative, or its origin differs from `base`, the function returns `url` unchanged.\n *\n * @param url - The destination URL\n * @param base - The base URL\n * @returns The relative path\n *\n * @public\n *\n * @example\n * {@includeCode ../test/urlToRelativePath.test.ts#example}\n */\nexport function urlToRelativePath(url: string, base: string): string {\n\tif (!SCHEME_REGEX.test(url)) {\n\t\treturn url\n\t}\n\n\tlet to: URL\n\ttry {\n\t\tto = new URL(url)\n\t}\n\tcatch {\n\t\treturn url\n\t}\n\n\tconst from = new URL(base)\n\n\tif (to.origin !== from.origin) {\n\t\treturn url\n\t}\n\n\tconst toPath = to.pathname.split('/').slice(1)\n\tconst fromPath = from.pathname.split('/').slice(1, -1)\n\n\t// count common parents, stopping before the destination file\n\tlet common = 0\n\n\twhile (common < toPath.length - 1 && common < fromPath.length && toPath[common] === fromPath[common]) {\n\t\tcommon++\n\t}\n\n\t// add back paths\n\tconst ups = fromPath.length - common\n\tlet relativePath = '../'.repeat(ups) + toPath.slice(common).join('/')\n\n\t// RFC 3986 section 4.2: a relative-path reference cannot be empty, start with \"/\", or have \":\" in its first segment\n\tif (ups === 0 && (relativePath === '' || relativePath.startsWith('/') || toPath[common].includes(':'))) {\n\t\trelativePath = './' + relativePath\n\t}\n\n\t// preserve query parameters and hash of the destination url\n\treturn relativePath + to.search + to.hash\n}\n","import { arrayBufferToUuid } from './arrayBufferToUuid.ts'\n\n/**\n * Generates a random v4 UUID\n *\n * @returns A random v4 UUID\n *\n * @public\n *\n * @example\n * {@includeCode ../test/uuid.test.ts#example}\n */\nexport function uuid(): string {\n\ttry {\n\t\treturn crypto.randomUUID()\n\t}\n\tcatch (error) {\n\t\ttry {\n\t\t\tconst bytes = crypto.getRandomValues(new Uint8Array(16))\n\n\t\t\t// Set the version (4) and variant (RFC 4122) bits\n\t\t\tbytes[6] = (bytes[6] & 0x0f) | 0x40\n\t\t\tbytes[8] = (bytes[8] & 0x3f) | 0x80\n\n\t\t\treturn arrayBufferToUuid(bytes.buffer)\n\t\t}\n\t\tcatch (error) {\n\t\t\tconst url = URL.createObjectURL(new Blob())\n\t\t\tconst uuid = url.toString()\n\t\t\tURL.revokeObjectURL(url)\n\t\t\treturn uuid.slice(uuid.lastIndexOf('/') + 1)\n\t\t}\n\t}\n}\n","import { hexToArrayBuffer } from './hexToArrayBuffer.ts'\n\n/**\n * Converts a UUID string to an ArrayBuffer.\n *\n * @param uuid - The UUID string to convert.\n * @returns The ArrayBuffer representation.\n *\n * @public\n *\n * @example\n * {@includeCode ../test/uuidToArrayBuffer.test.ts#example}\n */\nexport function uuidToArrayBuffer(uuid: string): ArrayBuffer {\n\tconst hex = uuid.replace(/-/g, '')\n\treturn hexToArrayBuffer(hex)\n}\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,iBAAiB,QAA6B;CAE7D,OAAO,IADU,WAAW,MAClB,CAAC,CAAC,QAAQ,QAAQ,SAAS,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,EAAE;AACrF;;;;;;;;;;;;;;ACDA,SAAgB,kBAAkB,QAA6B;CAE9D,OADY,iBAAiB,MACpB,CAAC,CAAC,QAAQ,mCAAmC,gBAAgB;AACvE;;;;;;;;;;;ACRA,SAAgB,aAAa,KAAyB;CACrD,OAAO,IAAI,WAAW,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AACjE;;;;;;;;;;;;;;;ACIA,MAAa,eAAoC;;;ACdjD,MAAM,aAAa;;;;;;;;;;;;AAanB,SAAgB,aAAa,QAA4B;CACxD,IAAI,OAAO;CAEX,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,YAAY;EACnD,MAAM,QAA2B,OAAO,SAAS,GAAG,IAAI,UAAU;EAClE,QAAQ,OAAO,aAAa,MAAM,MAAM,KAAiB;CAC1D;CAEA,OAAO,KAAK,IAAI;AACjB;;;;;;;;;;;;;;;ACRA,MAAa,eAAoC;;;;;;;;;;;ACNjD,SAAgB,qBAAqB,OAAgC;CACpE,IAAI,MAAM,SAAS,MAAM,GAAG;EAC3B,MAAM,SAAS,IAAI,WAAW,MAAM,SAAS,CAAC;EAC9C,OAAO,IAAI,KAAK;EAChB,OAAO,IAAI,YAAY,OAAO,MAAM;CACrC;CACA,OAAO,IAAI,YAAY,MAAM,MAAM;AACpC;;;;;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