@svta/cml-utils 0.19.0 → 0.20.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 (119) hide show
  1. package/README.md +57 -0
  2. package/dist/index.d.ts +407 -31
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +472 -31
  5. package/dist/index.js.map +1 -1
  6. package/package.json +4 -23
  7. package/dist/DecodeTextOptions.d.ts +0 -14
  8. package/dist/DecodeTextOptions.d.ts.map +0 -1
  9. package/dist/DecodeTextOptions.js +0 -2
  10. package/dist/DecodeTextOptions.js.map +0 -1
  11. package/dist/Encoding.d.ts +0 -25
  12. package/dist/Encoding.d.ts.map +0 -1
  13. package/dist/Encoding.js +0 -17
  14. package/dist/Encoding.js.map +0 -1
  15. package/dist/Request.d.ts +0 -47
  16. package/dist/Request.d.ts.map +0 -1
  17. package/dist/Request.js +0 -2
  18. package/dist/Request.js.map +0 -1
  19. package/dist/RequestType.d.ts +0 -21
  20. package/dist/RequestType.d.ts.map +0 -1
  21. package/dist/RequestType.js +0 -16
  22. package/dist/RequestType.js.map +0 -1
  23. package/dist/ResourceTiming.d.ts +0 -13
  24. package/dist/ResourceTiming.d.ts.map +0 -1
  25. package/dist/ResourceTiming.js +0 -2
  26. package/dist/ResourceTiming.js.map +0 -1
  27. package/dist/TypedResult.d.ts +0 -11
  28. package/dist/TypedResult.d.ts.map +0 -1
  29. package/dist/TypedResult.js +0 -2
  30. package/dist/TypedResult.js.map +0 -1
  31. package/dist/UTF_16.d.ts +0 -8
  32. package/dist/UTF_16.d.ts.map +0 -1
  33. package/dist/UTF_16.js +0 -8
  34. package/dist/UTF_16.js.map +0 -1
  35. package/dist/UTF_16_BE.d.ts +0 -8
  36. package/dist/UTF_16_BE.d.ts.map +0 -1
  37. package/dist/UTF_16_BE.js +0 -8
  38. package/dist/UTF_16_BE.js.map +0 -1
  39. package/dist/UTF_16_LE.d.ts +0 -8
  40. package/dist/UTF_16_LE.d.ts.map +0 -1
  41. package/dist/UTF_16_LE.js +0 -8
  42. package/dist/UTF_16_LE.js.map +0 -1
  43. package/dist/UTF_8.d.ts +0 -8
  44. package/dist/UTF_8.d.ts.map +0 -1
  45. package/dist/UTF_8.js +0 -8
  46. package/dist/UTF_8.js.map +0 -1
  47. package/dist/ValueOf.d.ts +0 -8
  48. package/dist/ValueOf.d.ts.map +0 -1
  49. package/dist/ValueOf.js +0 -2
  50. package/dist/ValueOf.js.map +0 -1
  51. package/dist/ValueOrArray.d.ts +0 -8
  52. package/dist/ValueOrArray.d.ts.map +0 -1
  53. package/dist/ValueOrArray.js +0 -2
  54. package/dist/ValueOrArray.js.map +0 -1
  55. package/dist/arrayBufferToHex.d.ts +0 -14
  56. package/dist/arrayBufferToHex.d.ts.map +0 -1
  57. package/dist/arrayBufferToHex.js +0 -17
  58. package/dist/arrayBufferToHex.js.map +0 -1
  59. package/dist/arrayBufferToUuid.d.ts +0 -14
  60. package/dist/arrayBufferToUuid.d.ts.map +0 -1
  61. package/dist/arrayBufferToUuid.js +0 -18
  62. package/dist/arrayBufferToUuid.js.map +0 -1
  63. package/dist/base64decode.d.ts +0 -15
  64. package/dist/base64decode.d.ts.map +0 -1
  65. package/dist/base64decode.js +0 -18
  66. package/dist/base64decode.js.map +0 -1
  67. package/dist/base64encode.d.ts +0 -15
  68. package/dist/base64encode.d.ts.map +0 -1
  69. package/dist/base64encode.js +0 -18
  70. package/dist/base64encode.js.map +0 -1
  71. package/dist/convertUint8ToUint16.d.ts +0 -10
  72. package/dist/convertUint8ToUint16.d.ts.map +0 -1
  73. package/dist/convertUint8ToUint16.js +0 -17
  74. package/dist/convertUint8ToUint16.js.map +0 -1
  75. package/dist/decodeBase64.d.ts +0 -11
  76. package/dist/decodeBase64.d.ts.map +0 -1
  77. package/dist/decodeBase64.js +0 -13
  78. package/dist/decodeBase64.js.map +0 -1
  79. package/dist/decodeText.d.ts +0 -17
  80. package/dist/decodeText.d.ts.map +0 -1
  81. package/dist/decodeText.js +0 -140
  82. package/dist/decodeText.js.map +0 -1
  83. package/dist/encodeBase64.d.ts +0 -11
  84. package/dist/encodeBase64.d.ts.map +0 -1
  85. package/dist/encodeBase64.js +0 -13
  86. package/dist/encodeBase64.js.map +0 -1
  87. package/dist/getBandwidthBps.d.ts +0 -12
  88. package/dist/getBandwidthBps.d.ts.map +0 -1
  89. package/dist/getBandwidthBps.js +0 -15
  90. package/dist/getBandwidthBps.js.map +0 -1
  91. package/dist/hexToArrayBuffer.d.ts +0 -14
  92. package/dist/hexToArrayBuffer.d.ts.map +0 -1
  93. package/dist/hexToArrayBuffer.js +0 -21
  94. package/dist/hexToArrayBuffer.js.map +0 -1
  95. package/dist/roundToEven.d.ts +0 -13
  96. package/dist/roundToEven.d.ts.map +0 -1
  97. package/dist/roundToEven.js +0 -28
  98. package/dist/roundToEven.js.map +0 -1
  99. package/dist/stringToUint16.d.ts +0 -14
  100. package/dist/stringToUint16.d.ts.map +0 -1
  101. package/dist/stringToUint16.js +0 -21
  102. package/dist/stringToUint16.js.map +0 -1
  103. package/dist/tsconfig.tsbuildinfo +0 -1
  104. package/dist/unescapeHtml.d.ts +0 -14
  105. package/dist/unescapeHtml.d.ts.map +0 -1
  106. package/dist/unescapeHtml.js +0 -38
  107. package/dist/unescapeHtml.js.map +0 -1
  108. package/dist/urlToRelativePath.d.ts +0 -12
  109. package/dist/urlToRelativePath.d.ts.map +0 -1
  110. package/dist/urlToRelativePath.js +0 -37
  111. package/dist/urlToRelativePath.js.map +0 -1
  112. package/dist/uuid.d.ts +0 -10
  113. package/dist/uuid.d.ts.map +0 -1
  114. package/dist/uuid.js +0 -31
  115. package/dist/uuid.js.map +0 -1
  116. package/dist/uuidToArrayBuffer.d.ts +0 -14
  117. package/dist/uuidToArrayBuffer.d.ts.map +0 -1
  118. package/dist/uuidToArrayBuffer.js +0 -18
  119. package/dist/uuidToArrayBuffer.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,33 +1,474 @@
