motion-master-client 0.0.246 → 0.0.248

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.d.ts CHANGED
@@ -1,23 +1,157 @@
1
1
  import { SystemLogLine } from './system-log-line';
2
2
  import { IMotionMasterMessage, MotionMasterMessage } from './types';
3
+ /**
4
+ * Parses a single line of system log into a structured `SystemLogLine` object.
5
+ *
6
+ * This function uses a regular expression to extract key parts of a log line: the timestamp, uptime, ID,
7
+ * file, log level, and message. If the line matches the expected format, it returns an object with these
8
+ * extracted properties. If the line doesn't match the format, it returns `undefined`.
9
+ *
10
+ * **Note:** The regular expression uses the `s` flag (dot-all mode), which may not be supported in all browsers.
11
+ * This is suppressed with `@ts-ignore`.
12
+ *
13
+ * @param {string} line - A single log line to parse.
14
+ * @returns {SystemLogLine | undefined} A `SystemLogLine` object with the parsed data, or `undefined` if the line doesn't match the expected format.
15
+ */
3
16
  export declare function parseSystemLogLine(line: string): SystemLogLine | undefined;
17
+ /**
18
+ * Parses the content of a system log into an array of `SystemLogLine` objects.
19
+ *
20
+ * This function uses a regular expression to split the log content into individual log lines. It then parses
21
+ * each log line into a structured `SystemLogLine` object. The function also filters out any empty lines
22
+ * and ensures only valid `SystemLogLine` objects are returned.
23
+ *
24
+ * **Note:** The regular expression uses the `s` flag, which may not be supported in all browsers. This is suppressed
25
+ * with `@ts-ignore` to allow the use of dot-all mode in the regex.
26
+ *
27
+ * @param {string} content - The raw system log content to parse.
28
+ * @returns {SystemLogLine[]} An array of `SystemLogLine` objects parsed from the log content.
29
+ */
4
30
  export declare function parseSystemLogContent(content: string): SystemLogLine[];
31
+ /**
32
+ * Differs two system log contents and returns the new content after the last matching line.
33
+ *
34
+ * This function compares two log contents, `oldContent` and `newContent`, and returns the portion of
35
+ * the `newContent` that appears after the last matching line in the `oldContent`. It splits the content
36
+ * based on the provided `lineSeparator` and uses the `lastLineIndex` to find the line to compare.
37
+ *
38
+ * @param {string} oldContent - The original system log content to compare against.
39
+ * @param {string} newContent - The new system log content to find the difference from the old content.
40
+ * @param {string} [lineSeparator='\n'] - The character(s) used to separate lines in the content (default is newline).
41
+ * @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).
42
+ * @returns {string} The portion of `newContent` after the last matching line in `oldContent`. If no match is found, returns the entire `newContent`.
43
+ */
5
44
  export declare function diffSystemLogContents(oldContent: string, newContent: string, lineSeparator?: string, lastLineIndex?: number): string;
6
- export declare function createPlainObjectFromMotionMasterMessage(motionMasterMessage: MotionMasterMessage): {
7
- [k: string]: any;
8
- };
45
+ /**
46
+ * Converts a `MotionMasterMessage` to a plain JavaScript object with specific field handling options.
47
+ *
48
+ * This function utilizes the `MotionMasterMessage.toObject()` method to create a plain object
49
+ * from the provided `MotionMasterMessage`. It includes various options for how fields are processed,
50
+ * such as handling arrays, default values, and JSON compatibility.
51
+ *
52
+ * **Note:** The function includes a fix for the error `TypeError: Cannot freeze array buffer views with elements in NgRx`.
53
+ *
54
+ * @param {MotionMasterMessage} motionMasterMessage - The `MotionMasterMessage` instance to convert.
55
+ * @returns {object} A plain JavaScript object representing the message with the specified options applied.
56
+ */
57
+ export declare function createPlainObjectFromMotionMasterMessage(motionMasterMessage: MotionMasterMessage): IMotionMasterMessage;
58
+ /**
59
+ * Converts a `motionMasterMessage` into a logger context object.
60
+ *
61
+ * This function extracts relevant details from the provided `motionMasterMessage` and
62
+ * constructs an object to be used as context in logging. It determines whether the message
63
+ * is a request or status type and stores the associated keys from the respective properties.
64
+ *
65
+ * @param {IMotionMasterMessage} motionMasterMessage - The message to convert into a logger context.
66
+ * @param {string} [namespace='reqResMessage'] - The namespace to associate with the context (default is 'reqResMessage').
67
+ * @returns {object} An object containing the `namespace`, the original `motionMasterMessage`, the `type` of message
68
+ * (either 'request' or 'status'), and the `name` (a string of keys from the request or status).
69
+ */
9
70
  export declare function convertMotionMasterMessageToLoggerContext(motionMasterMessage: IMotionMasterMessage, namespace?: string): {
10
71
  namespace: string;
11
72
  motionMasterMessage: IMotionMasterMessage;
12
- type: string | undefined;
13
- name: string | undefined;
73
+ type: string;
74
+ name: string;
14
75
  };
