motion-master-client 0.0.339 → 0.0.341

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/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.withTimeDifference = 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;
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
- * This function uses a regular expression to extract key parts of a log line: the timestamp, uptime, ID,
11
- * file, log level, and message. If the line matches the expected format, it returns an object with these
12
- * extracted properties. If the line doesn't match the format, it returns `undefined`.
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
- * **Note:** The regular expression uses the `s` flag (dot-all mode), which may not be supported in all browsers.
15
- * This is suppressed with `@ts-ignore`.
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
- * @param {string} line - A single log line to parse.
18
- * @returns {SystemLogLine | undefined} A `SystemLogLine` object with the parsed data, or `undefined` if the line doesn't match the expected format.
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 the content of a system log into an array of `SystemLogLine` objects.
50
+ * Parses a system log string into an array of structured `SystemLogLine` objects.
40
51
  *
41
- * This function uses a regular expression to split the log content into individual log lines. It then parses
42
- * each log line into a structured `SystemLogLine` object. The function also filters out any empty lines
43
- * and ensures only valid `SystemLogLine` objects are returned.
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
- * **Note:** The regular expression uses the `s` flag, which may not be supported in all browsers. This is suppressed
46
- * with `@ts-ignore` to allow the use of dot-all mode in the regex.
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
- * @param {string} content - The raw system log content to parse.
49
- * @returns {SystemLogLine[]} An array of `SystemLogLine` objects parsed from the log content.
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
- * Differs two system log contents and returns the new content after the last matching line.
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
- * This function compares two log contents, `oldContent` and `newContent`, and returns the portion of
65
- * the `newContent` that appears after the last matching line in the `oldContent`. It splits the content
66
- * based on the provided `lineSeparator` and uses the `lastLineIndex` to find the line to compare.
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
- * @param {string} oldContent - The original system log content to compare against.
69
- * @param {string} newContent - The new system log content to find the difference from the old content.
70
- * @param {string} [lineSeparator='\n'] - The character(s) used to separate lines in the content (default is newline).
71
- * @param {number} [lastLineIndex=-2] - The index of the last line to compare, negative index can be used (default is -2, the second-to-last line).
72
- * @returns {string} The portion of `newContent` after the last matching line in `oldContent`. If no match is found, returns the entire `newContent`.
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` to a plain JavaScript object with specific field handling options.
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
- * This function utilizes the `MotionMasterMessage.toObject()` method to create a plain object
97
- * from the provided `MotionMasterMessage`. It includes various options for how fields are processed,
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
- * **Note:** The function includes a fix for the error `TypeError: Cannot freeze array buffer views with elements in NgRx`.
134
+ * @example
135
+ * const plainObject = createPlainObjectFromMotionMasterMessage(message);
136
+ * console.log(plainObject.status); // → fully populated status object
101
137
  *
102
- * @param {MotionMasterMessage} motionMasterMessage - The `MotionMasterMessage` instance to convert.
103
- * @returns {object} A plain JavaScript object representing the message with the specified options applied.
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 `motionMasterMessage` into a logger context object.
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
- * This function extracts relevant details from the provided `motionMasterMessage` and
120
- * constructs an object to be used as context in logging. It determines whether the message
121
- * is a request or status type and stores the associated keys from the respective properties.
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
- * @param {IMotionMasterMessage} motionMasterMessage - The message to convert into a logger context.
124
- * @param {string} [namespace='reqResMessage'] - The namespace to associate with the context (default is 'reqResMessage').
125
- * @returns {object} An object containing the `namespace`, the original `motionMasterMessage`, the `type` of message
126
- * (either 'request' or 'status'), and the `name` (a string of keys from the request or status).
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 text content into a string.
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
- * This function uses the `TextDecoder` API to decode the given `Uint8Array` (representing
146
- * text encoded in a specific encoding, such as UTF-8) into a readable string.
196
+ * @example
197
+ * const bytes = new Uint8Array([72, 101, 108, 108, 111]);
198
+ * const text = decodeTextContent(bytes); // → "Hello"
147
199
  *
148
- * @param {Uint8Array} content - The `Uint8Array` containing the encoded text.
149
- * @returns {string} The decoded string.
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
- * Resolves a promise after a specified delay.
211
+ * Returns a promise that resolves with the specified value after a given delay.
159
212
  *
160
- * This function returns a promise that resolves after the given number of milliseconds (`ms`),
161
- * optionally resolving with a provided value.
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
- * @param {number} ms - The number of milliseconds to wait before resolving the promise.
164
- * @param {unknown} [value] - The value to resolve with once the delay has passed. Default is `undefined`.
165
- * @returns {Promise<unknown>} A promise that resolves with the specified value after the delay.
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 to a format used by LED controllers.
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
- * This function takes an RGB color value (represented as a single 24-bit number)
177
- * and rearranges the color channels to match a typical LED color format, which may
178
- * require swapping the red and green channels.
243
+ * @example
244
+ * const rgb = 0x112233;
245
+ * const ledColor = convertRgbToLedColor(rgb); // 0x221133
179
246
  *
180
- * @param {number} value - A 24-bit integer representing the RGB color value (0xRRGGBB).
181
- * @returns {number} A new integer representing the color in the LED format (0xGRB).
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 hex color code with a specified brightness.
260
+ * Generates a random hexadecimal color string with a specified minimum brightness.
193
261
  *
194
- * This function creates a random color by generating random values for the red, green, and blue
195
- * color channels. The brightness parameter ensures the generated color is not too dark by
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
- * @param {number} brightness - The minimum brightness of the generated color. Should be between 0 and 255.
199
- * @returns {string} A random hex color code, in the form of `#RRGGBB`.
265
+ * @example
266
+ * createRandomColor(100); // '#c48f7a' (example output)
267
+ * createRandomColor(200); // → '#e5f0ff' (example output)
200
268
  *
