@svta/cml-utils 0.19.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.
- package/LICENSE +202 -0
- package/dist/DecodeTextOptions.d.ts +14 -0
- package/dist/DecodeTextOptions.d.ts.map +1 -0
- package/dist/DecodeTextOptions.js +2 -0
- package/dist/DecodeTextOptions.js.map +1 -0
- package/dist/Encoding.d.ts +25 -0
- package/dist/Encoding.d.ts.map +1 -0
- package/dist/Encoding.js +17 -0
- package/dist/Encoding.js.map +1 -0
- package/dist/Request.d.ts +47 -0
- package/dist/Request.d.ts.map +1 -0
- package/dist/Request.js +2 -0
- package/dist/Request.js.map +1 -0
- package/dist/RequestType.d.ts +21 -0
- package/dist/RequestType.d.ts.map +1 -0
- package/dist/RequestType.js +16 -0
- package/dist/RequestType.js.map +1 -0
- package/dist/ResourceTiming.d.ts +13 -0
- package/dist/ResourceTiming.d.ts.map +1 -0
- package/dist/ResourceTiming.js +2 -0
- package/dist/ResourceTiming.js.map +1 -0
- package/dist/TypedResult.d.ts +11 -0
- package/dist/TypedResult.d.ts.map +1 -0
- package/dist/TypedResult.js +2 -0
- package/dist/TypedResult.js.map +1 -0
- package/dist/UTF_16.d.ts +8 -0
- package/dist/UTF_16.d.ts.map +1 -0
- package/dist/UTF_16.js +8 -0
- package/dist/UTF_16.js.map +1 -0
- package/dist/UTF_16_BE.d.ts +8 -0
- package/dist/UTF_16_BE.d.ts.map +1 -0
- package/dist/UTF_16_BE.js +8 -0
- package/dist/UTF_16_BE.js.map +1 -0
- package/dist/UTF_16_LE.d.ts +8 -0
- package/dist/UTF_16_LE.d.ts.map +1 -0
- package/dist/UTF_16_LE.js +8 -0
- package/dist/UTF_16_LE.js.map +1 -0
- package/dist/UTF_8.d.ts +8 -0
- package/dist/UTF_8.d.ts.map +1 -0
- package/dist/UTF_8.js +8 -0
- package/dist/UTF_8.js.map +1 -0
- package/dist/ValueOf.d.ts +8 -0
- package/dist/ValueOf.d.ts.map +1 -0
- package/dist/ValueOf.js +2 -0
- package/dist/ValueOf.js.map +1 -0
- package/dist/ValueOrArray.d.ts +8 -0
- package/dist/ValueOrArray.d.ts.map +1 -0
- package/dist/ValueOrArray.js +2 -0
- package/dist/ValueOrArray.js.map +1 -0
- package/dist/arrayBufferToHex.d.ts +14 -0
- package/dist/arrayBufferToHex.d.ts.map +1 -0
- package/dist/arrayBufferToHex.js +17 -0
- package/dist/arrayBufferToHex.js.map +1 -0
- package/dist/arrayBufferToUuid.d.ts +14 -0
- package/dist/arrayBufferToUuid.d.ts.map +1 -0
- package/dist/arrayBufferToUuid.js +18 -0
- package/dist/arrayBufferToUuid.js.map +1 -0
- package/dist/base64decode.d.ts +15 -0
- package/dist/base64decode.d.ts.map +1 -0
- package/dist/base64decode.js +18 -0
- package/dist/base64decode.js.map +1 -0
- package/dist/base64encode.d.ts +15 -0
- package/dist/base64encode.d.ts.map +1 -0
- package/dist/base64encode.js +18 -0
- package/dist/base64encode.js.map +1 -0
- package/dist/convertUint8ToUint16.d.ts +10 -0
- package/dist/convertUint8ToUint16.d.ts.map +1 -0
- package/dist/convertUint8ToUint16.js +17 -0
- package/dist/convertUint8ToUint16.js.map +1 -0
- package/dist/decodeBase64.d.ts +11 -0
- package/dist/decodeBase64.d.ts.map +1 -0
- package/dist/decodeBase64.js +13 -0
- package/dist/decodeBase64.js.map +1 -0
- package/dist/decodeText.d.ts +17 -0
- package/dist/decodeText.d.ts.map +1 -0
- package/dist/decodeText.js +140 -0
- package/dist/decodeText.js.map +1 -0
- package/dist/encodeBase64.d.ts +11 -0
- package/dist/encodeBase64.d.ts.map +1 -0
- package/dist/encodeBase64.js +13 -0
- package/dist/encodeBase64.js.map +1 -0
- package/dist/getBandwidthBps.d.ts +12 -0
- package/dist/getBandwidthBps.d.ts.map +1 -0
- package/dist/getBandwidthBps.js +15 -0
- package/dist/getBandwidthBps.js.map +1 -0
- package/dist/hexToArrayBuffer.d.ts +14 -0
- package/dist/hexToArrayBuffer.d.ts.map +1 -0
- package/dist/hexToArrayBuffer.js +21 -0
- package/dist/hexToArrayBuffer.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/roundToEven.d.ts +13 -0
- package/dist/roundToEven.d.ts.map +1 -0
- package/dist/roundToEven.js +28 -0
- package/dist/roundToEven.js.map +1 -0
- package/dist/stringToUint16.d.ts +14 -0
- package/dist/stringToUint16.d.ts.map +1 -0
- package/dist/stringToUint16.js +21 -0
- package/dist/stringToUint16.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/unescapeHtml.d.ts +14 -0
- package/dist/unescapeHtml.d.ts.map +1 -0
- package/dist/unescapeHtml.js +38 -0
- package/dist/unescapeHtml.js.map +1 -0
- package/dist/urlToRelativePath.d.ts +12 -0
- package/dist/urlToRelativePath.d.ts.map +1 -0
- package/dist/urlToRelativePath.js +37 -0
- package/dist/urlToRelativePath.js.map +1 -0
- package/dist/uuid.d.ts +10 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +31 -0
- package/dist/uuid.js.map +1 -0
- package/dist/uuidToArrayBuffer.d.ts +14 -0
- package/dist/uuidToArrayBuffer.d.ts.map +1 -0
- package/dist/uuidToArrayBuffer.js +18 -0
- package/dist/uuidToArrayBuffer.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an ArrayBuffer to a UUID string.
|
|
3
|
+
*
|
|
4
|
+
* @param buffer - The ArrayBuffer to convert.
|
|
5
|
+
* @returns The UUID string representation.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* {@includeCode ../test/arrayBufferToUuid.test.ts#example}
|
|
12
|
+
*/
|
|
13
|
+
export declare function arrayBufferToUuid(buffer: ArrayBuffer): string;
|
|
14
|
+
//# sourceMappingURL=arrayBufferToUuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrayBufferToUuid.d.ts","sourceRoot":"","sources":["../src/arrayBufferToUuid.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAG7D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { arrayBufferToHex } from './arrayBufferToHex.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts an ArrayBuffer to a UUID string.
|
|
4
|
+
*
|
|
5
|
+
* @param buffer - The ArrayBuffer to convert.
|
|
6
|
+
* @returns The UUID string representation.
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @beta
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* {@includeCode ../test/arrayBufferToUuid.test.ts#example}
|
|
13
|
+
*/
|
|
14
|
+
export function arrayBufferToUuid(buffer) {
|
|
15
|
+
const hex = arrayBufferToHex(buffer);
|
|
16
|
+
return hex.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '$1-$2-$3-$4-$5');
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=arrayBufferToUuid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrayBufferToUuid.js","sourceRoot":"","sources":["../src/arrayBufferToUuid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAmB;IACpD,MAAM,GAAG,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO,GAAG,CAAC,OAAO,CAAC,iCAAiC,EAAE,gBAAgB,CAAC,CAAC;AACzE,CAAC","sourcesContent":["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"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a base64 encoded string into binary data
|
|
3
|
+
*
|
|
4
|
+
* @param str - The base64 encoded string to decode
|
|
5
|
+
* @returns The decoded binary data
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use {@link decodeBase64} instead.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link decodeBase64}
|
|
13
|
+
*/
|
|
14
|
+
export declare function base64decode(str: string): Uint8Array;
|
|
15
|
+
//# sourceMappingURL=base64decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64decode.d.ts","sourceRoot":"","sources":["../src/base64decode.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAEpD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { decodeBase64 } from './decodeBase64.js';
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a base64 encoded string into binary data
|
|
4
|
+
*
|
|
5
|
+
* @param str - The base64 encoded string to decode
|
|
6
|
+
* @returns The decoded binary data
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @beta
|
|
10
|
+
*
|
|
11
|
+
* @deprecated Use {@link decodeBase64} instead.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link decodeBase64}
|
|
14
|
+
*/
|
|
15
|
+
export function base64decode(str) {
|
|
16
|
+
return decodeBase64(str);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=base64decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64decode.js","sourceRoot":"","sources":["../src/base64decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACvC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["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 function base64decode(str: string): Uint8Array {\n\treturn decodeBase64(str);\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes binary data to base64
|
|
3
|
+
*
|
|
4
|
+
* @param binary - The binary data to encode
|
|
5
|
+
* @returns The base64 encoded string
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use {@link encodeBase64} instead.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link encodeBase64}
|
|
13
|
+
*/
|
|
14
|
+
export declare function base64encode(binary: Uint8Array): string;
|
|
15
|
+
//# sourceMappingURL=base64encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64encode.d.ts","sourceRoot":"","sources":["../src/base64encode.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAEvD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { encodeBase64 } from './encodeBase64.js';
|
|
2
|
+
/**
|
|
3
|
+
* Encodes binary data to base64
|
|
4
|
+
*
|
|
5
|
+
* @param binary - The binary data to encode
|
|
6
|
+
* @returns The base64 encoded string
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @beta
|
|
10
|
+
*
|
|
11
|
+
* @deprecated Use {@link encodeBase64} instead.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link encodeBase64}
|
|
14
|
+
*/
|
|
15
|
+
export function base64encode(binary) {
|
|
16
|
+
return encodeBase64(binary);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=base64encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64encode.js","sourceRoot":"","sources":["../src/base64encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC9C,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["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 function base64encode(binary: Uint8Array): string {\n\treturn encodeBase64(binary);\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a Uint8Array to a Uint16Array by aligning its buffer.
|
|
3
|
+
*
|
|
4
|
+
* @param input - The Uint8Array to convert
|
|
5
|
+
* @returns A properly aligned Uint16Array
|
|
6
|
+
*
|
|
7
|
+
* @beta
|
|
8
|
+
*/
|
|
9
|
+
export declare function convertUint8ToUint16(input: Uint8Array): Uint16Array;
|
|
10
|
+
//# sourceMappingURL=convertUint8ToUint16.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertUint8ToUint16.d.ts","sourceRoot":"","sources":["../src/convertUint8ToUint16.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAOnE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a Uint8Array to a Uint16Array by aligning its buffer.
|
|
3
|
+
*
|
|
4
|
+
* @param input - The Uint8Array to convert
|
|
5
|
+
* @returns A properly aligned Uint16Array
|
|
6
|
+
*
|
|
7
|
+
* @beta
|
|
8
|
+
*/
|
|
9
|
+
export function convertUint8ToUint16(input) {
|
|
10
|
+
if (input.length % 2 !== 0) {
|
|
11
|
+
const padded = new Uint8Array(input.length + 1);
|
|
12
|
+
padded.set(input);
|
|
13
|
+
return new Uint16Array(padded.buffer);
|
|
14
|
+
}
|
|
15
|
+
return new Uint16Array(input.buffer);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=convertUint8ToUint16.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertUint8ToUint16.js","sourceRoot":"","sources":["../src/convertUint8ToUint16.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAiB;IACrD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClB,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/**\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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a base64 encoded string into binary data
|
|
3
|
+
*
|
|
4
|
+
* @param str - The base64 encoded string to decode
|
|
5
|
+
* @returns The decoded binary data
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export declare function decodeBase64(str: string): Uint8Array;
|
|
11
|
+
//# sourceMappingURL=decodeBase64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeBase64.d.ts","sourceRoot":"","sources":["../src/decodeBase64.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAEpD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a base64 encoded string into binary data
|
|
3
|
+
*
|
|
4
|
+
* @param str - The base64 encoded string to decode
|
|
5
|
+
* @returns The decoded binary data
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export function decodeBase64(str) {
|
|
11
|
+
return new Uint8Array([...atob(str)].map((a) => a.charCodeAt(0)));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=decodeBase64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeBase64.js","sourceRoot":"","sources":["../src/decodeBase64.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACvC,OAAO,IAAI,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["/**\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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DecodeTextOptions } from './DecodeTextOptions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts an ArrayBuffer or ArrayBufferView to a string. Similar to `TextDecoder.decode`
|
|
4
|
+
* but with a fallback for environments that don't support `TextDecoder`.
|
|
5
|
+
*
|
|
6
|
+
* @param data - The data to decode.
|
|
7
|
+
* @param options - The options for the decoding.
|
|
8
|
+
* @returns The string representation of the ArrayBuffer.
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* @beta
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* {@includeCode ../test/decodeText.test.ts#example}
|
|
15
|
+
*/
|
|
16
|
+
export declare function decodeText(data: ArrayBuffer | ArrayBufferView<ArrayBuffer>, options?: DecodeTextOptions): string;
|
|
17
|
+
//# sourceMappingURL=decodeText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeText.d.ts","sourceRoot":"","sources":["../src/decodeText.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAMhE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,eAAe,CAAC,WAAW,CAAC,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAmIpH"}
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
* Converts an ArrayBuffer or ArrayBufferView to a string. Similar to `TextDecoder.decode`
|
|
7
|
+
* but with a fallback for environments that don't support `TextDecoder`.
|
|
8
|
+
*
|
|
9
|
+
* @param data - The data to decode.
|
|
10
|
+
* @param options - The options for the decoding.
|
|
11
|
+
* @returns The string representation of the ArrayBuffer.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* @beta
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* {@includeCode ../test/decodeText.test.ts#example}
|
|
18
|
+
*/
|
|
19
|
+
export function decodeText(data, options = {}) {
|
|
20
|
+
let view;
|
|
21
|
+
if (data instanceof ArrayBuffer) {
|
|
22
|
+
view = new DataView(data);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
26
|
+
}
|
|
27
|
+
let byteOffset = 0;
|
|
28
|
+
let { encoding } = options;
|
|
29
|
+
// If no encoding is provided, try to detect it from the BOM
|
|
30
|
+
if (!encoding) {
|
|
31
|
+
const first = view.getUint8(0);
|
|
32
|
+
const second = view.getUint8(1);
|
|
33
|
+
// UTF-8 BOM
|
|
34
|
+
if (first == 0xef && second == 0xbb && view.getUint8(2) == 0xbf) {
|
|
35
|
+
encoding = UTF_8;
|
|
36
|
+
byteOffset = 3;
|
|
37
|
+
}
|
|
38
|
+
// UTF-16 BE BOM
|
|
39
|
+
else if (first == 0xfe && second == 0xff) {
|
|
40
|
+
encoding = UTF_16_BE;
|
|
41
|
+
byteOffset = 2;
|
|
42
|
+
}
|
|
43
|
+
// UTF-16 LE BOM
|
|
44
|
+
else if (first == 0xff && second == 0xfe) {
|
|
45
|
+
encoding = UTF_16_LE;
|
|
46
|
+
byteOffset = 2;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
encoding = UTF_8;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
53
|
+
return new TextDecoder(encoding).decode(view);
|
|
54
|
+
}
|
|
55
|
+
const { byteLength } = view;
|
|
56
|
+
const endian = encoding !== UTF_16_BE;
|
|
57
|
+
let str = '';
|
|
58
|
+
let char;
|
|
59
|
+
while (byteOffset < byteLength) {
|
|
60
|
+
switch (encoding) {
|
|
61
|
+
case UTF_8:
|
|
62
|
+
char = view.getUint8(byteOffset);
|
|
63
|
+
// Single byte (ASCII)
|
|
64
|
+
if (char < 128) {
|
|
65
|
+
byteOffset++;
|
|
66
|
+
}
|
|
67
|
+
// 2-byte sequence
|
|
68
|
+
else if (char >= 194 && char <= 223) {
|
|
69
|
+
if (byteOffset + 1 < byteLength) {
|
|
70
|
+
const byte2 = view.getUint8(byteOffset + 1);
|
|
71
|
+
if (byte2 >= 128 && byte2 <= 191) {
|
|
72
|
+
char = ((char & 0x1F) << 6) | (byte2 & 0x3F);
|
|
73
|
+
byteOffset += 2;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Invalid sequence, skip
|
|
77
|
+
byteOffset++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// Incomplete sequence, skip
|
|
82
|
+
byteOffset++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// 3-byte sequence
|
|
86
|
+
else if (char >= 224 && char <= 239) {
|
|
87
|
+
if (byteOffset + 2 <= byteLength - 1) {
|
|
88
|
+
const byte2 = view.getUint8(byteOffset + 1);
|
|
89
|
+
const byte3 = view.getUint8(byteOffset + 2);
|
|
90
|
+
if (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191) {
|
|
91
|
+
char = ((char & 0x0F) << 12) | ((byte2 & 0x3F) << 6) | (byte3 & 0x3F);
|
|
92
|
+
byteOffset += 3;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Invalid sequence, skip
|
|
96
|
+
byteOffset++;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Incomplete sequence, skip
|
|
101
|
+
byteOffset++;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// 4-byte sequence
|
|
105
|
+
else if (char >= 240 && char <= 244) {
|
|
106
|
+
if (byteOffset + 3 <= byteLength - 1) {
|
|
107
|
+
const byte2 = view.getUint8(byteOffset + 1);
|
|
108
|
+
const byte3 = view.getUint8(byteOffset + 2);
|
|
109
|
+
const byte4 = view.getUint8(byteOffset + 3);
|
|
110
|
+
if (byte2 >= 128 && byte2 <= 191 && byte3 >= 128 && byte3 <= 191 && byte4 >= 128 && byte4 <= 191) {
|
|
111
|
+
char = ((char & 0x07) << 18) | ((byte2 & 0x3F) << 12) | ((byte3 & 0x3F) << 6) | (byte4 & 0x3F);
|
|
112
|
+
byteOffset += 4;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// Invalid sequence, skip
|
|
116
|
+
byteOffset++;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Incomplete sequence, skip
|
|
121
|
+
byteOffset++;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Invalid byte, skip
|
|
125
|
+
else {
|
|
126
|
+
byteOffset++;
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
case UTF_16_BE:
|
|
130
|
+
case UTF_16:
|
|
131
|
+
case UTF_16_LE:
|
|
132
|
+
char = view.getUint16(byteOffset, endian);
|
|
133
|
+
byteOffset += 2;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
str += String.fromCodePoint(char);
|
|
137
|
+
}
|
|
138
|
+
return str;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=decodeText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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UAAU,GAAG,CAAC,CAAC,CAAC;wBAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;wBAC5C,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;4BAClG,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;4BAC/F,UAAU,IAAI,CAAC,CAAC;wBACjB,CAAC;6BACI,CAAC;4BACL,yBAAyB;4BACzB,UAAU,EAAE,CAAC;wBACd,CAAC;oBACF,CAAC;yBACI,CAAC;wBACL,4BAA4B;wBAC5B,UAAU,EAAE,CAAC;oBACd,CAAC;gBACF,CAAC;gBACD,qBAAqB;qBAChB,CAAC;oBACL,UAAU,EAAE,CAAC;gBACd,CAAC;gBACD,MAAM;YAEP,KAAK,SAAS,CAAC;YACf,KAAK,MAAM,CAAC;YACZ,KAAK,SAAS;gBACb,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;gBAC1C,UAAU,IAAI,CAAC,CAAC;gBAChB,MAAM;QACR,CAAC;QAED,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,GAAG,CAAC;AACZ,CAAC","sourcesContent":["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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes binary data to base64
|
|
3
|
+
*
|
|
4
|
+
* @param binary - The binary data to encode
|
|
5
|
+
* @returns The base64 encoded string
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export declare function encodeBase64(binary: Uint8Array): string;
|
|
11
|
+
//# sourceMappingURL=encodeBase64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeBase64.d.ts","sourceRoot":"","sources":["../src/encodeBase64.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAEvD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes binary data to base64
|
|
3
|
+
*
|
|
4
|
+
* @param binary - The binary data to encode
|
|
5
|
+
* @returns The base64 encoded string
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export function encodeBase64(binary) {
|
|
11
|
+
return btoa(String.fromCharCode(...binary));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=encodeBase64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeBase64.js","sourceRoot":"","sources":["../src/encodeBase64.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC9C,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/**\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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ResourceTiming } from './ResourceTiming.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a ResourceTiming sample to bandwidth in bits per second (bps).
|
|
4
|
+
*
|
|
5
|
+
* @param sample - A ResourceTiming sample
|
|
6
|
+
* @returns
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export declare function getBandwidthBps(sample: ResourceTiming): number;
|
|
12
|
+
//# sourceMappingURL=getBandwidthBps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBandwidthBps.d.ts","sourceRoot":"","sources":["../src/getBandwidthBps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAI9D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a ResourceTiming sample to bandwidth in bits per second (bps).
|
|
3
|
+
*
|
|
4
|
+
* @param sample - A ResourceTiming sample
|
|
5
|
+
* @returns
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export function getBandwidthBps(sample) {
|
|
11
|
+
const durationSeconds = sample.duration / 1000;
|
|
12
|
+
const bandwidthBps = sample.encodedBodySize * 8 / durationSeconds;
|
|
13
|
+
return bandwidthBps;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=getBandwidthBps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBandwidthBps.js","sourceRoot":"","sources":["../src/getBandwidthBps.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,MAAsB;IACrD,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC/C,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,GAAG,CAAC,GAAG,eAAe,CAAC;IAClE,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["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"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a hexadecimal string into an ArrayBuffer.
|
|
3
|
+
*
|
|
4
|
+
* @param hex - The hexadecimal string to decode.
|
|
5
|
+
* @returns The decoded ArrayBuffer.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* {@includeCode ../test/hexToArrayBuffer.test.ts#example}
|
|
12
|
+
*/
|
|
13
|
+
export declare function hexToArrayBuffer(hex: string): ArrayBuffer;
|
|
14
|
+
//# sourceMappingURL=hexToArrayBuffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hexToArrayBuffer.d.ts","sourceRoot":"","sources":["../src/hexToArrayBuffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAOzD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a hexadecimal string into an ArrayBuffer.
|
|
3
|
+
*
|
|
4
|
+
* @param hex - The hexadecimal string to decode.
|
|
5
|
+
* @returns The decoded ArrayBuffer.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* {@includeCode ../test/hexToArrayBuffer.test.ts#example}
|
|
12
|
+
*/
|
|
13
|
+
export function hexToArrayBuffer(hex) {
|
|
14
|
+
const buffer = new ArrayBuffer(hex.length / 2);
|
|
15
|
+
const view = new Uint8Array(buffer);
|
|
16
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
17
|
+
view[i / 2] = parseInt(hex.slice(i, i + 2), 16);
|
|
18
|
+
}
|
|
19
|
+
return buffer;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=hexToArrayBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hexToArrayBuffer.js","sourceRoot":"","sources":["../src/hexToArrayBuffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC3C,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\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"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
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';
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
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';
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This implements the rounding procedure described in step 2 of the "Serializing a Decimal" specification.
|
|
3
|
+
* This rounding style is known as "even rounding", "banker's rounding", or "commercial rounding".
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to round
|
|
6
|
+
* @param precision - The number of decimal places to round to
|
|
7
|
+
* @returns The rounded value
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* @beta
|
|
11
|
+
*/
|
|
12
|
+
export declare function roundToEven(value: number, precision: number): number;
|
|
13
|
+
//# sourceMappingURL=roundToEven.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roundToEven.d.ts","sourceRoot":"","sources":["../src/roundToEven.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAiBpE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This implements the rounding procedure described in step 2 of the "Serializing a Decimal" specification.
|
|
3
|
+
* This rounding style is known as "even rounding", "banker's rounding", or "commercial rounding".
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to round
|
|
6
|
+
* @param precision - The number of decimal places to round to
|
|
7
|
+
* @returns The rounded value
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* @beta
|
|
11
|
+
*/
|
|
12
|
+
export function roundToEven(value, precision) {
|
|
13
|
+
if (value < 0) {
|
|
14
|
+
return -roundToEven(-value, precision);
|
|
15
|
+
}
|
|
16
|
+
const decimalShift = Math.pow(10, precision);
|
|
17
|
+
const isEquidistant = Math.abs(((value * decimalShift) % 1) - 0.5) < Number.EPSILON;
|
|
18
|
+
if (isEquidistant) {
|
|
19
|
+
// If the tail of the decimal place is 'equidistant' we round to the nearest even value
|
|
20
|
+
const flooredValue = Math.floor(value * decimalShift);
|
|
21
|
+
return (flooredValue % 2 === 0 ? flooredValue : flooredValue + 1) / decimalShift;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// Otherwise, proceed as normal
|
|
25
|
+
return Math.round(value * decimalShift) / decimalShift;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=roundToEven.js.map
|