76
+ /**
77
+ * Decodes a `Uint8Array` of text content into a string.
78
+ *
79
+ * This function uses the `TextDecoder` API to decode the given `Uint8Array` (representing
80
+ * text encoded in a specific encoding, such as UTF-8) into a readable string.
81
+ *
82
+ * @param {Uint8Array} content - The `Uint8Array` containing the encoded text.
83
+ * @returns {string} The decoded string.
84
+ */
15
85
  export declare function decodeTextContent(content: Uint8Array): string;
16
- export declare function resolveAfter(ms: number, value?: unknown): Promise<unknown>;
86
+ /**
87
+ * Resolves a promise after a specified delay.
88
+ *
89
+ * This function returns a promise that resolves after the given number of milliseconds (`ms`),
90
+ * optionally resolving with a provided value.
91
+ *
92
+ * @param {number} ms - The number of milliseconds to wait before resolving the promise.
93
+ * @param {unknown} [value] - The value to resolve with once the delay has passed. Default is `undefined`.
94
+ * @returns {Promise<unknown>} A promise that resolves with the specified value after the delay.
95
+ */
96
+ export declare function resolveAfter<T>(ms: number, value?: T): Promise<T | undefined>;
97
+ /**
98
+ * Converts a 24-bit RGB color value to a format used by LED controllers.
99
+ *
100
+ * This function takes an RGB color value (represented as a single 24-bit number)
101
+ * and rearranges the color channels to match a typical LED color format, which may
102
+ * require swapping the red and green channels.
103
+ *
104
+ * @param {number} value - A 24-bit integer representing the RGB color value (0xRRGGBB).
105
+ * @returns {number} A new integer representing the color in the LED format (0xGRB).
106
+ */
17
107
  export declare function convertRgbToLedColor(value: number): number;
108
+ /**
109
+ * Generates a random hex color code with a specified brightness.
110
+ *
111
+ * This function creates a random color by generating random values for the red, green, and blue
112
+ * color channels. The brightness parameter ensures the generated color is not too dark by
113
+ * limiting the possible range for each channel.
114
+ *
115
+ * @param {number} brightness - The minimum brightness of the generated color. Should be between 0 and 255.
116
+ * @returns {string} A random hex color code, in the form of `#RRGGBB`.
117
+ *
118
+ * @throws {Error} Throws an error if the brightness is not between 0 and 255.
119
+ */
18
120
  export declare function createRandomColor(brightness: number): string;
121
+ /**
122
+ * Retrieves the first key from a `Map` that matches a given value.
123
+ *
124
+ * This function iterates over the entries of the map and returns the first key
125
+ * whose corresponding value strictly equals (`===`) the provided `searchValue`.
126
+ * If no matching value is found, it returns `undefined`.
127
+ *
128
+ * @template K - The type of the map's keys.
129
+ * @template V - The type of the map's values.
130
+ * @param {Map<K, V>} map - The map to search through.
131
+ * @param {V} searchValue - The value to find the corresponding key for.
132
+ * @returns {K | undefined} The key associated with the given value, or `undefined` if not found.
133
+ */
19
134
  export declare function getMapKeyByValue<K, V>(map: Map<K, V>, searchValue: V): K | undefined;