201
- * @throws {Error} Throws an error if the brightness is not between 0 and 255.
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
- * Retrieves the first key from a `Map` that matches a given value.
285
+ * Finds the first key in a `Map` that corresponds to the specified value.
215
286
  *
216
- * This function iterates over the entries of the map and returns the first key
217
- * whose corresponding value strictly equals (`===`) the provided `searchValue`.
218
- * If no matching value is found, it returns `undefined`.
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
- * @template K - The type of the map's keys.
221
- * @template V - The type of the map's values.
222
- * @param {Map<K, V>} map - The map to search through.
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
- * Finds and returns the duplicate elements in an array.
312
+ * Identifies duplicate elements in an array and returns them as a new array.
237
313
  *
238
- * This function iterates through the array and identifies elements that appear more than once.
239
- * It preserves only one instance of each duplicate in the output.
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
- * @template T - The type of elements in the array.
242
- * @param {T[]} arr - The input array to search for duplicates.
243
- * @returns {T[]} An array of the duplicate elements, without repetition.
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
- * This function inserts spaces before each uppercase letter in the string (except the first one)
263
- * and converts the entire string to lowercase.
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
- * @param {string} str - The camelCase string to convert.
266
- * @returns {string} A space-separated, lowercase version of the input string.
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
- * Sets the specified bit in the given number to 0.
360
+ * Clears (sets to 0) the bit at the specified position in a number.
274
361
  *
275
- * @param {number} value - The original number whose bit will be modified.
276
- * @param {number} position - The position of the bit to set to 0 (0-based index).
277
- * @returns {number} The modified number with the specified bit set to 0.
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 specified bit in the given number to 1.
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
- * @param {number} value - The original number whose bit will be modified.
287
- * @param {number} position - The position of the bit to set to 1 (0-based index).
288
- * @returns {number} The modified number with the specified bit set to 1.
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
- * Returns the bit at the specified position in a number.
398
+ * Retrieves the value of the bit at the specified position in a number.
296
399
  *
297
- * This function performs a bitwise AND operation to isolate the bit at the `k`th position.
298
- * If the bit is 0, it returns `0`; otherwise, it returns `1`.
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
- * @param {number} n - The number whose bit will be retrieved.
301
- * @param {number} k - The position of the bit to retrieve (0-indexed).
302
- * @returns {number} The bit at position `k` (either 0 or 1).
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 if the bit at the specified position is on (1).
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
- * This function performs a bitwise AND operation to check if the bit at the `k`th position is set to `1`.
312
- * It returns `true` if the bit is set, otherwise `false`.
423
+ * @example
424
+ * isBitOn(0b1010, 1); // true (bit 1 is set)
425
+ * isBitOn(0b1010, 0); // → false (bit 0 is clear)
313
426
  *
314
- * @param {number} n - The number to check.
315
- * @param {number} k - The position of the bit to check (0-indexed).
316
- * @returns {boolean} `true` if the bit is on (1), otherwise `false`.
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 to 1.
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
- * This function performs a bitwise OR operation to ensure that the bit at the `k`th position is set to `1`.
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
- * @param {number} n - The number in which the bit will be set.
328
- * @param {number} k - The position of the bit to set (0-indexed).
329
- * @returns {number} The new number with the bit at position `k` set to 1.
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 (sets it to 0).
457
+ * Clears (sets to 0) the bit at the specified position in a number.
337
458
  *
338
- * This function performs a bitwise AND operation with a mask to ensure that the bit at the `k`th position is set to `0`.
459
+ * The original number is not mutated; a new number is returned with the bit cleared.
339
460
  *
340
- * @param {number} n - The number in which the bit will be cleared.
341
- * @param {number} k - The position of the bit to clear (0-indexed).
342
- * @returns {number} The new number with the bit at position `k` cleared (set to 0).
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 specified position with the given value.
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
- * This function updates the bit at the `k`th position to either `1` or `0` depending on the provided value.
353
- * If the value is a boolean, it will be normalized to `1` (true) or `0` (false).
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
- * @param {number} n - The number in which the bit will be updated.
356
- * @param {number} k - The position of the bit to update (0-indexed).
357
- * @param {number | boolean} value - The value to set the bit to (1 or 0, or `true`/`false`).
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
- * This function reads the provided `Blob` using `FileReader` and extracts the Base64 content
400
- * from the resulting data URL.
536
+ * @param blob - The `Blob` to convert.
537
+ * @returns A `Promise` that resolves to the Base64 string representation of the blob.
401
538
  *
402
- * @param {Blob} blob - The `Blob` to convert into a Base64 string.
403
- * @returns {Promise<string>} A promise that resolves with the Base64 string representation of the blob.
404
- *
405
- * @throws {string} If the blob cannot be read (e.g., due to an error), the promise rejects with an error message.
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 {number} value - The 32-bit integer to be parsed.
487
- * @returns {Object} An object containing the extracted components:
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
- * This function concatenates all provided `Uint8Array` instances in the order they are given,
509
- * producing a new array containing all their bytes sequentially.
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
- * @param {...Uint8Array[]} ary - An array of `Uint8Array` instances to merge.
512
- * @returns {Uint8Array} A new `Uint8Array` containing the concatenated bytes from all input arrays.
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 an array of unique items by removing duplicates from the given array.
680
+ * Returns a new array containing only the unique elements from the input array, preserving their order.
527
681
  *
528
- * This function utilizes the `Set` object to remove duplicate values, ensuring that only unique items
529
- * remain in the returned array. The order of items in the resulting array is preserved as in the input.
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
- * @param {Array<T>} items - The array from which duplicates will be removed.
532
- * @returns {Array<T>} A new array containing only the unique items from the input array.
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.