1
+ //#region src/arrayBufferToHex.ts
1
2
  /**
2
- * A collection of tools for working with media.
3
- *
4
- * @packageDocumentation
5
- */
6
- export * from './arrayBufferToHex.js';
7
- export * from './arrayBufferToUuid.js';
8
- export * from './base64decode.js';
9
- export * from './base64encode.js';
10
- export * from './convertUint8ToUint16.js';
11
- export * from './decodeBase64.js';
12
- export * from './decodeText.js';
13
- export * from './DecodeTextOptions.js';
14
- export * from './encodeBase64.js';
15
- export * from './Encoding.js';
16
- export * from './hexToArrayBuffer.js';
17
- export * from './Request.js';
18
- export * from './RequestType.js';
19
- export * from './ResourceTiming.js';
20
- export * from './roundToEven.js';
21
- export * from './stringToUint16.js';
22
- export * from './TypedResult.js';
23
- export * from './unescapeHtml.js';
24
- export * from './urlToRelativePath.js';
25
- export * from './UTF_16.js';
26
- export * from './UTF_16_BE.js';
27
- export * from './UTF_16_LE.js';
28
- export * from './UTF_8.js';
29
- export * from './uuid.js';
30
- export * from './uuidToArrayBuffer.js';
31
- export * from './ValueOf.js';
32
- export * from './ValueOrArray.js';
3
+ * Encodes an ArrayBuffer as a hexadecimal string.
4
+ *
5
+ * @param buffer - The ArrayBuffer to encode.
6
+ * @returns The hexadecimal string representation.
7
+ *
8
+ *
9
+ * @beta
10
+ *
11
+ * @example
12
+ * {@includeCode ../test/arrayBufferToHex.test.ts#example}
13
+ */
14
+ function arrayBufferToHex(buffer) {
15
+ return new Uint8Array(buffer).reduce((result, byte) => result + byte.toString(16).padStart(2, "0"), "");
16
+ }
17
+
18
+ //#endregion
19
+ //#region src/arrayBufferToUuid.ts
20
+ /**
21
+ * Converts an ArrayBuffer to a UUID string.
22
+ *
23
+ * @param buffer - The ArrayBuffer to convert.
24
+ * @returns The UUID string representation.
25
+ *
26
+ *
27
+ * @beta
28
+ *
29
+ * @example
30
+ * {@includeCode ../test/arrayBufferToUuid.test.ts#example}
31
+ */
32
+ function arrayBufferToUuid(buffer) {
33
+ return arrayBufferToHex(buffer).replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5");
34
+ }
35
+
36
+ //#endregion
37
+ //#region src/decodeBase64.ts
38
+ /**
39
+ * Decodes a base64 encoded string into binary data
40
+ *
41
+ * @param str - The base64 encoded string to decode
42
+ * @returns The decoded binary data
43
+ *
44
+ *
45
+ * @beta
46
+ */
47
+ function decodeBase64(str) {
48
+ return new Uint8Array([...atob(str)].map((a) => a.charCodeAt(0)));
49
+ }
50
+
51
+ //#endregion
52
+ //#region src/base64decode.ts
53
+ /**
54
+ * Decodes a base64 encoded string into binary data
55
+ *
56
+ * @param str - The base64 encoded string to decode
57
+ * @returns The decoded binary data
58
+ *
59
+ *
60
+ * @beta
61
+ *
62
+ * @deprecated Use {@link decodeBase64} instead.
63
+ *
64
+ * @see {@link decodeBase64}
65
+ */
66
+ const base64decode = decodeBase64;
67
+
68
+ //#endregion
69
+ //#region src/encodeBase64.ts
70
+ /**
71
+ * Encodes binary data to base64
72
+ *
73
+ * @param binary - The binary data to encode
74
+ * @returns The base64 encoded string
75
+ *
76
+ *
77
+ * @beta
78
+ */
79
+ function encodeBase64(binary) {
80
+ return btoa(String.fromCharCode(...binary));
81
+ }
82
+
83
+ //#endregion
84
+ //#region src/base64encode.ts
85
+ /**
86
+ * Encodes binary data to base64
87
+ *
88
+ * @param binary - The binary data to encode
89
+ * @returns The base64 encoded string
90
+ *
91
+ *
92
+ * @beta
93
+ *
94
+ * @deprecated Use {@link encodeBase64} instead.
95
+ *
96
+ * @see {@link encodeBase64}
97
+ */
98
+ const base64encode = encodeBase64;
99
+
100
+ //#endregion
101
+ //#region src/convertUint8ToUint16.ts
102
+ /**
103
+ * Converts a Uint8Array to a Uint16Array by aligning its buffer.
104
+ *
105
+ * @param input - The Uint8Array to convert
106
+ * @returns A properly aligned Uint16Array
107
+ *
108
+ * @beta
109
+ */
110
+ function convertUint8ToUint16(input) {
111
+ if (input.length % 2 !== 0) {
112
+ const padded = new Uint8Array(input.length + 1);
113
+ padded.set(input);
114
+ return new Uint16Array(padded.buffer);
115
+ }
116
+ return new Uint16Array(input.buffer);
117
+ }
118
+
119
+ //#endregion
120
+ //#region src/UTF_16.ts
121
+ /**
122
+ * UTF-16 Encoding.
123
+ *
124
+ *
125
+ * @beta
126
+ */
127
+ const UTF_16 = "utf-16";
128
+
129
+ //#endregion
130
+ //#region src/UTF_16_BE.ts
131
+ /**
132
+ * UTF-16 Big Endian Encoding.
133
+ *
134
+ *
135
+ * @beta
136
+ */
137
+ const UTF_16_BE = "utf-16be";
138
+
139
+ //#endregion
140
+ //#region src/UTF_16_LE.ts
141
+ /**
142
+ * UTF-16 Little Endian Encoding.
143
+ *
144
+ *
145
+ * @beta
146
+ */
147
+ const UTF_16_LE = "utf-16le";
148
+
149
+ //#endregion
150
+ //#region src/UTF_8.ts
151
+ /**
152
+ * UTF-8 Encoding.
153
+ *
154
+ *
155
+ * @beta
156
+ */
157
+ const UTF_8 = "utf-8";
158
+
159
+ //#endregion
160
+ //#region src/decodeText.ts
161
+ /**
162
+ * Converts an ArrayBuffer or ArrayBufferView to a string. Similar to `TextDecoder.decode`
163
+ * but with a fallback for environments that don't support `TextDecoder`.
164
+ *
165
+ * @param data - The data to decode.
166
+ * @param options - The options for the decoding.
167
+ * @returns The string representation of the ArrayBuffer.
168
+ *
169
+ *
170
+ * @beta
171
+ *
172
+ * @example
173
+ * {@includeCode ../test/decodeText.test.ts#example}
174
+ */
175
+ function decodeText(data, options = {}) {
176
+ let view;
177
+ if (data instanceof ArrayBuffer) view = new DataView(data);
178
+ else view = new DataView(data.buffer, data.byteOffset, data.byteLength);
179
+ let byteOffset = 0;
180
+ let { encoding } = options;
181
+ if (!encoding) {
182
+ const first = view.getUint8(0);
183
+ const second = view.getUint8(1);
184
+ if (first == 239 && second == 187 && view.getUint8(2) == 191) {
185
+ encoding = UTF_8;
186
+ byteOffset = 3;
187
+ } else if (first == 254 && second == 255) {
188
+ encoding = UTF_16_BE;
189
+ byteOffset = 2;
190
+ } else if (first == 255 && second == 254) {
191
+ encoding = UTF_16_LE;
192
+ byteOffset = 2;
193
+ } else encoding = UTF_8;
194
+ }
195
+ if (typeof TextDecoder !== "undefined") return new TextDecoder(encoding).decode(view);
196
+ const { byteLength } = view;
197
+ const endian = encoding !== UTF_16_BE;
198
+ let str = "";
199
+ let char;
200
+ while (byteOffset < byteLength) {
201
+ switch (encoding) {
202
+ case UTF_8:
203
+ char = view.getUint8(byteOffset);
204
+ if (char < 128) byteOffset++;
205
+ else if (char >= 194 && char <= 223) if (byteOffset + 1 < byteLength) {
206
+ const byte2 = view.getUint8(byteOffset + 1);
207
+ if (byte2 >= 128 && byte2 <= 191) {
208
+ char = (char & 31) << 6 | byte2 & 63;
209
+ byteOffset += 2;
210
+ } else byteOffset++;
211
+ } else byteOffset++;
212
+ else if (char >= 224 && char <= 239) if (byteOffset + 2 <= byteLength - 1) {
213
+ const byte2 = view.getUint8(byteOffset + 1);
214
+ const byte3 = view.getUint8(byteOffset + 2);
215
+ if (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191) {
216
+ char = (char & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
217
+ byteOffset += 3;
218
+ } else byteOffset++;
219
+ } else byteOffset++;
220
+ else if (char >= 240 && char <= 244) if (byteOffset + 3 <= byteLength - 1) {
221
+ const byte2 = view.getUint8(byteOffset + 1);
222
+ const byte3 = view.getUint8(byteOffset + 2);
223
+ const byte4 = view.getUint8(byteOffset + 3);
224
+ if (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191 && byte4 >= 128 && byte4 <= 191) {
225
+ char = (char & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
226
+ byteOffset += 4;
227
+ } else byteOffset++;
228
+ } else byteOffset++;
229
+ else byteOffset++;
230
+ break;
231
+ case UTF_16_BE:
232
+ case UTF_16:
233
+ case UTF_16_LE:
234
+ char = view.getUint16(byteOffset, endian);
235
+ byteOffset += 2;
236
+ break;
237
+ }
238
+ str += String.fromCodePoint(char);
239
+ }
240
+ return str;
241
+ }
242
+
243
+ //#endregion
244
+ //#region src/Encoding.ts
245
+ /**
246
+ * Text encoding types.
247
+ *
248
+ *
249
+ * @beta
250
+ */
251
+ const Encoding = {
252
+ UTF8: UTF_8,
253
+ UTF16: UTF_16,
254
+ UTF16BE: UTF_16_BE,
255
+ UTF16LE: UTF_16_LE
256
+ };
257
+
258
+ //#endregion
259
+ //#region src/getBandwidthBps.ts
260
+ /**
261
+ * Converts a ResourceTiming sample to bandwidth in bits per second (bps).
262
+ *
263
+ * @param sample - A ResourceTiming sample
264
+ * @returns
265
+ *
266
+ *
267
+ * @beta
268
+ */
269
+ function getBandwidthBps(sample) {
270
+ const durationSeconds = sample.duration / 1e3;
271
+ return sample.encodedBodySize * 8 / durationSeconds;
272
+ }
273
+
274
+ //#endregion
275
+ //#region src/hexToArrayBuffer.ts
276
+ /**
277
+ * Decodes a hexadecimal string into an ArrayBuffer.
278
+ *
279
+ * @param hex - The hexadecimal string to decode.
280
+ * @returns The decoded ArrayBuffer.
281
+ *
282
+ *
283
+ * @beta
284
+ *
285
+ * @example
286
+ * {@includeCode ../test/hexToArrayBuffer.test.ts#example}
287
+ */
288
+ function hexToArrayBuffer(hex) {
289
+ const buffer = /* @__PURE__ */ new ArrayBuffer(hex.length / 2);
290
+ const view = new Uint8Array(buffer);
291
+ for (let i = 0; i < hex.length; i += 2) view[i / 2] = parseInt(hex.slice(i, i + 2), 16);
292
+ return buffer;
293
+ }
294
+
295
+ //#endregion
296
+ //#region src/RequestType.ts
297
+ /**
298
+ * The content type of the request.
299
+ *
300
+ *
301
+ * @enum
302
+ *
303
+ * @beta
304
+ */
305
+ const RequestType = {
306
+ TEXT: "text",
307
+ JSON: "json",
308
+ BLOB: "blob",
309
+ ARRAY_BUFFER: "arrayBuffer",
310
+ DOCUMENT: "document"
311
+ };
312
+
313
+ //#endregion
314
+ //#region src/roundToEven.ts
315
+ /**
316
+ * This implements the rounding procedure described in step 2 of the "Serializing a Decimal" specification.
317
+ * This rounding style is known as "even rounding", "banker's rounding", or "commercial rounding".
318
+ *
319
+ * @param value - The value to round
320
+ * @param precision - The number of decimal places to round to
321
+ * @returns The rounded value
322
+ *
323
+ *
324
+ * @beta
325
+ */
326
+ function roundToEven(value, precision) {
327
+ if (value < 0) return -roundToEven(-value, precision);
328
+ const decimalShift = Math.pow(10, precision);
329
+ if (Math.abs(value * decimalShift % 1 - .5) < Number.EPSILON) {
330
+ const flooredValue = Math.floor(value * decimalShift);
331
+ return (flooredValue % 2 === 0 ? flooredValue : flooredValue + 1) / decimalShift;
332
+ } else return Math.round(value * decimalShift) / decimalShift;
333
+ }
334
+
335
+ //#endregion
336
+ //#region src/stringToUint16.ts
337
+ /**
338
+ * Converts a string to a Uint16Array.
339
+ *
340
+ * @param str - The string to convert
341
+ * @returns A Uint16Array representation of the string
342
+ *
343
+ *
344
+ * @beta
345
+ *
346
+ * @example
347
+ * {@includeCode ../test/stringToUint16.test.ts#example}
348
+ */
349
+ function stringToUint16(str) {
350
+ const buffer = /* @__PURE__ */ new ArrayBuffer(str.length * 2);
351
+ const view = new DataView(buffer);
352
+ for (let i = 0; i < str.length; i++) view.setUint16(i * 2, str.charCodeAt(i), true);
353
+ return new Uint16Array(buffer);
354
+ }
355
+
356
+ //#endregion
357
+ //#region src/unescapeHtml.ts
358
+ const escapedHtml = /&(?:amp|lt|gt|quot|apos|nbsp|lrm|rlm|#[xX]?[0-9a-fA-F]+);/g;
359
+ /**
360
+ * Unescapes HTML entities
361
+ *
362
+ * @param text - The text to unescape
363
+ * @returns The unescaped text
364
+ *
365
+ *
366
+ * @beta
367
+ *
368
+ * @example
369
+ * {@includeCode ../test/unescapeHtml.test.ts#example}
370
+ */
371
+ function unescapeHtml(text) {
372
+ if (text.indexOf("&") === -1) return text;
373
+ return text.replace(escapedHtml, (match) => {
374
+ switch (match) {
375
+ case "&amp;": return "&";
376
+ case "&lt;": return "<";
377
+ case "&gt;": return ">";
378
+ case "&quot;": return "\"";
379
+ case "&apos;": return "'";
380
+ case "&nbsp;": return "\xA0";
381
+ case "&lrm;": return "‎";
382
+ case "&rlm;": return "‏";
383
+ default:
384
+ if (match[1] === "#") {
385
+ const code = match[2] === "x" || match[2] === "X" ? parseInt(match.slice(3), 16) : parseInt(match.slice(2), 10);
386
+ return String.fromCodePoint(code);
387
+ }
388
+ return match;
389
+ }
390
+ });
391
+ }
392
+
393
+ //#endregion
394
+ //#region src/urlToRelativePath.ts
395
+ /**
396
+ * Constructs a relative path from a URL.
397
+ *
398
+ * @param url - The destination URL
399
+ * @param base - The base URL
400
+ * @returns The relative path
401
+ *
402
+ *
403
+ * @beta
404
+ */
405
+ function urlToRelativePath(url, base) {
406
+ const to = new URL(url);
407
+ const from = new URL(base);
408
+ if (to.origin !== from.origin) return url;
409
+ const toPath = to.pathname.split("/").slice(1);
410
+ const fromPath = from.pathname.split("/").slice(1, -1);
411
+ const length = Math.min(toPath.length, fromPath.length);
412
+ for (let i = 0; i < length; i++) {
413
+ if (toPath[i] !== fromPath[i]) break;
414
+ toPath.shift();
415
+ fromPath.shift();
416
+ }
417
+ while (fromPath.length) {
418
+ fromPath.shift();
419
+ toPath.unshift("..");
420
+ }
421
+ return toPath.join("/") + to.search + to.hash;
422
+ }
423
+
424
+ //#endregion
425
+ //#region src/uuid.ts
426
+ /**
427
+ * Generate a random v4 UUID
428
+ *
429
+ * @returns A random v4 UUID
430
+ *
431
+ *
432
+ * @beta
433
+ */
434
+ function uuid() {
435
+ try {
436
+ return crypto.randomUUID();
437
+ } catch (error) {
438
+ try {
439
+ const url = URL.createObjectURL(new Blob());
440
+ const uuid$1 = url.toString();
441
+ URL.revokeObjectURL(url);
442
+ return uuid$1.slice(uuid$1.lastIndexOf("/") + 1);
443
+ } catch (error$1) {
444
+ let dt = (/* @__PURE__ */ new Date()).getTime();
445
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
446
+ const r = (dt + Math.random() * 16) % 16 | 0;
447
+ dt = Math.floor(dt / 16);
448
+ return (c == "x" ? r : r & 3 | 8).toString(16);
449
+ });
450
+ }
451
+ }
452
+ }
453
+
454
+ //#endregion
455
+ //#region src/uuidToArrayBuffer.ts
456
+ /**
457
+ * Converts a UUID string to an ArrayBuffer.
458
+ *
459
+ * @param uuid - The UUID string to convert.
460
+ * @returns The ArrayBuffer representation.
461
+ *
462
+ *
463
+ * @beta
464
+ *
465
+ * @example
466
+ * {@includeCode ../test/uuidToArrayBuffer.test.ts#example}
467
+ */
468
+ function uuidToArrayBuffer(uuid$1) {
469
+ return hexToArrayBuffer(uuid$1.replace(/-/g, ""));
470
+ }
471
+
472
+ //#endregion
473
+ export { Encoding, RequestType, UTF_16, UTF_16_BE, UTF_16_LE, UTF_8, arrayBufferToHex, arrayBufferToUuid, base64decode, base64encode, convertUint8ToUint16, decodeBase64, decodeText, encodeBase64, getBandwidthBps, hexToArrayBuffer, roundToEven, stringToUint16, unescapeHtml, urlToRelativePath, uuid, uuidToArrayBuffer };
33
474
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC","sourcesContent":["/**\n * A collection of tools for working with media.\n *\n * @packageDocumentation\n */\nexport * from './arrayBufferToHex.js';\nexport * from './arrayBufferToUuid.js';\nexport * from './base64decode.js';\nexport * from './base64encode.js';\nexport * from './convertUint8ToUint16.js';\nexport * from './decodeBase64.js';\nexport * from './decodeText.js';\nexport * from './DecodeTextOptions.js';\nexport * from './encodeBase64.js';\nexport * from './Encoding.js';\nexport * from './hexToArrayBuffer.js';\nexport * from './Request.js';\nexport * from './RequestType.js';\nexport * from './ResourceTiming.js';\nexport * from './roundToEven.js';\nexport * from './stringToUint16.js';\nexport * from './TypedResult.js';\nexport * from './unescapeHtml.js';\nexport * from './urlToRelativePath.js';\nexport * from './UTF_16.js';\nexport * from './UTF_16_BE.js';\nexport * from './UTF_16_LE.js';\nexport * from './UTF_8.js';\nexport * from './uuid.js';\nexport * from './uuidToArrayBuffer.js';\nexport * from './ValueOf.js';\nexport * from './ValueOrArray.js';\n"]}
1
+ {"version":3,"file":"index.js","names":["base64decode: typeof decodeBase64","base64encode: typeof encodeBase64","view: DataView<ArrayBuffer>","char!: number","uuid","error","uuid"],"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/decodeText.ts","../src/Encoding.ts","../src/getBandwidthBps.ts","../src/hexToArrayBuffer.ts","../src/RequestType.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 *\n * @beta\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.js';\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 *\n * @beta\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 *\n * @beta\n */\nexport function decodeBase64(str: string): Uint8Array {\n\treturn new Uint8Array([...atob(str)].map((a) => a.charCodeAt(0)));\n}\n","import { decodeBase64 } from './decodeBase64.js';\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 *\n * @beta\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 *\n * @beta\n */\nexport function encodeBase64(binary: Uint8Array): string {\n\treturn btoa(String.fromCharCode(...binary));\n}\n","import { encodeBase64 } from './encodeBase64.js';\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 *\n * @beta\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 * @beta\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 * UTF-16 Encoding.\n *\n *\n * @beta\n */\nexport const UTF_16 = 'utf-16';\n","/**\n * UTF-16 Big Endian Encoding.\n *\n *\n * @beta\n */\nexport const UTF_16_BE = 'utf-16be';\n","/**\n * UTF-16 Little Endian Encoding.\n *\n *\n * @beta\n */\nexport const UTF_16_LE = 'utf-16le';\n","/**\n * UTF-8 Encoding.\n *\n *\n * @beta\n */\nexport const UTF_8 = 'utf-8';\n","import type { DecodeTextOptions } from './DecodeTextOptions.js';\nimport { UTF_16 } from './UTF_16.js';\nimport { UTF_16_BE } from './UTF_16_BE.js';\nimport { UTF_16_LE } from './UTF_16_LE.js';\nimport { UTF_8 } from './UTF_8.js';\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 *\n * @beta\n *\n * @example\n * {@includeCode ../test/decodeText.test.ts#example}\n */\nexport function decodeText(data: ArrayBuffer | ArrayBufferView<ArrayBuffer>, options: DecodeTextOptions = {}): string {\n\tlet view: DataView<ArrayBuffer>;\n\n\tif (data instanceof ArrayBuffer) {\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","import { UTF_16 } from './UTF_16.js';\nimport { UTF_16_BE } from './UTF_16_BE.js';\nimport { UTF_16_LE } from './UTF_16_LE.js';\nimport { UTF_8 } from './UTF_8.js';\nimport type { ValueOf } from './ValueOf.js';\n\n/**\n * Text encoding types.\n *\n *\n * @beta\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 *\n * @beta\n */\nexport type Encoding = ValueOf<typeof Encoding>;\n","import type { ResourceTiming } from './ResourceTiming.js';\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 *\n * @beta\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 * Decodes a hexadecimal string into an ArrayBuffer.\n *\n * @param hex - The hexadecimal string to decode.\n * @returns The decoded ArrayBuffer.\n *\n *\n * @beta\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.js';\n\n/**\n * The content type of the request.\n *\n *\n * @enum\n *\n * @beta\n */\nexport const RequestType = {\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} as const;\n\n/**\n * @beta\n */\nexport type RequestType = ValueOf<typeof RequestType>;\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 *\n * @beta\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 *\n * @beta\n *\n * @example\n * {@includeCode ../test/stringToUint16.test.ts#example}\n */\nexport function stringToUint16(str: string): Uint16Array<ArrayBuffer> {\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 *\n * @beta\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 '&amp;': return '&';\n\t\t\tcase '&lt;': return '<';\n\t\t\tcase '&gt;': return '>';\n\t\t\tcase '&quot;': return '\"';\n\t\t\tcase '&apos;': return '\\'';\n\t\t\tcase '&nbsp;': return '\\u{a0}';\n\t\t\tcase '&lrm;': return '\\u{200e}';\n\t\t\tcase '&rlm;': 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 * @param url - The destination URL\n * @param base - The base URL\n * @returns The relative path\n *\n *\n * @beta\n */\nexport function urlToRelativePath(url: string, base: string): string {\n\tconst to = new URL(url);\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","/**\n * Generate a random v4 UUID\n *\n * @returns A random v4 UUID\n *\n *\n * @beta\n */\nexport function uuid(): string {\n\ttry {\n\t\treturn crypto.randomUUID();\n\t}\n\tcatch (error) {\n\t\ttry {\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\tcatch (error) {\n\t\t\tlet dt = new Date().getTime();\n\t\t\tconst uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n\t\t\t\tconst r = (dt + Math.random() * 16) % 16 | 0;\n\t\t\t\tdt = Math.floor(dt / 16);\n\t\t\t\treturn (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);\n\t\t\t});\n\t\t\treturn uuid;\n\t\t}\n\t}\n}\n","import { hexToArrayBuffer } from './hexToArrayBuffer.js';\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 *\n * @beta\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":";;;;;;;;;;;;;AAYA,SAAgB,iBAAiB,QAA6B;AAE7D,QADa,IAAI,WAAW,OAAO,CACvB,QAAQ,QAAQ,SAAS,SAAS,KAAK,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,EAAE,GAAG;;;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AAChB,SAAO,QAAQ,KAAK;;AAMrB,QAHqB,OAAO,KAAK,IAAI,GAGf,GAAG,SAAS,GAAG;;;;;;;;;;;;;AClCtC,SAAgB,OAAe;AAC9B,KAAI;AACH,SAAO,OAAO,YAAY;UAEpB,OAAO;AACb,MAAI;GACH,MAAM,MAAM,IAAI,gBAAgB,IAAI,MAAM,CAAC;GAC3C,MAAMC,SAAO,IAAI,UAAU;AAC3B,OAAI,gBAAgB,IAAI;AACxB,UAAOA,OAAK,MAAMA,OAAK,YAAY,IAAI,GAAG,EAAE;WAEtCC,SAAO;GACb,IAAI,sBAAK,IAAI,MAAM,EAAC,SAAS;AAM7B,UALa,uCAAuC,QAAQ,UAAU,MAAM;IAC3E,MAAM,KAAK,KAAK,KAAK,QAAQ,GAAG,MAAM,KAAK;AAC3C,SAAK,KAAK,MAAM,KAAK,GAAG;AACxB,YAAQ,KAAK,MAAM,IAAK,IAAI,IAAM,GAAM,SAAS,GAAG;KACnD;;;;;;;;;;;;;;;;;;;ACXL,SAAgB,kBAAkB,QAA2B;AAE5D,QAAO,iBADKC,OAAK,QAAQ,MAAM,GAAG,CACN"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@svta/cml-utils",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "Common utility functions for media processing",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
- "homepage": "https://github.com/streaming-video-technology-alliance/common-media-library",
7
+ "homepage": "https://github.com/streaming-video-technology-alliance/common-media-library/tree/main/libs/utils",
8
8
  "authors": "Casey Occhialini <1508707+littlespex@users.noreply.github.com>",
9
9
  "repository": {
10
10
  "type": "git",
@@ -28,23 +28,6 @@
28
28
  "types": "./dist/index.d.ts",
29
29
  "import": "./dist/index.js",
30
30
  "default": "./dist/index.js"
31
- },
32
- "./*.js": {
33
- "import": "./dist/*.js",
34
- "default": "./dist/*.js"
35
- },
36
- "./*": {
37
- "types": "./dist/*.d.ts",
38
- "import": "./dist/*.js",
39
- "default": "./dist/*.js"
40
- }
41
- },
42
- "typesVersions": {
43
- "*": {
44
- "*": [
45
- "dist/*",
46
- "dist/cjs/*"
47
- ]
48
31
  }
49
32
  },
50
33
  "keywords": [
@@ -52,10 +35,8 @@
52
35
  "CML"
53
36
  ],
54
37
  "scripts": {
55
- "build": "tsc",
56
- "postbuild": "api-extractor run --local",
57
- "test": "node --no-warnings --test **/*.test.ts",
58
- "prepublishOnly": "npm run build"
38
+ "build": "node ../../scripts/build.ts",
39
+ "test": "node ../../scripts/test.ts"
59
40
  },
60
41
  "engines": {
61
42
  "node": ">=20"
@@ -1,14 +0,0 @@
1
- import type { Encoding } from './Encoding.js';
2
- /**
3
- * Options for the `decodeText` function.
4
- *
5
- *
6
- * @beta
7
- */
8
- export type DecodeTextOptions = {
9
- /**
10
- * The encoding to use. If not provided, the function will try to detect the encoding from the BOM.
11
- */
12
- encoding?: Encoding;
13
- };
14
- //# sourceMappingURL=DecodeTextOptions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DecodeTextOptions.d.ts","sourceRoot":"","sources":["../src/DecodeTextOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAMpB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=DecodeTextOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DecodeTextOptions.js","sourceRoot":"","sources":["../src/DecodeTextOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { Encoding } from './Encoding.js';\n\n/**\n * Options for the `decodeText` function.\n *\n *\n * @beta\n */\nexport type DecodeTextOptions = {\n\t/**\n\t * The encoding to use. If not provided, the function will try to detect the encoding from the BOM.\n\t */\n\tencoding?: Encoding;\n\n\t/**\n\t * Whether to exit on the first null byte.\n\t */\n\t// exitOnNull?: boolean;\n};\n"]}
@@ -1,25 +0,0 @@
1
- import { UTF_16 } from './UTF_16.js';
2
- import { UTF_16_BE } from './UTF_16_BE.js';
3
- import { UTF_16_LE } from './UTF_16_LE.js';
4
- import { UTF_8 } from './UTF_8.js';
5
- import type { ValueOf } from './ValueOf.js';
6
- /**
7
- * Text encoding types.
8
- *
9
- *
10
- * @beta
11
- */
12
- export declare const Encoding: {
13
- readonly UTF8: typeof UTF_8;
14
- readonly UTF16: typeof UTF_16;
15
- readonly UTF16BE: typeof UTF_16_BE;
16
- readonly UTF16LE: typeof UTF_16_LE;
17
- };
18
- /**
19
- * Text encoding types.
20
- *
21
- *
22
- * @beta
23
- */
24
- export type Encoding = ValueOf<typeof Encoding>;
25
- //# sourceMappingURL=Encoding.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Encoding.d.ts","sourceRoot":"","sources":["../src/Encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,QAAQ;mBACL,OAAO,KAAK;oBACV,OAAO,MAAM;sBACR,OAAO,SAAS;sBAChB,OAAO,SAAS;CAC7B,CAAC;AAEX;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,QAAQ,CAAC,CAAC"}
package/dist/Encoding.js DELETED
@@ -1,17 +0,0 @@
1
- import { UTF_16 } from './UTF_16.js';
2
- import { UTF_16_BE } from './UTF_16_BE.js';
3
- import { UTF_16_LE } from './UTF_16_LE.js';
4
- import { UTF_8 } from './UTF_8.js';
5
- /**
6
- * Text encoding types.
7
- *
8
- *
9
- * @beta
10
- */
11
- export const Encoding = {
12
- UTF8: UTF_8,
13
- UTF16: UTF_16,
14
- UTF16BE: UTF_16_BE,
15
- UTF16LE: UTF_16_LE,
16
- };
17
- //# sourceMappingURL=Encoding.js.map