135
+ /**
136
+ * Finds and returns the duplicate elements in an array.
137
+ *
138
+ * This function iterates through the array and identifies elements that appear more than once.
139
+ * It preserves only one instance of each duplicate in the output.
140
+ *
141
+ * @template T - The type of elements in the array.
142
+ * @param {T[]} arr - The input array to search for duplicates.
143
+ * @returns {T[]} An array of the duplicate elements, without repetition.
144
+ */
20
145
  export declare function findDuplicates<T>(arr: T[]): T[];
146
+ /**
147
+ * Converts a camelCase string into a space-separated lowercase string.
148
+ *
149
+ * This function inserts spaces before each uppercase letter in the string (except the first one)
150
+ * and converts the entire string to lowercase.
151
+ *
152
+ * @param {string} str - The camelCase string to convert.
153
+ * @returns {string} A space-separated, lowercase version of the input string.
154
+ */
21
155
  export declare function camelCaseToWords(str: string): string;
22
156
  /**
23
157
  * Sets the specified bit in the given number to 0.
@@ -35,6 +169,60 @@ export declare function setBitLow(value: number, position: number): number;
35
169
  * @returns {number} The modified number with the specified bit set to 1.
36
170
  */
37
171
  export declare function setBitHigh(value: number, position: number): number;
172
+ /**
173
+ * Returns the bit at the specified position in a number.
174
+ *
175
+ * This function performs a bitwise AND operation to isolate the bit at the `k`th position.
176
+ * If the bit is 0, it returns `0`; otherwise, it returns `1`.
177
+ *
178
+ * @param {number} n - The number whose bit will be retrieved.
179
+ * @param {number} k - The position of the bit to retrieve (0-indexed).
180
+ * @returns {number} The bit at position `k` (either 0 or 1).
181
+ */
182
+ export declare function getBit(n: number, k: number): number;
183
+ /**
184
+ * Checks if the bit at the specified position is on (1).
185
+ *
186
+ * This function performs a bitwise AND operation to check if the bit at the `k`th position is set to `1`.
187
+ * It returns `true` if the bit is set, otherwise `false`.
188
+ *
189
+ * @param {number} n - The number to check.
190
+ * @param {number} k - The position of the bit to check (0-indexed).
191
+ * @returns {boolean} `true` if the bit is on (1), otherwise `false`.
192
+ */
193
+ export declare function isBitOn(n: number, k: number): boolean;
194
+ /**
195
+ * Sets the bit at the specified position to 1.
196
+ *
197
+ * This function performs a bitwise OR operation to ensure that the bit at the `k`th position is set to `1`.
198
+ *
199
+ * @param {number} n - The number in which the bit will be set.
200
+ * @param {number} k - The position of the bit to set (0-indexed).
201
+ * @returns {number} The new number with the bit at position `k` set to 1.
202
+ */
203
+ export declare function setBit(n: number, k: number): number;
204
+ /**
205
+ * Clears the bit at the specified position (sets it to 0).
206
+ *
207
+ * This function performs a bitwise AND operation with a mask to ensure that the bit at the `k`th position is set to `0`.
208
+ *
209
+ * @param {number} n - The number in which the bit will be cleared.
210
+ * @param {number} k - The position of the bit to clear (0-indexed).
211
+ * @returns {number} The new number with the bit at position `k` cleared (set to 0).
212
+ */
213
+ export declare function clearBit(n: number, k: number): number;
214
+ /**
215
+ * Updates the bit at the specified position with the given value.
216
+ *
217
+ * This function updates the bit at the `k`th position to either `1` or `0` depending on the provided value.
218
+ * If the value is a boolean, it will be normalized to `1` (true) or `0` (false).
219
+ *
220
+ * @param {number} n - The number in which the bit will be updated.
221
+ * @param {number} k - The position of the bit to update (0-indexed).
222
+ * @param {number | boolean} value - The value to set the bit to (1 or 0, or `true`/`false`).
223
+ * @returns {number} The new number with the bit at position `k` updated.
224
+ */
225
+ export declare function updateBit(n: number, k: number, value: number | boolean): number;
38
226
  /**
39
227
  * Converts a number (or string) to a fixed-point format with specified precision.
40
228
  *
@@ -44,6 +232,17 @@ export declare function setBitHigh(value: number, position: number): number;
44
232
  * @returns The formatted number as a string.
45
233
  */
