@capacitor-community/bluetooth-le 8.0.1 → 8.0.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/CapacitorCommunityBluetoothLe.podspec +17 -17
- package/LICENSE +21 -21
- package/Package.swift +27 -27
- package/README.md +2 -1
- package/android/build.gradle +73 -73
- package/android/src/main/AndroidManifest.xml +22 -22
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/BluetoothLe.kt +1094 -1094
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Conversion.kt +51 -51
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/Device.kt +771 -771
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/DeviceList.kt +28 -28
- package/android/src/main/java/com/capacitorjs/community/plugins/bluetoothle/DeviceScanner.kt +189 -189
- package/dist/docs.json +43 -43
- package/dist/esm/bleClient.d.ts +278 -278
- package/dist/esm/bleClient.js +361 -361
- package/dist/esm/bleClient.js.map +1 -1
- package/dist/esm/config.d.ts +53 -53
- package/dist/esm/config.js +2 -2
- package/dist/esm/conversion.d.ts +56 -56
- package/dist/esm/conversion.js +134 -134
- package/dist/esm/conversion.js.map +1 -1
- package/dist/esm/definitions.d.ts +352 -352
- package/dist/esm/definitions.js +42 -42
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +5 -5
- package/dist/esm/plugin.d.ts +2 -2
- package/dist/esm/plugin.js +4 -4
- package/dist/esm/queue.d.ts +3 -3
- package/dist/esm/queue.js +17 -17
- package/dist/esm/timeout.d.ts +1 -1
- package/dist/esm/timeout.js +9 -9
- package/dist/esm/validators.d.ts +1 -1
- package/dist/esm/validators.js +11 -11
- package/dist/esm/web.d.ts +57 -57
- package/dist/esm/web.js +403 -403
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +964 -964
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +964 -964
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/BluetoothLe/Conversion.swift +83 -83
- package/ios/Sources/BluetoothLe/Device.swift +422 -423
- package/ios/Sources/BluetoothLe/DeviceListView.swift +121 -121
- package/ios/Sources/BluetoothLe/DeviceManager.swift +409 -415
- package/ios/Sources/BluetoothLe/Logging.swift +8 -8
- package/ios/Sources/BluetoothLe/Plugin.swift +768 -763
- package/ios/Sources/BluetoothLe/ScanFilters.swift +114 -114
- package/ios/Sources/BluetoothLe/ThreadSafeDictionary.swift +61 -15
- package/ios/Tests/BluetoothLeTests/ConversionTests.swift +55 -55
- package/ios/Tests/BluetoothLeTests/PluginTests.swift +27 -27
- package/ios/Tests/BluetoothLeTests/ScanFiltersTests.swift +153 -153
- package/package.json +114 -114
package/dist/esm/conversion.js
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert an array of numbers into a DataView.
|
|
3
|
-
*/
|
|
4
|
-
export function numbersToDataView(value) {
|
|
5
|
-
return new DataView(Uint8Array.from(value).buffer);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Convert a DataView into an array of numbers.
|
|
9
|
-
*/
|
|
10
|
-
export function dataViewToNumbers(value) {
|
|
11
|
-
return Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Convert a string into a DataView.
|
|
15
|
-
*/
|
|
16
|
-
export function textToDataView(value) {
|
|
17
|
-
return numbersToDataView(value.split('').map((s) => s.charCodeAt(0)));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Convert a DataView into a string.
|
|
21
|
-
*/
|
|
22
|
-
export function dataViewToText(value) {
|
|
23
|
-
return String.fromCharCode(...dataViewToNumbers(value));
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Convert a 16 bit UUID into a 128 bit UUID string
|
|
27
|
-
* @param value number, e.g. 0x180d
|
|
28
|
-
* @return string, e.g. '0000180d-0000-1000-8000-00805f9b34fb'
|
|
29
|
-
*/
|
|
30
|
-
export function numberToUUID(value) {
|
|
31
|
-
return `0000${value.toString(16).padStart(4, '0')}-0000-1000-8000-00805f9b34fb`;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Convert a string of hex into a DataView of raw bytes.
|
|
35
|
-
* Note: characters other than [0-9a-fA-F] are ignored
|
|
36
|
-
* @param hex string of values, e.g. "00 01 02" or "000102"
|
|
37
|
-
* @return DataView of raw bytes
|
|
38
|
-
*/
|
|
39
|
-
export function hexStringToDataView(hex) {
|
|
40
|
-
const bin = [];
|
|
41
|
-
let i, c, isEmpty = 1, buffer = 0;
|
|
42
|
-
for (i = 0; i < hex.length; i++) {
|
|
43
|
-
c = hex.charCodeAt(i);
|
|
44
|
-
if ((c > 47 && c < 58) || (c > 64 && c < 71) || (c > 96 && c < 103)) {
|
|
45
|
-
buffer = (buffer << 4) ^ ((c > 64 ? c + 9 : c) & 15);
|
|
46
|
-
if ((isEmpty ^= 1)) {
|
|
47
|
-
bin.push(buffer & 0xff);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return numbersToDataView(bin);
|
|
52
|
-
}
|
|
53
|
-
export function dataViewToHexString(value) {
|
|
54
|
-
return dataViewToNumbers(value)
|
|
55
|
-
.map((n) => {
|
|
56
|
-
let s = n.toString(16);
|
|
57
|
-
if (s.length == 1) {
|
|
58
|
-
s = '0' + s;
|
|
59
|
-
}
|
|
60
|
-
return s;
|
|
61
|
-
})
|
|
62
|
-
.join('');
|
|
63
|
-
}
|
|
64
|
-
export function webUUIDToString(uuid) {
|
|
65
|
-
if (typeof uuid === 'string') {
|
|
66
|
-
return uuid;
|
|
67
|
-
}
|
|
68
|
-
else if (typeof uuid === 'number') {
|
|
69
|
-
return numberToUUID(uuid);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
throw new Error('Invalid UUID');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export function mapToObject(map) {
|
|
76
|
-
const obj = {};
|
|
77
|
-
if (!map) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
map.forEach((value, key) => {
|
|
81
|
-
obj[key.toString()] = value;
|
|
82
|
-
});
|
|
83
|
-
return obj;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Convert Data or Uint8Array to Uint8Array.
|
|
87
|
-
* @param value DataView, Uint8Array, or undefined
|
|
88
|
-
* @return Uint8Array or undefined
|
|
89
|
-
*/
|
|
90
|
-
export function toUint8Array(value) {
|
|
91
|
-
if (value === undefined) {
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
if (typeof value === 'string') {
|
|
95
|
-
const dataView = hexStringToDataView(value);
|
|
96
|
-
return new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength);
|
|
97
|
-
}
|
|
98
|
-
if (value instanceof DataView) {
|
|
99
|
-
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
100
|
-
}
|
|
101
|
-
return value; // Already Uint8Array
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Convert Data, Uint8Array, or string to hex string.
|
|
105
|
-
* @param value DataView, Uint8Array, or undefined
|
|
106
|
-
* @return hex string or undefined
|
|
107
|
-
*/
|
|
108
|
-
export function toHexString(value) {
|
|
109
|
-
if (value === undefined) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
if (value instanceof DataView) {
|
|
113
|
-
return dataViewToHexString(value);
|
|
114
|
-
}
|
|
115
|
-
// Uint8Array
|
|
116
|
-
return dataViewToHexString(new DataView(value.buffer, value.byteOffset, value.byteLength));
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Convert a DataView to a DataView backed by an ArrayBuffer.
|
|
120
|
-
* If the DataView is backed by a SharedArrayBuffer, this creates a copy.
|
|
121
|
-
* Otherwise, returns the original DataView.
|
|
122
|
-
* @param value DataView to convert
|
|
123
|
-
* @return DataView backed by ArrayBuffer
|
|
124
|
-
*/
|
|
125
|
-
export function toArrayBufferDataView(value) {
|
|
126
|
-
if (value.buffer instanceof SharedArrayBuffer) {
|
|
127
|
-
// Need to copy to a regular ArrayBuffer
|
|
128
|
-
const uint8Array = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
129
|
-
const buffer = uint8Array.slice().buffer;
|
|
130
|
-
return new DataView(buffer);
|
|
131
|
-
}
|
|
132
|
-
// Already an ArrayBuffer, use directly
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Convert an array of numbers into a DataView.
|
|
3
|
+
*/
|
|
4
|
+
export function numbersToDataView(value) {
|
|
5
|
+
return new DataView(Uint8Array.from(value).buffer);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Convert a DataView into an array of numbers.
|
|
9
|
+
*/
|
|
10
|
+
export function dataViewToNumbers(value) {
|
|
11
|
+
return Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Convert a string into a DataView.
|
|
15
|
+
*/
|
|
16
|
+
export function textToDataView(value) {
|
|
17
|
+
return numbersToDataView(value.split('').map((s) => s.charCodeAt(0)));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Convert a DataView into a string.
|
|
21
|
+
*/
|
|
22
|
+
export function dataViewToText(value) {
|
|
23
|
+
return String.fromCharCode(...dataViewToNumbers(value));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Convert a 16 bit UUID into a 128 bit UUID string
|
|
27
|
+
* @param value number, e.g. 0x180d
|
|
28
|
+
* @return string, e.g. '0000180d-0000-1000-8000-00805f9b34fb'
|
|
29
|
+
*/
|
|
30
|
+
export function numberToUUID(value) {
|
|
31
|
+
return `0000${value.toString(16).padStart(4, '0')}-0000-1000-8000-00805f9b34fb`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Convert a string of hex into a DataView of raw bytes.
|
|
35
|
+
* Note: characters other than [0-9a-fA-F] are ignored
|
|
36
|
+
* @param hex string of values, e.g. "00 01 02" or "000102"
|
|
37
|
+
* @return DataView of raw bytes
|
|
38
|
+
*/
|
|
39
|
+
export function hexStringToDataView(hex) {
|
|
40
|
+
const bin = [];
|
|
41
|
+
let i, c, isEmpty = 1, buffer = 0;
|
|
42
|
+
for (i = 0; i < hex.length; i++) {
|
|
43
|
+
c = hex.charCodeAt(i);
|
|
44
|
+
if ((c > 47 && c < 58) || (c > 64 && c < 71) || (c > 96 && c < 103)) {
|
|
45
|
+
buffer = (buffer << 4) ^ ((c > 64 ? c + 9 : c) & 15);
|
|
46
|
+
if ((isEmpty ^= 1)) {
|
|
47
|
+
bin.push(buffer & 0xff);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return numbersToDataView(bin);
|
|
52
|
+
}
|
|
53
|
+
export function dataViewToHexString(value) {
|
|
54
|
+
return dataViewToNumbers(value)
|
|
55
|
+
.map((n) => {
|
|
56
|
+
let s = n.toString(16);
|
|
57
|
+
if (s.length == 1) {
|
|
58
|
+
s = '0' + s;
|
|
59
|
+
}
|
|
60
|
+
return s;
|
|
61
|
+
})
|
|
62
|
+
.join('');
|
|
63
|
+
}
|
|
64
|
+
export function webUUIDToString(uuid) {
|
|
65
|
+
if (typeof uuid === 'string') {
|
|
66
|
+
return uuid;
|
|
67
|
+
}
|
|
68
|
+
else if (typeof uuid === 'number') {
|
|
69
|
+
return numberToUUID(uuid);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
throw new Error('Invalid UUID');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function mapToObject(map) {
|
|
76
|
+
const obj = {};
|
|
77
|
+
if (!map) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
map.forEach((value, key) => {
|
|
81
|
+
obj[key.toString()] = value;
|
|
82
|
+
});
|
|
83
|
+
return obj;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Convert Data or Uint8Array to Uint8Array.
|
|
87
|
+
* @param value DataView, Uint8Array, or undefined
|
|
88
|
+
* @return Uint8Array or undefined
|
|
89
|
+
*/
|
|
90
|
+
export function toUint8Array(value) {
|
|
91
|
+
if (value === undefined) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
if (typeof value === 'string') {
|
|
95
|
+
const dataView = hexStringToDataView(value);
|
|
96
|
+
return new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength);
|
|
97
|
+
}
|
|
98
|
+
if (value instanceof DataView) {
|
|
99
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
100
|
+
}
|
|
101
|
+
return value; // Already Uint8Array
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Convert Data, Uint8Array, or string to hex string.
|
|
105
|
+
* @param value DataView, Uint8Array, or undefined
|
|
106
|
+
* @return hex string or undefined
|
|
107
|
+
*/
|
|
108
|
+
export function toHexString(value) {
|
|
109
|
+
if (value === undefined) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
if (value instanceof DataView) {
|
|
113
|
+
return dataViewToHexString(value);
|
|
114
|
+
}
|
|
115
|
+
// Uint8Array
|
|
116
|
+
return dataViewToHexString(new DataView(value.buffer, value.byteOffset, value.byteLength));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Convert a DataView to a DataView backed by an ArrayBuffer.
|
|
120
|
+
* If the DataView is backed by a SharedArrayBuffer, this creates a copy.
|
|
121
|
+
* Otherwise, returns the original DataView.
|
|
122
|
+
* @param value DataView to convert
|
|
123
|
+
* @return DataView backed by ArrayBuffer
|
|
124
|
+
*/
|
|
125
|
+
export function toArrayBufferDataView(value) {
|
|
126
|
+
if (value.buffer instanceof SharedArrayBuffer) {
|
|
127
|
+
// Need to copy to a regular ArrayBuffer
|
|
128
|
+
const uint8Array = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
129
|
+
const buffer = uint8Array.slice().buffer;
|
|
130
|
+
return new DataView(buffer);
|
|
131
|
+
}
|
|
132
|
+
// Already an ArrayBuffer, use directly
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
135
|
//# sourceMappingURL=conversion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.js","sourceRoot":"","sources":["../../src/conversion.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAe;IAC/C,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAe;IAC/C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AACtF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,OAAO,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAe;IAC5C,OAAO,MAAM,CAAC,YAAY,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,8BAA8B,CAAC;AAClF,CAAC;AAED;;;;;G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C;QAC5C,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;KAClF;IACD,IAAI,KAAK,YAAY,QAAQ,EAAE;QAC7B,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;KACzE;IACD,OAAO,KAAK,CAAC,CAAC,qBAAqB;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAwC;IAClE,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,OAAO,SAAS,CAAC;KAClB;IACD,IAAI,KAAK,YAAY,QAAQ,EAAE;QAC7B,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;KACnC;IACD,aAAa;IACb,OAAO,mBAAmB,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAC7F,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAe;IACnD,IAAI,KAAK,CAAC,MAAM,YAAY,iBAAiB,EAAE;QAC7C,wCAAwC;QACxC,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QACpF,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC;QACzC,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAuC,CAAC;KACnE;IACD,uCAAuC;IACvC,OAAO,KAA2C,CAAC;AACrD,CAAC","sourcesContent":["/**\n * Convert an array of numbers into a DataView.\n */\nexport function numbersToDataView(value: number[]): DataView {\n return new DataView(Uint8Array.from(value).buffer);\n}\n\n/**\n * Convert a DataView into an array of numbers.\n */\nexport function dataViewToNumbers(value: DataView): number[] {\n return Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));\n}\n\n/**\n * Convert a string into a DataView.\n */\nexport function textToDataView(value: string): DataView {\n return numbersToDataView(value.split('').map((s) => s.charCodeAt(0)));\n}\n\n/**\n * Convert a DataView into a string.\n */\nexport function dataViewToText(value: DataView): string {\n return String.fromCharCode(...dataViewToNumbers(value));\n}\n\n/**\n * Convert a 16 bit UUID into a 128 bit UUID string\n * @param value number, e.g. 0x180d\n * @return string, e.g. '0000180d-0000-1000-8000-00805f9b34fb'\n */\nexport function numberToUUID(value: number): string {\n return `0000${value.toString(16).padStart(4, '0')}-0000-1000-8000-00805f9b34fb`;\n}\n\n/**\n * Convert a string of hex into a DataView of raw bytes.\n * Note: characters other than [0-9a-fA-F] are ignored\n * @param hex string of values, e.g. \"00 01 02\" or \"000102\"\n * @return DataView of raw bytes\n */\nexport function hexStringToDataView(hex: string): DataView {\n const bin = [];\n let i,\n c,\n isEmpty = 1,\n buffer = 0;\n for (i = 0; i < hex.length; i++) {\n c = hex.charCodeAt(i);\n if ((c > 47 && c < 58) || (c > 64 && c < 71) || (c > 96 && c < 103)) {\n buffer = (buffer << 4) ^ ((c > 64 ? c + 9 : c) & 15);\n if ((isEmpty ^= 1)) {\n bin.push(buffer & 0xff);\n }\n }\n }\n return numbersToDataView(bin);\n}\n\nexport function dataViewToHexString(value: DataView): string {\n return dataViewToNumbers(value)\n .map((n) => {\n let s = n.toString(16);\n if (s.length == 1) {\n s = '0' + s;\n }\n return s;\n })\n .join('');\n}\n\nexport function webUUIDToString(uuid: string | number): string {\n if (typeof uuid === 'string') {\n return uuid;\n } else if (typeof uuid === 'number') {\n return numberToUUID(uuid);\n } else {\n throw new Error('Invalid UUID');\n }\n}\n\nexport function mapToObject<V>(map?: Map<string | number, V>): { [key: string]: V } | undefined {\n const obj: { [key: string]: V } = {};\n if (!map) {\n return undefined;\n }\n map.forEach((value, key) => {\n obj[key.toString()] = value;\n });\n return obj;\n}\n\n/**\n * Convert Data or Uint8Array to Uint8Array.\n * @param value DataView, Uint8Array, or undefined\n * @return Uint8Array or undefined\n */\nexport function toUint8Array(value: DataView | Uint8Array | undefined): Uint8Array | undefined {\n if (value === undefined) {\n return undefined;\n }\n if (typeof value === 'string') {\n const dataView = hexStringToDataView(value);\n return new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength);\n }\n if (value instanceof DataView) {\n return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n }\n return value; // Already Uint8Array\n}\n\n/**\n * Convert Data, Uint8Array, or string to hex string.\n * @param value DataView, Uint8Array, or undefined\n * @return hex string or undefined\n */\nexport function toHexString(value: DataView | Uint8Array | undefined): string | undefined {\n if (value === undefined) {\n return undefined;\n }\n if (value instanceof DataView) {\n return dataViewToHexString(value);\n }\n // Uint8Array\n return dataViewToHexString(new DataView(value.buffer, value.byteOffset, value.byteLength));\n}\n\n/**\n * Convert a DataView to a DataView backed by an ArrayBuffer.\n * If the DataView is backed by a SharedArrayBuffer, this creates a copy.\n * Otherwise, returns the original DataView.\n * @param value DataView to convert\n * @return DataView backed by ArrayBuffer\n */\nexport function toArrayBufferDataView(value: DataView): DataView & { buffer: ArrayBuffer } {\n if (value.buffer instanceof SharedArrayBuffer) {\n // Need to copy to a regular ArrayBuffer\n const uint8Array = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n const buffer = uint8Array.slice().buffer;\n return new DataView(buffer) as DataView & { buffer: ArrayBuffer };\n }\n // Already an ArrayBuffer, use directly\n return value as DataView & { buffer: ArrayBuffer };\n}\n"]}
|