motion-master-client 0.0.339 → 0.0.340
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/package.json +1 -1
- package/src/api.js +79 -73
- package/src/api.js.map +1 -1
- package/src/lib/data-monitoring.d.ts +2 -2
- package/src/lib/data-monitoring.js +2 -2
- package/src/lib/device-parameter.d.ts +50 -3
- package/src/lib/device-parameter.js +117 -4
- package/src/lib/device-parameter.js.map +1 -1
- package/src/lib/motion-master-req-res-client.d.ts +12 -0
- package/src/lib/motion-master-req-res-client.js +14 -0
- package/src/lib/motion-master-req-res-client.js.map +1 -1
- package/src/lib/operators.d.ts +195 -1
- package/src/lib/operators.js +202 -1
- package/src/lib/operators.js.map +1 -1
- package/src/lib/util.d.ts +299 -160
- package/src/lib/util.js +301 -170
- package/src/lib/util.js.map +1 -1
package/src/lib/util.js
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeNormalizeTimestampFn = exports.analyzeTimeDurations = exports.
|
|
3
|
+
exports.makeNormalizeTimestampFn = exports.analyzeTimeDurations = exports.fromQ = exports.convertIpv4 = exports.convertValueToHexString = exports.hexDecValueToNumber = exports.convertCTypeToStructFormatCharacter = exports.mapByProperty = exports.groupByProperty = exports.uniqueItems = exports.mergeUint8Arrays = exports.parseUnitValue = exports.isElectronContext = exports.isElectronApp = exports.convertBlobToBase64 = exports.toFixedFormat = exports.updateBit = exports.clearBit = exports.setBit = exports.isBitOn = exports.getBit = exports.setBitHigh = exports.setBitLow = exports.camelCaseToWords = exports.findDuplicates = exports.getMapKeyByValue = exports.createRandomColor = exports.convertRgbToLedColor = exports.resolveAfter = exports.decodeTextContent = exports.convertMotionMasterMessageToLoggerContext = exports.createPlainObjectFromMotionMasterMessage = exports.diffSystemLogContents = exports.parseSystemLogContent = exports.parseSystemLogLine = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
6
5
|
const types_1 = require("./types");
|
|
7
6
|
/**
|
|
8
|
-
* Parses a single line of system log into a structured `SystemLogLine` object.
|
|
7
|
+
* Parses a single line of a system log into a structured `SystemLogLine` object.
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* The function expects the log line to follow the format:
|
|
10
|
+
* ```
|
|
11
|
+
* YYYY-MM-DD HH:MM:SS.sss (uptime) [id]file:linelevel|message
|
|
12
|
+
* ```
|
|
13
|
+
* where the `id` part is optional.
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* @param line - A single system log line as a string.
|
|
16
|
+
* @returns A `SystemLogLine` object with parsed fields, or `undefined` if the line cannot be parsed.
|
|
16
17
|
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
18
|
+
* @example
|
|
19
|
+
* const line = '2025-12-05 10:01:23.123 (12:34:56) [device1]main.ts:123INFO|Started';
|
|
20
|
+
* const parsed = parseSystemLogLine(line);
|
|
21
|
+
* console.log(parsed?.date); // → Date object for '2025-12-05 10:01:23.123'
|
|
22
|
+
* console.log(parsed?.uptime); // → '12:34:56'
|
|
23
|
+
* console.log(parsed?.id); // → 'device1'
|
|
24
|
+
* console.log(parsed?.message); // → 'Started'
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - Uses a regular expression with the `s` (dotAll) flag; this may not be supported in all browsers.
|
|
28
|
+
* - If parsing fails, the function returns `undefined`.
|
|
29
|
+
* - The returned object includes the original line for reference.
|
|
19
30
|
*/
|
|
20
31
|
function parseSystemLogLine(line) {
|
|
21
32
|
// @ts-ignore - The 's' flag is not supported in all browsers.
|
|
@@ -36,17 +47,24 @@ function parseSystemLogLine(line) {
|
|
|
36
47
|
}
|
|
37
48
|
exports.parseSystemLogLine = parseSystemLogLine;
|
|
38
49
|
/**
|
|
39
|
-
* Parses
|
|
50
|
+
* Parses a system log string into an array of structured `SystemLogLine` objects.
|
|
40
51
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
52
|
+
* Each log entry is expected to start with a timestamp in the format `YYYY-MM-DD HH:MM:SS.sss`.
|
|
53
|
+
* The function uses a regular expression to split the content into individual log entries,
|
|
54
|
+
* then parses each entry into a `SystemLogLine` using `parseSystemLogLine`.
|
|
44
55
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
56
|
+
* @param content - The full system log content as a string.
|
|
57
|
+
* @returns An array of `SystemLogLine` objects representing each parsed log entry.
|
|
47
58
|
*
|
|
48
|
-
* @
|
|
49
|
-
*
|
|
59
|
+
* @example
|
|
60
|
+
* const logContent = '2025-12-05 10:01:23.123 Info: started\n2025-12-05 10:01:24.456 Error: failed';
|
|
61
|
+
* const lines = parseSystemLogContent(logContent);
|
|
62
|
+
* console.log(lines[0].timestamp); // → Date object for '2025-12-05 10:01:23.123'
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* - Entries that cannot be parsed by `parseSystemLogLine` are ignored.
|
|
66
|
+
* - The regular expression uses the `s` (dotAll) flag, which may not be supported in all browsers;
|
|
67
|
+
* a `@ts-ignore` is used to suppress TypeScript warnings.
|
|
50
68
|
*/
|
|
51
69
|
function parseSystemLogContent(content) {
|
|
52
70
|
// @ts-ignore - The 's' flag is not supported in all browsers.
|
|
@@ -59,17 +77,26 @@ function parseSystemLogContent(content) {
|
|
|
59
77
|
}
|
|
60
78
|
exports.parseSystemLogContent = parseSystemLogContent;
|
|
61
79
|
/**
|
|
62
|
-
*
|
|
80
|
+
* Computes the difference between two system log contents by returning only the new lines
|
|
81
|
+
* added after the last known line from the old content.
|
|
63
82
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
83
|
+
* @param oldContent - The previous log content.
|
|
84
|
+
* @param newContent - The current log content.
|
|
85
|
+
* @param lineSeparator - Optional string used to split lines (default: `'\n'`).
|
|
86
|
+
* @param lastLineIndex - Optional index of the line in `oldContent` to use as the reference point
|
|
87
|
+
* (default: `-2`, i.e., the second-to-last line).
|
|
88
|
+
* @returns A string containing only the new lines from `newContent` that come after the reference
|
|
89
|
+
* line from `oldContent`. If the reference line is not found, returns the entire `newContent`.
|
|
67
90
|
*
|
|
68
|
-
* @
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
91
|
+
* @example
|
|
92
|
+
* const oldLog = 'line1\nline2\nline3';
|
|
93
|
+
* const newLog = 'line1\nline2\nline3\nline4\nline5';
|
|
94
|
+
* const diff = diffSystemLogContents(oldLog, newLog);
|
|
95
|
+
* console.log(diff); // → 'line4\nline5'
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* - Useful for incremental log processing where only newly appended lines need to be handled.
|
|
99
|
+
* - Handles negative indexing for selecting the reference line from the end of `oldContent`.
|
|
73
100
|
*/
|
|
74
101
|
function diffSystemLogContents(oldContent, newContent, lineSeparator = '\n', lastLineIndex = -2) {
|
|
75
102
|
const oldLines = oldContent.split(lineSeparator);
|
|
@@ -91,16 +118,26 @@ function diffSystemLogContents(oldContent, newContent, lineSeparator = '\n', las
|
|
|
91
118
|
}
|
|
92
119
|
exports.diffSystemLogContents = diffSystemLogContents;
|
|
93
120
|
/**
|
|
94
|
-
* Converts a `MotionMasterMessage`
|
|
121
|
+
* Converts a `MotionMasterMessage` instance into a plain JavaScript object with full defaults
|
|
122
|
+
* and JSON-compatible values.
|
|
123
|
+
*
|
|
124
|
+
* The conversion uses `MotionMasterMessage.toObject` with options that:
|
|
125
|
+
* - Convert bytes fields to standard arrays.
|
|
126
|
+
* - Include default values for missing fields.
|
|
127
|
+
* - Initialize empty arrays for repeated fields and empty objects for map fields.
|
|
128
|
+
* - Include virtual `oneof` properties indicating which field is set.
|
|
129
|
+
* - Apply JSON-compatible conversions (e.g., NaN and Infinity to strings).
|
|
95
130
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* such as handling arrays, default values, and JSON compatibility.
|
|
131
|
+
* @param motionMasterMessage - The `MotionMasterMessage` instance to convert.
|
|
132
|
+
* @returns A plain object representation of the message with all fields populated and JSON-safe.
|
|
99
133
|
*
|
|
100
|
-
*
|
|
134
|
+
* @example
|
|
135
|
+
* const plainObject = createPlainObjectFromMotionMasterMessage(message);
|
|
136
|
+
* console.log(plainObject.status); // → fully populated status object
|
|
101
137
|
*
|
|
102
|
-
* @
|
|
103
|
-
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* - Useful for logging, serialization, or transferring messages over standard JSON APIs.
|
|
140
|
+
* - Ensures that all optional, repeated, and map fields are represented in the resulting object.
|
|
104
141
|
*/
|
|
105
142
|
function createPlainObjectFromMotionMasterMessage(motionMasterMessage) {
|
|
106
143
|
return types_1.MotionMasterMessage.toObject(motionMasterMessage, {
|
|
@@ -114,16 +151,27 @@ function createPlainObjectFromMotionMasterMessage(motionMasterMessage) {
|
|
|
114
151
|
}
|
|
115
152
|
exports.createPlainObjectFromMotionMasterMessage = createPlainObjectFromMotionMasterMessage;
|
|
116
153
|
/**
|
|
117
|
-
* Converts a `
|
|
154
|
+
* Converts a `IMotionMasterMessage` into a structured context object suitable for logging.
|
|
155
|
+
*
|
|
156
|
+
* The resulting object includes:
|
|
157
|
+
* - `namespace`: a string identifying the logging context (default: `'reqResMessage'`),
|
|
158
|
+
* - `motionMasterMessage`: the original message,
|
|
159
|
+
* - `type`: either `'request'` or `'status'` depending on the message content,
|
|
160
|
+
* - `name`: a comma-separated string of the keys in the request or status object.
|
|
118
161
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
162
|
+
* @param motionMasterMessage - The Motion Master message to convert.
|
|
163
|
+
* @param namespace - Optional namespace for the logging context (default is `'reqResMessage'`).
|
|
164
|
+
* @returns An object containing the logging context with type, name, namespace, and original message.
|
|
122
165
|
*
|
|
123
|
-
* @
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
166
|
+
* @example
|
|
167
|
+
* const context = convertMotionMasterMessageToLoggerContext(message, 'motion');
|
|
168
|
+
* console.log(context.namespace); // → 'motion'
|
|
169
|
+
* console.log(context.type); // → 'request' or 'status'
|
|
170
|
+
* console.log(context.name); // → comma-separated keys of the message content
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* - Determines type by checking the presence of `request` or `status` in the message.
|
|
174
|
+
* - Useful for structured logging or telemetry where message metadata is required.
|
|
127
175
|
*/
|
|
128
176
|
function convertMotionMasterMessageToLoggerContext(motionMasterMessage, namespace = 'reqResMessage') {
|
|
129
177
|
let type = '';
|
|
@@ -140,13 +188,18 @@ function convertMotionMasterMessageToLoggerContext(motionMasterMessage, namespac
|
|
|
140
188
|
}
|
|
141
189
|
exports.convertMotionMasterMessageToLoggerContext = convertMotionMasterMessageToLoggerContext;
|
|
142
190
|
/**
|
|
143
|
-
* Decodes a `Uint8Array` of
|
|
191
|
+
* Decodes a `Uint8Array` of bytes into a string using UTF-8 encoding.
|
|
192
|
+
*
|
|
193
|
+
* @param content - The byte array to decode.
|
|
194
|
+
* @returns The decoded string representation of the input bytes.
|
|
144
195
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
196
|
+
* @example
|
|
197
|
+
* const bytes = new Uint8Array([72, 101, 108, 108, 111]);
|
|
198
|
+
* const text = decodeTextContent(bytes); // → "Hello"
|
|
147
199
|
*
|
|
148
|
-
* @
|
|
149
|
-
*
|
|
200
|
+
* @remarks
|
|
201
|
+
* - Uses the standard `TextDecoder` API with UTF-8 encoding.
|
|
202
|
+
* - Creates a copy of the input array before decoding, so the original `Uint8Array` is not modified.
|
|
150
203
|
*/
|
|
151
204
|
function decodeTextContent(content) {
|
|
152
205
|
const decoder = new TextDecoder();
|
|
@@ -155,14 +208,20 @@ function decodeTextContent(content) {
|
|
|
155
208
|
}
|
|
156
209
|
exports.decodeTextContent = decodeTextContent;
|
|
157
210
|
/**
|
|
158
|
-
*
|
|
211
|
+
* Returns a promise that resolves with the specified value after a given delay.
|
|
159
212
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
213
|
+
* @typeParam T - The type of the value to resolve.
|
|
214
|
+
* @param ms - The delay in milliseconds before the promise resolves.
|
|
215
|
+
* @param value - Optional value to resolve the promise with (defaults to `undefined` if not provided).
|
|
216
|
+
* @returns A `Promise` that resolves to `value` after `ms` milliseconds.
|
|
162
217
|
*
|
|
163
|
-
* @
|
|
164
|
-
*
|
|
165
|
-
*
|
|
218
|
+
* @example
|
|
219
|
+
* await resolveAfter(1000, 'hello'); // resolves with 'hello' after 1 second
|
|
220
|
+
* await resolveAfter(500); // resolves with undefined after 0.5 seconds
|
|
221
|
+
*
|
|
222
|
+
* @remarks
|
|
223
|
+
* - Useful for simulating delays or asynchronous timing in tests or animations.
|
|
224
|
+
* - The function does not reject; it always resolves after the specified timeout.
|
|
166
225
|
*/
|
|
167
226
|
function resolveAfter(ms, value) {
|
|
168
227
|
return new Promise(function (resolve) {
|
|
@@ -171,14 +230,23 @@ function resolveAfter(ms, value) {
|
|
|
171
230
|
}
|
|
172
231
|
exports.resolveAfter = resolveAfter;
|
|
173
232
|
/**
|
|
174
|
-
* Converts a 24-bit RGB color value
|
|
233
|
+
* Converts a standard 24-bit RGB color value into a format suitable for certain LED controllers.
|
|
234
|
+
*
|
|
235
|
+
* The conversion swaps the red and green channels, producing a new 24-bit integer where:
|
|
236
|
+
* - Original green becomes the most significant byte,
|
|
237
|
+
* - Original red becomes the middle byte,
|
|
238
|
+
* - Original blue remains the least significant byte.
|
|
239
|
+
*
|
|
240
|
+
* @param value - A 24-bit RGB color represented as a number (0xRRGGBB).
|
|
241
|
+
* @returns The converted 24-bit LED color value with swapped red and green channels.
|
|
175
242
|
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
243
|
+
* @example
|
|
244
|
+
* const rgb = 0x112233;
|
|
245
|
+
* const ledColor = convertRgbToLedColor(rgb); // → 0x221133
|
|
179
246
|
*
|
|
180
|
-
* @
|
|
181
|
-
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* - Useful when interfacing with LED hardware that expects a different channel ordering.
|
|
249
|
+
* - Input and output are standard JavaScript numbers representing 24-bit colors.
|
|
182
250
|
*/
|
|
183
251
|
function convertRgbToLedColor(value) {
|
|
184
252
|
const r = (value >> 16) & 0xff;
|
|
@@ -189,16 +257,19 @@ function convertRgbToLedColor(value) {
|
|
|
189
257
|
}
|
|
190
258
|
exports.convertRgbToLedColor = convertRgbToLedColor;
|
|
191
259
|
/**
|
|
192
|
-
* Generates a random
|
|
260
|
+
* Generates a random hexadecimal color string with a specified minimum brightness.
|
|
193
261
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* limiting the possible range for each channel.
|
|
262
|
+
* @param brightness - Minimum value for each RGB channel (0–255). Higher values produce lighter colors.
|
|
263
|
+
* @returns A random color string in `#RRGGBB` format.
|
|
197
264
|
*
|
|
198
|
-
* @
|
|
199
|
-
*
|
|
265
|
+
* @example
|
|
266
|
+
* createRandomColor(100); // → '#c48f7a' (example output)
|
|
267
|
+
* createRandomColor(200); // → '#e5f0ff' (example output)
|
|
200
268
|
*
|
|
201
|
-
* @
|
|
269
|
+
* @remarks
|
|
270
|
+
* - Each color channel (red, green, blue) is independently randomized between `brightness` and 255.
|
|
271
|
+
* - Ensures that no channel is darker than the specified brightness.
|
|
272
|
+
* - Useful for generating visually distinct colors while avoiding very dark shades.
|
|
202
273
|
*/
|
|
203
274
|
function createRandomColor(brightness) {
|
|
204
275
|
function randomChannel(brightness) {
|
|
@@ -211,17 +282,22 @@ function createRandomColor(brightness) {
|
|
|
211
282
|
}
|
|
212
283
|
exports.createRandomColor = createRandomColor;
|
|
213
284
|
/**
|
|
214
|
-
*
|
|
285
|
+
* Finds the first key in a `Map` that corresponds to the specified value.
|
|
215
286
|
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
287
|
+
* @typeParam K - The type of keys in the map.
|
|
288
|
+
* @typeParam V - The type of values in the map.
|
|
289
|
+
* @param map - The map to search.
|
|
290
|
+
* @param searchValue - The value to find the corresponding key for.
|
|
291
|
+
* @returns The first key whose value strictly equals (`===`) the searchValue, or `undefined` if no match is found.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* const myMap = new Map<string, number>([['a', 1], ['b', 2], ['c', 1]]);
|
|
295
|
+
* getMapKeyByValue(myMap, 1); // → 'a'
|
|
296
|
+
* getMapKeyByValue(myMap, 3); // → undefined
|
|
219
297
|
*
|
|
220
|
-
* @
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* @param {V} searchValue - The value to find the corresponding key for.
|
|
224
|
-
* @returns {K | undefined} The key associated with the given value, or `undefined` if not found.
|
|
298
|
+
* @remarks
|
|
299
|
+
* - Only the first matching key is returned; subsequent keys with the same value are ignored.
|
|
300
|
+
* - Comparison uses strict equality (`===`).
|
|
225
301
|
*/
|
|
226
302
|
function getMapKeyByValue(map, searchValue) {
|
|
227
303
|
for (let [key, value] of map.entries()) {
|
|
@@ -233,14 +309,20 @@ function getMapKeyByValue(map, searchValue) {
|
|
|
233
309
|
}
|
|
234
310
|
exports.getMapKeyByValue = getMapKeyByValue;
|
|
235
311
|
/**
|
|
236
|
-
*
|
|
312
|
+
* Identifies duplicate elements in an array and returns them as a new array.
|
|
237
313
|
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
314
|
+
* @typeParam T - The type of elements in the array.
|
|
315
|
+
* @param arr - The array to check for duplicate values.
|
|
316
|
+
* @returns An array containing all elements that appear more than once in the input array.
|
|
317
|
+
* Each duplicate element appears only once in the returned array, regardless of how many times it occurs.
|
|
240
318
|
*
|
|
241
|
-
* @
|
|
242
|
-
*
|
|
243
|
-
*
|
|
319
|
+
* @example
|
|
320
|
+
* findDuplicates([1, 2, 3, 2, 4, 3, 5]); // → [2, 3]
|
|
321
|
+
* findDuplicates(['a', 'b', 'a', 'c']); // → ['a']
|
|
322
|
+
*
|
|
323
|
+
* @remarks
|
|
324
|
+
* - Uses `Set` internally for efficient duplicate detection.
|
|
325
|
+
* - Preserves the insertion order of first detected duplicates.
|
|
244
326
|
*/
|
|
245
327
|
function findDuplicates(arr) {
|
|
246
328
|
const uniqueElements = new Set();
|
|
@@ -257,89 +339,136 @@ function findDuplicates(arr) {
|
|
|
257
339
|
}
|
|
258
340
|
exports.findDuplicates = findDuplicates;
|
|
259
341
|
/**
|
|
260
|
-
* Converts a camelCase string into a space-separated lowercase string.
|
|
342
|
+
* Converts a camelCase or PascalCase string into a space-separated, lowercase string.
|
|
261
343
|
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
344
|
+
* @param str - The input string in camelCase or PascalCase format.
|
|
345
|
+
* @returns A new string where each uppercase letter is preceded by a space and all letters are lowercase.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* camelCaseToWords('camelCaseString'); // → 'camel case string'
|
|
349
|
+
* camelCaseToWords('PascalCase'); // → 'pascal case'
|
|
264
350
|
*
|
|
265
|
-
* @
|
|
266
|
-
*
|
|
351
|
+
* @remarks
|
|
352
|
+
* - Useful for converting identifiers into human-readable words.
|
|
353
|
+
* - Leading spaces are preserved if the string starts with an uppercase letter.
|
|
267
354
|
*/
|
|
268
355
|
function camelCaseToWords(str) {
|
|
269
356
|
return str.replace(/([A-Z])/g, ' $1').toLowerCase();
|
|
270
357
|
}
|
|
271
358
|
exports.camelCaseToWords = camelCaseToWords;
|
|
272
359
|
/**
|
|
273
|
-
*
|
|
360
|
+
* Clears (sets to 0) the bit at the specified position in a number.
|
|
274
361
|
*
|
|
275
|
-
* @param
|
|
276
|
-
* @param
|
|
277
|
-
* @returns
|
|
362
|
+
* @param value - The original number whose bit is to be cleared.
|
|
363
|
+
* @param position - Zero-based bit position to clear (0 = least-significant bit).
|
|
364
|
+
* @returns A new number with the bit at the specified position cleared to 0.
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* setBitLow(0b1011, 1); // → 0b1001 (clears bit 1)
|
|
368
|
+
* setBitLow(0b1111, 3); // → 0b0111 (clears bit 3)
|
|
369
|
+
*
|
|
370
|
+
* @remarks
|
|
371
|
+
* - Only the bit at the given position is affected; all other bits remain unchanged.
|
|
372
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
278
373
|
*/
|
|
279
374
|
function setBitLow(value, position) {
|
|
280
375
|
return value & ~(1 << position);
|
|
281
376
|
}
|
|
282
377
|
exports.setBitLow = setBitLow;
|
|
283
378
|
/**
|
|
284
|
-
* Sets the
|
|
379
|
+
* Sets (changes to 1) the bit at the specified position in a number.
|
|
380
|
+
*
|
|
381
|
+
* @param value - The original number whose bit is to be set.
|
|
382
|
+
* @param position - Zero-based bit position to set (0 = least-significant bit).
|
|
383
|
+
* @returns A new number with the bit at the specified position set to 1.
|
|
285
384
|
*
|
|
286
|
-
* @
|
|
287
|
-
*
|
|
288
|
-
*
|
|
385
|
+
* @example
|
|
386
|
+
* setBitHigh(0b1001, 1); // → 0b1011 (sets bit 1)
|
|
387
|
+
* setBitHigh(0b0111, 3); // → 0b1111 (sets bit 3)
|
|
388
|
+
*
|
|
389
|
+
* @remarks
|
|
390
|
+
* - Only the bit at the given position is affected; all other bits remain unchanged.
|
|
391
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
289
392
|
*/
|
|
290
393
|
function setBitHigh(value, position) {
|
|
291
394
|
return value | (1 << position);
|
|
292
395
|
}
|
|
293
396
|
exports.setBitHigh = setBitHigh;
|
|
294
397
|
/**
|
|
295
|
-
*
|
|
398
|
+
* Retrieves the value of the bit at the specified position in a number.
|
|
296
399
|
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
400
|
+
* @param n - The number from which to retrieve the bit.
|
|
401
|
+
* @param k - Zero-based bit position to retrieve (0 = least-significant bit).
|
|
402
|
+
* @returns `1` if the bit at position `k` is set, otherwise `0`.
|
|
299
403
|
*
|
|
300
|
-
* @
|
|
301
|
-
*
|
|
302
|
-
*
|
|
404
|
+
* @example
|
|
405
|
+
* getBit(0b1010, 1); // → 1 (bit 1 is set)
|
|
406
|
+
* getBit(0b1010, 0); // → 0 (bit 0 is clear)
|
|
407
|
+
*
|
|
408
|
+
* @remarks
|
|
409
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
410
|
+
* - Does not modify the original number.
|
|
303
411
|
*/
|
|
304
412
|
function getBit(n, k) {
|
|
305
413
|
return (n & (1 << k)) === 0 ? 0 : 1;
|
|
306
414
|
}
|
|
307
415
|
exports.getBit = getBit;
|
|
308
416
|
/**
|
|
309
|
-
* Checks
|
|
417
|
+
* Checks whether the bit at the specified position in a number is set (1).
|
|
418
|
+
*
|
|
419
|
+
* @param n - The number to check.
|
|
420
|
+
* @param k - Zero-based bit position to check (0 = least-significant bit).
|
|
421
|
+
* @returns `true` if the bit at position `k` is 1, otherwise `false`.
|
|
310
422
|
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
423
|
+
* @example
|
|
424
|
+
* isBitOn(0b1010, 1); // → true (bit 1 is set)
|
|
425
|
+
* isBitOn(0b1010, 0); // → false (bit 0 is clear)
|
|
313
426
|
*
|
|
314
|
-
* @
|
|
315
|
-
*
|
|
316
|
-
*
|
|
427
|
+
* @remarks
|
|
428
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
429
|
+
* - Does not modify the original number.
|
|
317
430
|
*/
|
|
318
431
|
function isBitOn(n, k) {
|
|
319
432
|
return (n & (1 << k)) > 0;
|
|
320
433
|
}
|
|
321
434
|
exports.isBitOn = isBitOn;
|
|
322
435
|
/**
|
|
323
|
-
* Sets the bit at the specified position
|
|
436
|
+
* Sets (changes to 1) the bit at the specified position in a number.
|
|
437
|
+
*
|
|
438
|
+
* The original number is not mutated; a new number is returned with the bit set.
|
|
324
439
|
*
|
|
325
|
-
*
|
|
440
|
+
* @param n - The original number whose bit is to be set.
|
|
441
|
+
* @param k - Zero-based bit position to set (0 = least-significant bit).
|
|
442
|
+
* @returns A new number equal to `n` with bit `k` set.
|
|
326
443
|
*
|
|
327
|
-
* @
|
|
328
|
-
*
|
|
329
|
-
*
|
|
444
|
+
* @example
|
|
445
|
+
* setBit(0b1001, 1); // → 0b1011 (sets bit 1)
|
|
446
|
+
* setBit(0b0111, 3); // → 0b1111 (sets bit 3)
|
|
447
|
+
*
|
|
448
|
+
* @remarks
|
|
449
|
+
* - Only the bit at position `k` is affected; all other bits remain unchanged.
|
|
450
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
330
451
|
*/
|
|
331
452
|
function setBit(n, k) {
|
|
332
453
|
return n | (1 << k);
|
|
333
454
|
}
|
|
334
455
|
exports.setBit = setBit;
|
|
335
456
|
/**
|
|
336
|
-
* Clears the bit at the specified position
|
|
457
|
+
* Clears (sets to 0) the bit at the specified position in a number.
|
|
337
458
|
*
|
|
338
|
-
*
|
|
459
|
+
* The original number is not mutated; a new number is returned with the bit cleared.
|
|
339
460
|
*
|
|
340
|
-
* @param
|
|
341
|
-
* @param
|
|
342
|
-
* @returns
|
|
461
|
+
* @param n - The original number whose bit is to be cleared.
|
|
462
|
+
* @param k - Zero-based bit position to clear (0 = least-significant bit).
|
|
463
|
+
* @returns A new number equal to `n` with bit `k` cleared.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* clearBit(0b1011, 1); // → 0b1001 (clears bit 1)
|
|
467
|
+
* clearBit(0b1111, 3); // → 0b0111 (clears bit 3)
|
|
468
|
+
*
|
|
469
|
+
* @remarks
|
|
470
|
+
* - Only the bit at position `k` is affected; all other bits remain unchanged.
|
|
471
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
343
472
|
*/
|
|
344
473
|
function clearBit(n, k) {
|
|
345
474
|
const mask = ~(1 << k);
|
|
@@ -347,15 +476,23 @@ function clearBit(n, k) {
|
|
|
347
476
|
}
|
|
348
477
|
exports.clearBit = clearBit;
|
|
349
478
|
/**
|
|
350
|
-
* Updates the bit at the
|
|
479
|
+
* Updates the bit at position `k` in the given number `n` to the specified value.
|
|
480
|
+
*
|
|
481
|
+
* The original number is not mutated; instead, a new number is returned with the bit updated.
|
|
351
482
|
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
483
|
+
* @param n - The original number whose bit is being modified.
|
|
484
|
+
* @param k - Zero-based bit position to update (0 = least-significant bit).
|
|
485
|
+
* @param value - Boolean or numeric value indicating whether the bit should be set (`true` / `1`)
|
|
486
|
+
* or cleared (`false` / `0`).
|
|
487
|
+
* @returns A new number equal to `n` with bit `k` updated.
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* updateBit(0b1010, 1, true); // → 0b1011 (set bit 1)
|
|
491
|
+
* updateBit(0b1011, 3, false); // → 0b0011 (clear bit 3)
|
|
354
492
|
*
|
|
355
|
-
* @
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
* @returns {number} The new number with the bit at position `k` updated.
|
|
493
|
+
* @remarks
|
|
494
|
+
* - Values other than `0` or `false` result in bit being set to `1`.
|
|
495
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
359
496
|
*/
|
|
360
497
|
function updateBit(n, k, value) {
|
|
361
498
|
const normalizedValue = value ? 1 : 0;
|
|
@@ -394,15 +531,20 @@ function toFixedFormat(x, n = 6, rightTrimZero = true) {
|
|
|
394
531
|
}
|
|
395
532
|
exports.toFixedFormat = toFixedFormat;
|
|
396
533
|
/**
|
|
397
|
-
* Converts a `Blob` into a Base64-encoded string.
|
|
534
|
+
* Converts a `Blob` object into a Base64-encoded string.
|
|
398
535
|
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
536
|
+
* @param blob - The `Blob` to convert.
|
|
537
|
+
* @returns A `Promise` that resolves to the Base64 string representation of the blob.
|
|
401
538
|
*
|
|
402
|
-
* @
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
539
|
+
* @example
|
|
540
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
541
|
+
* const base64 = await convertBlobToBase64(blob);
|
|
542
|
+
* console.log(base64); // → 'SGVsbG8sIHdvcmxkIQ=='
|
|
543
|
+
*
|
|
544
|
+
* @remarks
|
|
545
|
+
* - Internally uses `FileReader.readAsDataURL` to serialize the blob.
|
|
546
|
+
* - The returned Base64 string excludes the data URL prefix (e.g., `data:text/plain;base64,`).
|
|
547
|
+
* - The promise is rejected if the blob cannot be read.
|
|
406
548
|
*/
|
|
407
549
|
function convertBlobToBase64(blob) {
|
|
408
550
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -483,12 +625,17 @@ exports.isElectronContext = isElectronContext;
|
|
|
483
625
|
*
|
|
484
626
|
* The function uses bitwise operations to isolate each byte from the 32-bit integer.
|
|
485
627
|
*
|
|
486
|
-
* @param
|
|
487
|
-
* @returns
|
|
628
|
+
* @param value - The 32-bit integer to be parsed.
|
|
629
|
+
* @returns An object containing the extracted components:
|
|
488
630
|
* - `prefix`: The extracted prefix byte (8 bits).
|
|
489
631
|
* - `numerator`: The extracted numerator byte (8 bits).
|
|
490
632
|
* - `denominator`: The extracted denominator byte (8 bits).
|
|
491
633
|
* - `reserved`: The extracted reserved byte (8 bits).
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* const parsed = parseUnitValue(0x12345678);
|
|
637
|
+
* console.log(parsed);
|
|
638
|
+
* // → { prefix: 0x12, numerator: 0x34, denominator: 0x56, reserved: 0x78 }
|
|
492
639
|
*/
|
|
493
640
|
function parseUnitValue(value) {
|
|
494
641
|
// Convert a value to a 32-bit signed integer using bitwise OR
|
|
@@ -505,11 +652,18 @@ exports.parseUnitValue = parseUnitValue;
|
|
|
505
652
|
/**
|
|
506
653
|
* Merges multiple `Uint8Array` instances into a single `Uint8Array`.
|
|
507
654
|
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
655
|
+
* @param ary - One or more `Uint8Array` instances to merge.
|
|
656
|
+
* @returns A new `Uint8Array` containing all elements from the input arrays in order.
|
|
510
657
|
*
|
|
511
|
-
* @
|
|
512
|
-
*
|
|
658
|
+
* @example
|
|
659
|
+
* const a = new Uint8Array([1, 2]);
|
|
660
|
+
* const b = new Uint8Array([3, 4]);
|
|
661
|
+
* const merged = mergeUint8Arrays(a, b); // → Uint8Array [1, 2, 3, 4]
|
|
662
|
+
*
|
|
663
|
+
* @remarks
|
|
664
|
+
* - Preserves the order of elements from each input array.
|
|
665
|
+
* - Efficiently concatenates arrays without creating intermediate arrays for each element.
|
|
666
|
+
* - Returns a new `Uint8Array`; the input arrays are not modified.
|
|
513
667
|
*/
|
|
514
668
|
function mergeUint8Arrays(...ary) {
|
|
515
669
|
const elements = ary.map((v) => v.length).reduce((a, b) => a + b, 0);
|
|
@@ -523,13 +677,19 @@ function mergeUint8Arrays(...ary) {
|
|
|
523
677
|
}
|
|
524
678
|
exports.mergeUint8Arrays = mergeUint8Arrays;
|
|
525
679
|
/**
|
|
526
|
-
* Returns
|
|
680
|
+
* Returns a new array containing only the unique elements from the input array, preserving their order.
|
|
527
681
|
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
682
|
+
* @typeParam T - The type of elements in the array.
|
|
683
|
+
* @param items - The array from which to remove duplicates.
|
|
684
|
+
* @returns A new array with duplicate elements removed.
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* uniqueItems([1, 2, 2, 3, 1]); // → [1, 2, 3]
|
|
688
|
+
* uniqueItems(['a', 'b', 'a']); // → ['a', 'b']
|
|
530
689
|
*
|
|
531
|
-
* @
|
|
532
|
-
*
|
|
690
|
+
* @remarks
|
|
691
|
+
* - Uses a `Set` internally for efficient duplicate removal.
|
|
692
|
+
* - Original array is not modified.
|
|
533
693
|
*/
|
|
534
694
|
function uniqueItems(items) {
|
|
535
695
|
return [...new Set(items)];
|
|
@@ -804,35 +964,6 @@ function fromQ(rawValue, qFractionalBits = 15, round = false) {
|
|
|
804
964
|
return round ? Math.round(value) : value;
|
|
805
965
|
}
|
|
806
966
|
exports.fromQ = fromQ;
|
|
807
|
-
/**
|
|
808
|
-
* Custom RxJS operator that accumulates notifications with their
|
|
809
|
-
* elapsed time relative to a provided start time.
|
|
810
|
-
*
|
|
811
|
-
* Each emitted notification string is converted into a `NotificationEntry`
|
|
812
|
-
* object, and the operator maintains an array of all previous entries.
|
|
813
|
-
*
|
|
814
|
-
* @param startTime - The timestamp (in milliseconds) to use as the reference
|
|
815
|
-
* point for calculating elapsed time. Typically obtained via `performance.now()`.
|
|
816
|
-
* @returns An OperatorFunction that transforms an Observable of strings into
|
|
817
|
-
* an Observable of `NotificationEntry[]`.
|
|
818
|
-
*
|
|
819
|
-
* @example
|
|
820
|
-
* ```ts
|
|
821
|
-
* const startTime = performance.now();
|
|
822
|
-
* notifications$.pipe(withTimeDifference(startTime)).subscribe(entries => {
|
|
823
|
-
* console.log(entries); // Array of NotificationEntry objects with elapsed time
|
|
824
|
-
* });
|
|
825
|
-
* ```
|
|
826
|
-
*/
|
|
827
|
-
function withTimeDifference(startTime) {
|
|
828
|
-
return (source) => source.pipe((0, rxjs_1.scan)((acc, message) => {
|
|
829
|
-
const endTime = performance.now();
|
|
830
|
-
const timeDifference = endTime - startTime;
|
|
831
|
-
acc.push({ message, timeDifference });
|
|
832
|
-
return acc;
|
|
833
|
-
}, []));
|
|
834
|
-
}
|
|
835
|
-
exports.withTimeDifference = withTimeDifference;
|
|
836
967
|
/**
|
|
837
968
|
* Analyzes an array of measured time durations and returns useful statistics
|
|
838
969
|
* both for the full dataset and for outlier-filtered data.
|