46
234
  export declare function toFixedFormat(x: number | string, n?: number, rightTrimZero?: boolean): string;
235
+ /**
236
+ * Converts a `Blob` into a Base64-encoded string.
237
+ *
238
+ * This function reads the provided `Blob` using `FileReader` and extracts the Base64 content
239
+ * from the resulting data URL.
240
+ *
241
+ * @param {Blob} blob - The `Blob` to convert into a Base64 string.
242
+ * @returns {Promise<string>} A promise that resolves with the Base64 string representation of the blob.
243
+ *
244
+ * @throws {string} If the blob cannot be read (e.g., due to an error), the promise rejects with an error message.
245
+ */
47
246
  export declare function convertBlobToBase64(blob: Blob): Promise<string>;
48
247
  /**
49
248
  * Checks if the application is running in an Electron environment.
@@ -77,4 +276,56 @@ export declare function parseUnitValue(value: number): {
77
276
  denominator: number;
78
277
  reserved: number;
79
278
  };
279
+ /**
280
+ * Merges multiple `Uint8Array` instances into a single `Uint8Array`.
281
+ *
282
+ * This function concatenates all provided `Uint8Array` instances in the order they are given,
283
+ * producing a new array containing all their bytes sequentially.
284
+ *
285
+ * @param {...Uint8Array[]} ary - An array of `Uint8Array` instances to merge.
286
+ * @returns {Uint8Array} A new `Uint8Array` containing the concatenated bytes from all input arrays.
287
+ */
80
288
  export declare function mergeUint8Arrays(...ary: Uint8Array[]): Uint8Array;
289
+ /**
290
+ * Returns an array of unique items by removing duplicates from the given array.
291
+ *
292
+ * This function utilizes the `Set` object to remove duplicate values, ensuring that only unique items
293
+ * remain in the returned array. The order of items in the resulting array is preserved as in the input.
294
+ *
295
+ * @param {Array<T>} items - The array from which duplicates will be removed.
296
+ * @returns {Array<T>} A new array containing only the unique items from the input array.
297
+ */
298
+ export declare function uniqueItems<T>(items: Array<T>): Array<T>;
299
+ /**
300
+ * Groups an array of objects by the value of a specified property.
301
+ *
302
+ * This function iterates over the array of objects and groups them into a new object,
303
+ * where the key is the value of the specified property and the value is an array of
304
+ * objects that have that property value.
305
+ *
306
+ * @param {T[]} objects - The array of objects to be grouped.
307
+ * @param {string} prop - The property name by which the objects will be grouped.
308
+ * @returns {{ [key: string]: T[] }} An object where the keys are the unique property values and the values are arrays of objects that have that property value.
309
+ */
310
+ export declare function groupByProperty<T>(objects: T[], prop: keyof T): {
311
+ [key: string]: T[];
312
+ };
313
+ /**
314
+ * Maps an array of objects by a specified property, creating a map where the key is
315
+ * the value of the specified property and the value is an array of objects that have
316
+ * the same property value.
317
+ *
318
+ * @param {V[]} objects - The array of objects to be mapped.
319
+ * @param {keyof V} prop - The property name by which the objects will be mapped.
320
+ * @returns {Map<K, V[]>} A map where the keys are the unique property values and the values are arrays of objects that share that property value.
321
+ */
322
+ export declare function mapByProperty<V, K = string>(objects: V[], prop: keyof V): Map<K, V[]>;
323
+ /**
324
+ * Converts a C type to its corresponding struct format character.
325
+ *
326
+ * @param cType - The C type as a string (e.g., `int8_t`, `uint32_t`, `char[24]`, etc.).
327
+ * @returns A string representing the struct format equivalent of the given C type.
328
+ * For example, `int8_t` becomes `b`, `uint16_t` becomes `H`, `char[24]` becomes `24s`, etc.
329
+ * @throws Error if the given C type is not recognized.
330
+ */
331
+ export declare function convertCTypeToStructFormatCharacter(cType: string): string;