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/package.json +1 -1
- package/src/api.js +81 -74
- package/src/api.js.map +1 -1
- package/src/lib/circulo.d.ts +51 -0
- package/src/lib/circulo.js +96 -1
- package/src/lib/circulo.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/device.d.ts +70 -24
- package/src/lib/device.js +45 -2
- package/src/lib/device.js.map +1 -1
- package/src/lib/motion-master-req-res-client.d.ts +12 -2
- package/src/lib/motion-master-req-res-client.js +14 -32
- 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.d.ts
CHANGED
|
@@ -1,72 +1,120 @@
|
|
|
1
|
-
import { OperatorFunction } from 'rxjs';
|
|
2
1
|
import { SystemLogLine } from './system-log-line';
|
|
3
2
|
import { IMotionMasterMessage, MotionMasterMessage, Ipv4 } from './types';
|
|
4
3
|
/**
|
|
5
|
-
* Parses a single line of system log into a structured `SystemLogLine` object.
|
|
4
|
+
* Parses a single line of a system log into a structured `SystemLogLine` object.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* The function expects the log line to follow the format:
|
|
7
|
+
* ```
|
|
8
|
+
* YYYY-MM-DD HH:MM:SS.sss (uptime) [id]file:linelevel|message
|
|
9
|
+
* ```
|
|
10
|
+
* where the `id` part is optional.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
12
|
+
* @param line - A single system log line as a string.
|
|
13
|
+
* @returns A `SystemLogLine` object with parsed fields, or `undefined` if the line cannot be parsed.
|
|
13
14
|
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
15
|
+
* @example
|
|
16
|
+
* const line = '2025-12-05 10:01:23.123 (12:34:56) [device1]main.ts:123INFO|Started';
|
|
17
|
+
* const parsed = parseSystemLogLine(line);
|
|
18
|
+
* console.log(parsed?.date); // → Date object for '2025-12-05 10:01:23.123'
|
|
19
|
+
* console.log(parsed?.uptime); // → '12:34:56'
|
|
20
|
+
* console.log(parsed?.id); // → 'device1'
|
|
21
|
+
* console.log(parsed?.message); // → 'Started'
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* - Uses a regular expression with the `s` (dotAll) flag; this may not be supported in all browsers.
|
|
25
|
+
* - If parsing fails, the function returns `undefined`.
|
|
26
|
+
* - The returned object includes the original line for reference.
|
|
16
27
|
*/
|
|
17
28
|
export declare function parseSystemLogLine(line: string): SystemLogLine | undefined;
|
|
18
29
|
/**
|
|
19
|
-
* Parses
|
|
30
|
+
* Parses a system log string into an array of structured `SystemLogLine` objects.
|
|
31
|
+
*
|
|
32
|
+
* Each log entry is expected to start with a timestamp in the format `YYYY-MM-DD HH:MM:SS.sss`.
|
|
33
|
+
* The function uses a regular expression to split the content into individual log entries,
|
|
34
|
+
* then parses each entry into a `SystemLogLine` using `parseSystemLogLine`.
|
|
20
35
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* and ensures only valid `SystemLogLine` objects are returned.
|
|
36
|
+
* @param content - The full system log content as a string.
|
|
37
|
+
* @returns An array of `SystemLogLine` objects representing each parsed log entry.
|
|
24
38
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
39
|
+
* @example
|
|
40
|
+
* const logContent = '2025-12-05 10:01:23.123 Info: started\n2025-12-05 10:01:24.456 Error: failed';
|
|
41
|
+
* const lines = parseSystemLogContent(logContent);
|
|
42
|
+
* console.log(lines[0].timestamp); // → Date object for '2025-12-05 10:01:23.123'
|
|
27
43
|
*
|
|
28
|
-
* @
|
|
29
|
-
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* - Entries that cannot be parsed by `parseSystemLogLine` are ignored.
|
|
46
|
+
* - The regular expression uses the `s` (dotAll) flag, which may not be supported in all browsers;
|
|
47
|
+
* a `@ts-ignore` is used to suppress TypeScript warnings.
|
|
30
48
|
*/
|
|
31
49
|
export declare function parseSystemLogContent(content: string): SystemLogLine[];
|
|
32
50
|
/**
|
|
33
|
-
*
|
|
51
|
+
* Computes the difference between two system log contents by returning only the new lines
|
|
52
|
+
* added after the last known line from the old content.
|
|
53
|
+
*
|
|
54
|
+
* @param oldContent - The previous log content.
|
|
55
|
+
* @param newContent - The current log content.
|
|
56
|
+
* @param lineSeparator - Optional string used to split lines (default: `'\n'`).
|
|
57
|
+
* @param lastLineIndex - Optional index of the line in `oldContent` to use as the reference point
|
|
58
|
+
* (default: `-2`, i.e., the second-to-last line).
|
|
59
|
+
* @returns A string containing only the new lines from `newContent` that come after the reference
|
|
60
|
+
* line from `oldContent`. If the reference line is not found, returns the entire `newContent`.
|
|
34
61
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
62
|
+
* @example
|
|
63
|
+
* const oldLog = 'line1\nline2\nline3';
|
|
64
|
+
* const newLog = 'line1\nline2\nline3\nline4\nline5';
|
|
65
|
+
* const diff = diffSystemLogContents(oldLog, newLog);
|
|
66
|
+
* console.log(diff); // → 'line4\nline5'
|
|
38
67
|
*
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* @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).
|
|
43
|
-
* @returns {string} The portion of `newContent` after the last matching line in `oldContent`. If no match is found, returns the entire `newContent`.
|
|
68
|
+
* @remarks
|
|
69
|
+
* - Useful for incremental log processing where only newly appended lines need to be handled.
|
|
70
|
+
* - Handles negative indexing for selecting the reference line from the end of `oldContent`.
|
|
44
71
|
*/
|
|
45
72
|
export declare function diffSystemLogContents(oldContent: string, newContent: string, lineSeparator?: string, lastLineIndex?: number): string;
|
|
46
73
|
/**
|
|
47
|
-
* Converts a `MotionMasterMessage`
|
|
74
|
+
* Converts a `MotionMasterMessage` instance into a plain JavaScript object with full defaults
|
|
75
|
+
* and JSON-compatible values.
|
|
48
76
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
77
|
+
* The conversion uses `MotionMasterMessage.toObject` with options that:
|
|
78
|
+
* - Convert bytes fields to standard arrays.
|
|
79
|
+
* - Include default values for missing fields.
|
|
80
|
+
* - Initialize empty arrays for repeated fields and empty objects for map fields.
|
|
81
|
+
* - Include virtual `oneof` properties indicating which field is set.
|
|
82
|
+
* - Apply JSON-compatible conversions (e.g., NaN and Infinity to strings).
|
|
52
83
|
*
|
|
53
|
-
*
|
|
84
|
+
* @param motionMasterMessage - The `MotionMasterMessage` instance to convert.
|
|
85
|
+
* @returns A plain object representation of the message with all fields populated and JSON-safe.
|
|
54
86
|
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
87
|
+
* @example
|
|
88
|
+
* const plainObject = createPlainObjectFromMotionMasterMessage(message);
|
|
89
|
+
* console.log(plainObject.status); // → fully populated status object
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* - Useful for logging, serialization, or transferring messages over standard JSON APIs.
|
|
93
|
+
* - Ensures that all optional, repeated, and map fields are represented in the resulting object.
|
|
57
94
|
*/
|
|
58
95
|
export declare function createPlainObjectFromMotionMasterMessage(motionMasterMessage: MotionMasterMessage): IMotionMasterMessage;
|
|
59
96
|
/**
|
|
60
|
-
* Converts a `
|
|
97
|
+
* Converts a `IMotionMasterMessage` into a structured context object suitable for logging.
|
|
98
|
+
*
|
|
99
|
+
* The resulting object includes:
|
|
100
|
+
* - `namespace`: a string identifying the logging context (default: `'reqResMessage'`),
|
|
101
|
+
* - `motionMasterMessage`: the original message,
|
|
102
|
+
* - `type`: either `'request'` or `'status'` depending on the message content,
|
|
103
|
+
* - `name`: a comma-separated string of the keys in the request or status object.
|
|
61
104
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
105
|
+
* @param motionMasterMessage - The Motion Master message to convert.
|
|
106
|
+
* @param namespace - Optional namespace for the logging context (default is `'reqResMessage'`).
|
|
107
|
+
* @returns An object containing the logging context with type, name, namespace, and original message.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* const context = convertMotionMasterMessageToLoggerContext(message, 'motion');
|
|
111
|
+
* console.log(context.namespace); // → 'motion'
|
|
112
|
+
* console.log(context.type); // → 'request' or 'status'
|
|
113
|
+
* console.log(context.name); // → comma-separated keys of the message content
|
|
65
114
|
*
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* (either 'request' or 'status'), and the `name` (a string of keys from the request or status).
|
|
115
|
+
* @remarks
|
|
116
|
+
* - Determines type by checking the presence of `request` or `status` in the message.
|
|
117
|
+
* - Useful for structured logging or telemetry where message metadata is required.
|
|
70
118
|
*/
|
|
71
119
|
export declare function convertMotionMasterMessageToLoggerContext(motionMasterMessage: IMotionMasterMessage, namespace?: string): {
|
|
72
120
|
namespace: string;
|
|
@@ -75,153 +123,242 @@ export declare function convertMotionMasterMessageToLoggerContext(motionMasterMe
|
|
|
75
123
|
name: string;
|
|
76
124
|
};
|
|
77
125
|
/**
|
|
78
|
-
* Decodes a `Uint8Array` of
|
|
126
|
+
* Decodes a `Uint8Array` of bytes into a string using UTF-8 encoding.
|
|
79
127
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
128
|
+
* @param content - The byte array to decode.
|
|
129
|
+
* @returns The decoded string representation of the input bytes.
|
|
82
130
|
*
|
|
83
|
-
* @
|
|
84
|
-
*
|
|
131
|
+
* @example
|
|
132
|
+
* const bytes = new Uint8Array([72, 101, 108, 108, 111]);
|
|
133
|
+
* const text = decodeTextContent(bytes); // → "Hello"
|
|
134
|
+
*
|
|
135
|
+
* @remarks
|
|
136
|
+
* - Uses the standard `TextDecoder` API with UTF-8 encoding.
|
|
137
|
+
* - Creates a copy of the input array before decoding, so the original `Uint8Array` is not modified.
|
|
85
138
|
*/
|
|
86
139
|
export declare function decodeTextContent(content: Uint8Array): string;
|
|
87
140
|
/**
|
|
88
|
-
*
|
|
141
|
+
* Returns a promise that resolves with the specified value after a given delay.
|
|
142
|
+
*
|
|
143
|
+
* @typeParam T - The type of the value to resolve.
|
|
144
|
+
* @param ms - The delay in milliseconds before the promise resolves.
|
|
145
|
+
* @param value - Optional value to resolve the promise with (defaults to `undefined` if not provided).
|
|
146
|
+
* @returns A `Promise` that resolves to `value` after `ms` milliseconds.
|
|
89
147
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
148
|
+
* @example
|
|
149
|
+
* await resolveAfter(1000, 'hello'); // resolves with 'hello' after 1 second
|
|
150
|
+
* await resolveAfter(500); // resolves with undefined after 0.5 seconds
|
|
92
151
|
*
|
|
93
|
-
* @
|
|
94
|
-
*
|
|
95
|
-
*
|
|
152
|
+
* @remarks
|
|
153
|
+
* - Useful for simulating delays or asynchronous timing in tests or animations.
|
|
154
|
+
* - The function does not reject; it always resolves after the specified timeout.
|
|
96
155
|
*/
|
|
97
156
|
export declare function resolveAfter<T>(ms: number, value?: T): Promise<T | undefined>;
|
|
98
157
|
/**
|
|
99
|
-
* Converts a 24-bit RGB color value
|
|
158
|
+
* Converts a standard 24-bit RGB color value into a format suitable for certain LED controllers.
|
|
159
|
+
*
|
|
160
|
+
* The conversion swaps the red and green channels, producing a new 24-bit integer where:
|
|
161
|
+
* - Original green becomes the most significant byte,
|
|
162
|
+
* - Original red becomes the middle byte,
|
|
163
|
+
* - Original blue remains the least significant byte.
|
|
100
164
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
165
|
+
* @param value - A 24-bit RGB color represented as a number (0xRRGGBB).
|
|
166
|
+
* @returns The converted 24-bit LED color value with swapped red and green channels.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* const rgb = 0x112233;
|
|
170
|
+
* const ledColor = convertRgbToLedColor(rgb); // → 0x221133
|
|
104
171
|
*
|
|
105
|
-
* @
|
|
106
|
-
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* - Useful when interfacing with LED hardware that expects a different channel ordering.
|
|
174
|
+
* - Input and output are standard JavaScript numbers representing 24-bit colors.
|
|
107
175
|
*/
|
|
108
176
|
export declare function convertRgbToLedColor(value: number): number;
|
|
109
177
|
/**
|
|
110
|
-
* Generates a random
|
|
178
|
+
* Generates a random hexadecimal color string with a specified minimum brightness.
|
|
111
179
|
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* limiting the possible range for each channel.
|
|
180
|
+
* @param brightness - Minimum value for each RGB channel (0–255). Higher values produce lighter colors.
|
|
181
|
+
* @returns A random color string in `#RRGGBB` format.
|
|
115
182
|
*
|
|
116
|
-
* @
|
|
117
|
-
*
|
|
183
|
+
* @example
|
|
184
|
+
* createRandomColor(100); // → '#c48f7a' (example output)
|
|
185
|
+
* createRandomColor(200); // → '#e5f0ff' (example output)
|
|
118
186
|
*
|
|
119
|
-
* @
|
|
187
|
+
* @remarks
|
|
188
|
+
* - Each color channel (red, green, blue) is independently randomized between `brightness` and 255.
|
|
189
|
+
* - Ensures that no channel is darker than the specified brightness.
|
|
190
|
+
* - Useful for generating visually distinct colors while avoiding very dark shades.
|
|
120
191
|
*/
|
|
121
192
|
export declare function createRandomColor(brightness: number): string;
|
|
122
193
|
/**
|
|
123
|
-
*
|
|
194
|
+
* Finds the first key in a `Map` that corresponds to the specified value.
|
|
195
|
+
*
|
|
196
|
+
* @typeParam K - The type of keys in the map.
|
|
197
|
+
* @typeParam V - The type of values in the map.
|
|
198
|
+
* @param map - The map to search.
|
|
199
|
+
* @param searchValue - The value to find the corresponding key for.
|
|
200
|
+
* @returns The first key whose value strictly equals (`===`) the searchValue, or `undefined` if no match is found.
|
|
124
201
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
202
|
+
* @example
|
|
203
|
+
* const myMap = new Map<string, number>([['a', 1], ['b', 2], ['c', 1]]);
|
|
204
|
+
* getMapKeyByValue(myMap, 1); // → 'a'
|
|
205
|
+
* getMapKeyByValue(myMap, 3); // → undefined
|
|
128
206
|
*
|
|
129
|
-
* @
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @param {V} searchValue - The value to find the corresponding key for.
|
|
133
|
-
* @returns {K | undefined} The key associated with the given value, or `undefined` if not found.
|
|
207
|
+
* @remarks
|
|
208
|
+
* - Only the first matching key is returned; subsequent keys with the same value are ignored.
|
|
209
|
+
* - Comparison uses strict equality (`===`).
|
|
134
210
|
*/
|
|
135
211
|
export declare function getMapKeyByValue<K, V>(map: Map<K, V>, searchValue: V): K | undefined;
|
|
136
212
|
/**
|
|
137
|
-
*
|
|
213
|
+
* Identifies duplicate elements in an array and returns them as a new array.
|
|
138
214
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
215
|
+
* @typeParam T - The type of elements in the array.
|
|
216
|
+
* @param arr - The array to check for duplicate values.
|
|
217
|
+
* @returns An array containing all elements that appear more than once in the input array.
|
|
218
|
+
* Each duplicate element appears only once in the returned array, regardless of how many times it occurs.
|
|
141
219
|
*
|
|
142
|
-
* @
|
|
143
|
-
*
|
|
144
|
-
*
|
|
220
|
+
* @example
|
|
221
|
+
* findDuplicates([1, 2, 3, 2, 4, 3, 5]); // → [2, 3]
|
|
222
|
+
* findDuplicates(['a', 'b', 'a', 'c']); // → ['a']
|
|
223
|
+
*
|
|
224
|
+
* @remarks
|
|
225
|
+
* - Uses `Set` internally for efficient duplicate detection.
|
|
226
|
+
* - Preserves the insertion order of first detected duplicates.
|
|
145
227
|
*/
|
|
146
228
|
export declare function findDuplicates<T>(arr: T[]): T[];
|
|
147
229
|
/**
|
|
148
|
-
* Converts a camelCase string into a space-separated lowercase string.
|
|
230
|
+
* Converts a camelCase or PascalCase string into a space-separated, lowercase string.
|
|
231
|
+
*
|
|
232
|
+
* @param str - The input string in camelCase or PascalCase format.
|
|
233
|
+
* @returns A new string where each uppercase letter is preceded by a space and all letters are lowercase.
|
|
149
234
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
235
|
+
* @example
|
|
236
|
+
* camelCaseToWords('camelCaseString'); // → 'camel case string'
|
|
237
|
+
* camelCaseToWords('PascalCase'); // → 'pascal case'
|
|
152
238
|
*
|
|
153
|
-
* @
|
|
154
|
-
*
|
|
239
|
+
* @remarks
|
|
240
|
+
* - Useful for converting identifiers into human-readable words.
|
|
241
|
+
* - Leading spaces are preserved if the string starts with an uppercase letter.
|
|
155
242
|
*/
|
|
156
243
|
export declare function camelCaseToWords(str: string): string;
|
|
157
244
|
/**
|
|
158
|
-
*
|
|
245
|
+
* Clears (sets to 0) the bit at the specified position in a number.
|
|
246
|
+
*
|
|
247
|
+
* @param value - The original number whose bit is to be cleared.
|
|
248
|
+
* @param position - Zero-based bit position to clear (0 = least-significant bit).
|
|
249
|
+
* @returns A new number with the bit at the specified position cleared to 0.
|
|
159
250
|
*
|
|
160
|
-
* @
|
|
161
|
-
*
|
|
162
|
-
*
|
|
251
|
+
* @example
|
|
252
|
+
* setBitLow(0b1011, 1); // → 0b1001 (clears bit 1)
|
|
253
|
+
* setBitLow(0b1111, 3); // → 0b0111 (clears bit 3)
|
|
254
|
+
*
|
|
255
|
+
* @remarks
|
|
256
|
+
* - Only the bit at the given position is affected; all other bits remain unchanged.
|
|
257
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
163
258
|
*/
|
|
164
259
|
export declare function setBitLow(value: number, position: number): number;
|
|
165
260
|
/**
|
|
166
|
-
* Sets the
|
|
261
|
+
* Sets (changes to 1) the bit at the specified position in a number.
|
|
262
|
+
*
|
|
263
|
+
* @param value - The original number whose bit is to be set.
|
|
264
|
+
* @param position - Zero-based bit position to set (0 = least-significant bit).
|
|
265
|
+
* @returns A new number with the bit at the specified position set to 1.
|
|
167
266
|
*
|
|
168
|
-
* @
|
|
169
|
-
*
|
|
170
|
-
*
|
|
267
|
+
* @example
|
|
268
|
+
* setBitHigh(0b1001, 1); // → 0b1011 (sets bit 1)
|
|
269
|
+
* setBitHigh(0b0111, 3); // → 0b1111 (sets bit 3)
|
|
270
|
+
*
|
|
271
|
+
* @remarks
|
|
272
|
+
* - Only the bit at the given position is affected; all other bits remain unchanged.
|
|
273
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
171
274
|
*/
|
|
172
275
|
export declare function setBitHigh(value: number, position: number): number;
|
|
173
276
|
/**
|
|
174
|
-
*
|
|
277
|
+
* Retrieves the value of the bit at the specified position in a number.
|
|
175
278
|
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
279
|
+
* @param n - The number from which to retrieve the bit.
|
|
280
|
+
* @param k - Zero-based bit position to retrieve (0 = least-significant bit).
|
|
281
|
+
* @returns `1` if the bit at position `k` is set, otherwise `0`.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* getBit(0b1010, 1); // → 1 (bit 1 is set)
|
|
285
|
+
* getBit(0b1010, 0); // → 0 (bit 0 is clear)
|
|
178
286
|
*
|
|
179
|
-
* @
|
|
180
|
-
*
|
|
181
|
-
*
|
|
287
|
+
* @remarks
|
|
288
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
289
|
+
* - Does not modify the original number.
|
|
182
290
|
*/
|
|
183
291
|
export declare function getBit(n: number, k: number): number;
|
|
184
292
|
/**
|
|
185
|
-
* Checks
|
|
293
|
+
* Checks whether the bit at the specified position in a number is set (1).
|
|
186
294
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
295
|
+
* @param n - The number to check.
|
|
296
|
+
* @param k - Zero-based bit position to check (0 = least-significant bit).
|
|
297
|
+
* @returns `true` if the bit at position `k` is 1, otherwise `false`.
|
|
189
298
|
*
|
|
190
|
-
* @
|
|
191
|
-
*
|
|
192
|
-
*
|
|
299
|
+
* @example
|
|
300
|
+
* isBitOn(0b1010, 1); // → true (bit 1 is set)
|
|
301
|
+
* isBitOn(0b1010, 0); // → false (bit 0 is clear)
|
|
302
|
+
*
|
|
303
|
+
* @remarks
|
|
304
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
305
|
+
* - Does not modify the original number.
|
|
193
306
|
*/
|
|
194
307
|
export declare function isBitOn(n: number, k: number): boolean;
|
|
195
308
|
/**
|
|
196
|
-
* Sets the bit at the specified position
|
|
309
|
+
* Sets (changes to 1) the bit at the specified position in a number.
|
|
197
310
|
*
|
|
198
|
-
*
|
|
311
|
+
* The original number is not mutated; a new number is returned with the bit set.
|
|
199
312
|
*
|
|
200
|
-
* @param
|
|
201
|
-
* @param
|
|
202
|
-
* @returns
|
|
313
|
+
* @param n - The original number whose bit is to be set.
|
|
314
|
+
* @param k - Zero-based bit position to set (0 = least-significant bit).
|
|
315
|
+
* @returns A new number equal to `n` with bit `k` set.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* setBit(0b1001, 1); // → 0b1011 (sets bit 1)
|
|
319
|
+
* setBit(0b0111, 3); // → 0b1111 (sets bit 3)
|
|
320
|
+
*
|
|
321
|
+
* @remarks
|
|
322
|
+
* - Only the bit at position `k` is affected; all other bits remain unchanged.
|
|
323
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
203
324
|
*/
|
|
204
325
|
export declare function setBit(n: number, k: number): number;
|
|
205
326
|
/**
|
|
206
|
-
* Clears the bit at the specified position
|
|
327
|
+
* Clears (sets to 0) the bit at the specified position in a number.
|
|
328
|
+
*
|
|
329
|
+
* The original number is not mutated; a new number is returned with the bit cleared.
|
|
207
330
|
*
|
|
208
|
-
*
|
|
331
|
+
* @param n - The original number whose bit is to be cleared.
|
|
332
|
+
* @param k - Zero-based bit position to clear (0 = least-significant bit).
|
|
333
|
+
* @returns A new number equal to `n` with bit `k` cleared.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* clearBit(0b1011, 1); // → 0b1001 (clears bit 1)
|
|
337
|
+
* clearBit(0b1111, 3); // → 0b0111 (clears bit 3)
|
|
209
338
|
*
|
|
210
|
-
* @
|
|
211
|
-
*
|
|
212
|
-
*
|
|
339
|
+
* @remarks
|
|
340
|
+
* - Only the bit at position `k` is affected; all other bits remain unchanged.
|
|
341
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
213
342
|
*/
|
|
214
343
|
export declare function clearBit(n: number, k: number): number;
|
|
215
344
|
/**
|
|
216
|
-
* Updates the bit at the
|
|
345
|
+
* Updates the bit at position `k` in the given number `n` to the specified value.
|
|
217
346
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
347
|
+
* The original number is not mutated; instead, a new number is returned with the bit updated.
|
|
348
|
+
*
|
|
349
|
+
* @param n - The original number whose bit is being modified.
|
|
350
|
+
* @param k - Zero-based bit position to update (0 = least-significant bit).
|
|
351
|
+
* @param value - Boolean or numeric value indicating whether the bit should be set (`true` / `1`)
|
|
352
|
+
* or cleared (`false` / `0`).
|
|
353
|
+
* @returns A new number equal to `n` with bit `k` updated.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* updateBit(0b1010, 1, true); // → 0b1011 (set bit 1)
|
|
357
|
+
* updateBit(0b1011, 3, false); // → 0b0011 (clear bit 3)
|
|
220
358
|
*
|
|
221
|
-
* @
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* @returns {number} The new number with the bit at position `k` updated.
|
|
359
|
+
* @remarks
|
|
360
|
+
* - Values other than `0` or `false` result in bit being set to `1`.
|
|
361
|
+
* - Works with any 32-bit integer representable in JavaScript.
|
|
225
362
|
*/
|
|
226
363
|
export declare function updateBit(n: number, k: number, value: number | boolean): number;
|
|
227
364
|
/**
|
|
@@ -234,15 +371,20 @@ export declare function updateBit(n: number, k: number, value: number | boolean)
|
|
|
234
371
|
*/
|
|
235
372
|
export declare function toFixedFormat(x: number | string, n?: number, rightTrimZero?: boolean): string;
|
|
236
373
|
/**
|
|
237
|
-
* Converts a `Blob` into a Base64-encoded string.
|
|
374
|
+
* Converts a `Blob` object into a Base64-encoded string.
|
|
238
375
|
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
376
|
+
* @param blob - The `Blob` to convert.
|
|
377
|
+
* @returns A `Promise` that resolves to the Base64 string representation of the blob.
|
|
241
378
|
*
|
|
242
|
-
* @
|
|
243
|
-
*
|
|
379
|
+
* @example
|
|
380
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
381
|
+
* const base64 = await convertBlobToBase64(blob);
|
|
382
|
+
* console.log(base64); // → 'SGVsbG8sIHdvcmxkIQ=='
|
|
244
383
|
*
|
|
245
|
-
* @
|
|
384
|
+
* @remarks
|
|
385
|
+
* - Internally uses `FileReader.readAsDataURL` to serialize the blob.
|
|
386
|
+
* - The returned Base64 string excludes the data URL prefix (e.g., `data:text/plain;base64,`).
|
|
387
|
+
* - The promise is rejected if the blob cannot be read.
|
|
246
388
|
*/
|
|
247
389
|
export declare function convertBlobToBase64(blob: Blob): Promise<string>;
|
|
248
390
|
/**
|
|
@@ -277,12 +419,17 @@ export declare function isElectronContext(): boolean;
|
|
|
277
419
|
*
|
|
278
420
|
* The function uses bitwise operations to isolate each byte from the 32-bit integer.
|
|
279
421
|
*
|
|
280
|
-
* @param
|
|
281
|
-
* @returns
|
|
422
|
+
* @param value - The 32-bit integer to be parsed.
|
|
423
|
+
* @returns An object containing the extracted components:
|
|
282
424
|
* - `prefix`: The extracted prefix byte (8 bits).
|
|
283
425
|
* - `numerator`: The extracted numerator byte (8 bits).
|
|
284
426
|
* - `denominator`: The extracted denominator byte (8 bits).
|
|
285
427
|
* - `reserved`: The extracted reserved byte (8 bits).
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* const parsed = parseUnitValue(0x12345678);
|
|
431
|
+
* console.log(parsed);
|
|
432
|
+
* // → { prefix: 0x12, numerator: 0x34, denominator: 0x56, reserved: 0x78 }
|
|
286
433
|
*/
|
|
287
434
|
export declare function parseUnitValue(value: number): {
|
|
288
435
|
prefix: number;
|
|
@@ -293,21 +440,34 @@ export declare function parseUnitValue(value: number): {
|
|
|
293
440
|
/**
|
|
294
441
|
* Merges multiple `Uint8Array` instances into a single `Uint8Array`.
|
|
295
442
|
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
443
|
+
* @param ary - One or more `Uint8Array` instances to merge.
|
|
444
|
+
* @returns A new `Uint8Array` containing all elements from the input arrays in order.
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* const a = new Uint8Array([1, 2]);
|
|
448
|
+
* const b = new Uint8Array([3, 4]);
|
|
449
|
+
* const merged = mergeUint8Arrays(a, b); // → Uint8Array [1, 2, 3, 4]
|
|
298
450
|
*
|
|
299
|
-
* @
|
|
300
|
-
*
|
|
451
|
+
* @remarks
|
|
452
|
+
* - Preserves the order of elements from each input array.
|
|
453
|
+
* - Efficiently concatenates arrays without creating intermediate arrays for each element.
|
|
454
|
+
* - Returns a new `Uint8Array`; the input arrays are not modified.
|
|
301
455
|
*/
|
|
302
456
|
export declare function mergeUint8Arrays(...ary: Uint8Array[]): Uint8Array;
|
|
303
457
|
/**
|
|
304
|
-
* Returns
|
|
458
|
+
* Returns a new array containing only the unique elements from the input array, preserving their order.
|
|
459
|
+
*
|
|
460
|
+
* @typeParam T - The type of elements in the array.
|
|
461
|
+
* @param items - The array from which to remove duplicates.
|
|
462
|
+
* @returns A new array with duplicate elements removed.
|
|
305
463
|
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
464
|
+
* @example
|
|
465
|
+
* uniqueItems([1, 2, 2, 3, 1]); // → [1, 2, 3]
|
|
466
|
+
* uniqueItems(['a', 'b', 'a']); // → ['a', 'b']
|
|
308
467
|
*
|
|
309
|
-
* @
|
|
310
|
-
*
|
|
468
|
+
* @remarks
|
|
469
|
+
* - Uses a `Set` internally for efficient duplicate removal.
|
|
470
|
+
* - Original array is not modified.
|
|
311
471
|
*/
|
|
312
472
|
export declare function uniqueItems<T>(items: Array<T>): Array<T>;
|
|
313
473
|
/**
|
|
@@ -450,27 +610,6 @@ export interface NotificationEntry {
|
|
|
450
610
|
message: string;
|
|
451
611
|
timeDifference: number;
|
|
452
612
|
}
|
|
453
|
-
/**
|
|
454
|
-
* Custom RxJS operator that accumulates notifications with their
|
|
455
|
-
* elapsed time relative to a provided start time.
|
|
456
|
-
*
|
|
457
|
-
* Each emitted notification string is converted into a `NotificationEntry`
|
|
458
|
-
* object, and the operator maintains an array of all previous entries.
|
|
459
|
-
*
|
|
460
|
-
* @param startTime - The timestamp (in milliseconds) to use as the reference
|
|
461
|
-
* point for calculating elapsed time. Typically obtained via `performance.now()`.
|
|
462
|
-
* @returns An OperatorFunction that transforms an Observable of strings into
|
|
463
|
-
* an Observable of `NotificationEntry[]`.
|
|
464
|
-
*
|
|
465
|
-
* @example
|
|
466
|
-
* ```ts
|
|
467
|
-
* const startTime = performance.now();
|
|
468
|
-
* notifications$.pipe(withTimeDifference(startTime)).subscribe(entries => {
|
|
469
|
-
* console.log(entries); // Array of NotificationEntry objects with elapsed time
|
|
470
|
-
* });
|
|
471
|
-
* ```
|
|
472
|
-
*/
|
|
473
|
-
export declare function withTimeDifference(startTime: number): OperatorFunction<string, NotificationEntry[]>;
|
|
474
613
|
/**
|
|
475
614
|
* Analyzes an array of measured time durations and returns useful statistics
|
|
476
615
|
* both for the full dataset and for outlier-filtered data.
|