@elgato/utils 0.4.5 → 0.5.0
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/LICENSE +21 -21
- package/README.md +253 -253
- package/dist/i18n/provider.d.ts +1 -1
- package/dist/i18n/provider.js +1 -1
- package/dist/logging/node/file-target.d.ts +9 -6
- package/dist/logging/node/file-target.js +6 -3
- package/dist/parsers.d.ts +1 -1
- package/dist/rpc/json-rpc/error.js +1 -1
- package/dist/rpc/json-rpc/response.d.ts +1 -1
- package/package.json +66 -64
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Corsair Memory Inc.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Corsair Memory Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,253 +1,253 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-
# @elgato/utils
|
|
4
|
-
|
|
5
|
-
Utilities used throughout the Elgato ecosystem.
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/@elgato/utils)
|
|
8
|
-
[](https://elgato.com)
|
|
9
|
-
|
|
10
|
-
</div>
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
```
|
|
15
|
-
npm install @elgato/utils
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Disposables
|
|
19
|
-
|
|
20
|
-
### `deferredDisposable`
|
|
21
|
-
|
|
22
|
-
Creates a new function that implements `Symbol.dispose` and accepts a disposer function. The disposer function is called when the new function is disposed.
|
|
23
|
-
|
|
24
|
-
```js
|
|
25
|
-
import { deferredDisposable } from "@elgato/utils";
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
using deferredDisposable(() => console.log("Hello world"));
|
|
29
|
-
// ...
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// "Hello world"
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### `DisposableStack`
|
|
36
|
-
|
|
37
|
-
Stack of managed resources, controlled by a single disposer. Partial polyfill of TC39 Explicit Resource Management's `DisposableStack`.
|
|
38
|
-
|
|
39
|
-
```js
|
|
40
|
-
import { DisposableStack } from "@elgato/utils";
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
using stack = new DisposableStack();
|
|
44
|
-
stack.defer(() => "Hello");
|
|
45
|
-
stack.defer(() => "world");
|
|
46
|
-
// ...
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// "Hello"
|
|
50
|
-
// "world"
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Events
|
|
54
|
-
|
|
55
|
-
### `EventEmitter`
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
import { EventEmitter } from "@elgato/utils";
|
|
61
|
-
|
|
62
|
-
type EventMap = {
|
|
63
|
-
created: [name: string];
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const emitter = new EventEmitter<EventMap>();
|
|
67
|
-
emitter.on("created", (name: string) => {
|
|
68
|
-
// ...
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## JSON
|
|
73
|
-
|
|
74
|
-
### `JsonObject`
|
|
75
|
-
|
|
76
|
-
Type that represents an object within JSON.
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
import { type JsonObject } from "@elgato/utils";
|
|
80
|
-
|
|
81
|
-
const obj: JsonObject = {
|
|
82
|
-
name: "Elgato",
|
|
83
|
-
};
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### `JsonPrimitive`
|
|
87
|
-
|
|
88
|
-
Type that represents a primitive within JSON, for example a string or number.
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
import { type JsonPrimitive } from "@elgato/utils";
|
|
92
|
-
|
|
93
|
-
const value: JsonPrimitive = "Elgato";
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### `JsonValue`
|
|
97
|
-
|
|
98
|
-
Type that represents a valid JSON value, for example an object, array, or primitive.
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
import { type JsonValue } from "@elgato/utils";
|
|
102
|
-
|
|
103
|
-
const value: JsonValue = ["Hello", "World"];
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Miscellaneous
|
|
107
|
-
|
|
108
|
-
### `Enumerable`
|
|
109
|
-
|
|
110
|
-
Provides a read-only iterable collection of items that also acts as a partial polyfill for iterator helpers.
|
|
111
|
-
|
|
112
|
-
```js
|
|
113
|
-
import { Enumerable } from "@elgato/utils";
|
|
114
|
-
|
|
115
|
-
const items = new Enumerable(["One", "Two", "Three", "Four"]);
|
|
116
|
-
items
|
|
117
|
-
.drop(1) // Drop "One"
|
|
118
|
-
.take(2); // Take "Two" & "Three"
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
Polyfilled iterator helpers:
|
|
122
|
-
|
|
123
|
-
- `Symbol.iterator`
|
|
124
|
-
- `asIndexedPairs()`
|
|
125
|
-
- `drop(limit)`
|
|
126
|
-
- `every(predicate)`
|
|
127
|
-
- `filter(predicate)`
|
|
128
|
-
- `find(predicate)`
|
|
129
|
-
- `findLast(predicate)`
|
|
130
|
-
- `
|
|
131
|
-
- `forEach(fn)`
|
|
132
|
-
- `includes(search)`
|
|
133
|
-
- `map(mapper)`
|
|
134
|
-
- `reduce(accumulator, initial)`
|
|
135
|
-
- `some(predicate)`
|
|
136
|
-
- `take(limit)`
|
|
137
|
-
- `toArray()`
|
|
138
|
-
|
|
139
|
-
### `Lazy`
|
|
140
|
-
|
|
141
|
-
Object that wraps a lazily instantiated value, similar to C# [`Lazy<T>`](https://learn.microsoft.com/en-us/dotnet/framework/performance/lazy-initialization).
|
|
142
|
-
|
|
143
|
-
```js
|
|
144
|
-
import { Lazy } from "@elgato/utils";
|
|
145
|
-
|
|
146
|
-
const lazy = new Lazy(() => "Hello world");
|
|
147
|
-
lazy.value; // "Hello world";
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
## Objects
|
|
151
|
-
|
|
152
|
-
### `get(source, path)`
|
|
153
|
-
|
|
154
|
-
Gets the value at the specified (deep) path.
|
|
155
|
-
|
|
156
|
-
```js
|
|
157
|
-
import { get } from "@elgato/utils";
|
|
158
|
-
|
|
159
|
-
const obj = {
|
|
160
|
-
name: "Elgato",
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
get(obj, "name"); // Elgato
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
### `set(target, path, value)`
|
|
167
|
-
|
|
168
|
-
Sets the value at the specified (deep) path.
|
|
169
|
-
|
|
170
|
-
```js
|
|
171
|
-
import { get } from "@elgato/utils";
|
|
172
|
-
|
|
173
|
-
const obj = {
|
|
174
|
-
name: "Gato",
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
set(obj, "name", "Elgato"); // { name: "Elgato" }
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
## Parsers
|
|
181
|
-
|
|
182
|
-
### `parseBoolean(value)`
|
|
183
|
-
|
|
184
|
-
Parses the value a truthy-boolean; the strings `"0"` and `"false"` are parsed as `false`.
|
|
185
|
-
|
|
186
|
-
```js
|
|
187
|
-
import { parseBoolean } from "@elgato/utils";
|
|
188
|
-
|
|
189
|
-
const a = parseBoolean(1); // true
|
|
190
|
-
const b = parseBoolean("false"); // false
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### `parseNumber(value)`
|
|
194
|
-
|
|
195
|
-
Attempts to parse a value to a number; returns `undefined` when parsing was unsuccessful.
|
|
196
|
-
|
|
197
|
-
```js
|
|
198
|
-
import { parseNumber } from "@elgato/utils";
|
|
199
|
-
|
|
200
|
-
const number = parseNumber("13"); // 13
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
## Processes
|
|
204
|
-
|
|
205
|
-
### `getProcesses()`
|
|
206
|
-
|
|
207
|
-
Gets the running processes in a cross-platform way.
|
|
208
|
-
|
|
209
|
-
```js
|
|
210
|
-
import { getProcesses } from "@elgato/utils";
|
|
211
|
-
|
|
212
|
-
const processes = await getProcesses();
|
|
213
|
-
console.log(processes);
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
## Promises
|
|
217
|
-
|
|
218
|
-
### `withResolvers()`
|
|
219
|
-
|
|
220
|
-
Function that returns an object that contains the promise, and two functions to resolve or reject it. Polyfill of [Promise.withResolvers()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers).
|
|
221
|
-
|
|
222
|
-
```js
|
|
223
|
-
import { withResolvers } "@elgato/utils";
|
|
224
|
-
|
|
225
|
-
const { promise, resolve, reject } = withResolvers<string>();
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
## Strings
|
|
229
|
-
|
|
230
|
-
### `format(format, ...args)`
|
|
231
|
-
|
|
232
|
-
Formats the specified string, replacing placeholders with their associated arguments.
|
|
233
|
-
|
|
234
|
-
```js
|
|
235
|
-
import { format } from "@elgato/utils";
|
|
236
|
-
|
|
237
|
-
format("Hello {0}, from {1}", "world", "Elgato"); // Hello world, from Elgato
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
## Timers
|
|
241
|
-
|
|
242
|
-
### `debounce(fn, delay)`
|
|
243
|
-
|
|
244
|
-
Wraps a function; subsequent invocations of the wrapped function made within the specified delay are debounced to prevent multiple calls.
|
|
245
|
-
|
|
246
|
-
```js
|
|
247
|
-
import { debounce } from "@elgato/utils";
|
|
248
|
-
|
|
249
|
-
const fn = debounce(() => console.log("Hello world"), 1000);
|
|
250
|
-
|
|
251
|
-
fn(); // Debounced
|
|
252
|
-
fn(); // "Hello world"
|
|
253
|
-
```
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @elgato/utils
|
|
4
|
+
|
|
5
|
+
Utilities used throughout the Elgato ecosystem.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@elgato/utils)
|
|
8
|
+
[](https://elgato.com)
|
|
9
|
+
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npm install @elgato/utils
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Disposables
|
|
19
|
+
|
|
20
|
+
### `deferredDisposable`
|
|
21
|
+
|
|
22
|
+
Creates a new function that implements `Symbol.dispose` and accepts a disposer function. The disposer function is called when the new function is disposed.
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { deferredDisposable } from "@elgato/utils";
|
|
26
|
+
|
|
27
|
+
{
|
|
28
|
+
using deferredDisposable(() => console.log("Hello world"));
|
|
29
|
+
// ...
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// "Hello world"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### `DisposableStack`
|
|
36
|
+
|
|
37
|
+
Stack of managed resources, controlled by a single disposer. Partial polyfill of TC39 Explicit Resource Management's `DisposableStack`.
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { DisposableStack } from "@elgato/utils";
|
|
41
|
+
|
|
42
|
+
{
|
|
43
|
+
using stack = new DisposableStack();
|
|
44
|
+
stack.defer(() => "Hello");
|
|
45
|
+
stack.defer(() => "world");
|
|
46
|
+
// ...
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// "Hello"
|
|
50
|
+
// "world"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Events
|
|
54
|
+
|
|
55
|
+
### `EventEmitter`
|
|
56
|
+
|
|
57
|
+
A strongly-typed event emitter that enables the listening for, and emitting of, events; supported in browser and Node.js environments.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { EventEmitter } from "@elgato/utils";
|
|
61
|
+
|
|
62
|
+
type EventMap = {
|
|
63
|
+
created: [name: string];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const emitter = new EventEmitter<EventMap>();
|
|
67
|
+
emitter.on("created", (name: string) => {
|
|
68
|
+
// ...
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## JSON
|
|
73
|
+
|
|
74
|
+
### `JsonObject`
|
|
75
|
+
|
|
76
|
+
Type that represents an object within JSON.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { type JsonObject } from "@elgato/utils";
|
|
80
|
+
|
|
81
|
+
const obj: JsonObject = {
|
|
82
|
+
name: "Elgato",
|
|
83
|
+
};
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### `JsonPrimitive`
|
|
87
|
+
|
|
88
|
+
Type that represents a primitive within JSON, for example a string or number.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { type JsonPrimitive } from "@elgato/utils";
|
|
92
|
+
|
|
93
|
+
const value: JsonPrimitive = "Elgato";
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### `JsonValue`
|
|
97
|
+
|
|
98
|
+
Type that represents a valid JSON value, for example an object, array, or primitive.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { type JsonValue } from "@elgato/utils";
|
|
102
|
+
|
|
103
|
+
const value: JsonValue = ["Hello", "World"];
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Miscellaneous
|
|
107
|
+
|
|
108
|
+
### `Enumerable`
|
|
109
|
+
|
|
110
|
+
Provides a read-only iterable collection of items that also acts as a partial polyfill for iterator helpers.
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
import { Enumerable } from "@elgato/utils";
|
|
114
|
+
|
|
115
|
+
const items = new Enumerable(["One", "Two", "Three", "Four"]);
|
|
116
|
+
items
|
|
117
|
+
.drop(1) // Drop "One"
|
|
118
|
+
.take(2); // Take "Two" & "Three"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Polyfilled iterator helpers:
|
|
122
|
+
|
|
123
|
+
- `Symbol.iterator`
|
|
124
|
+
- `asIndexedPairs()`
|
|
125
|
+
- `drop(limit)`
|
|
126
|
+
- `every(predicate)`
|
|
127
|
+
- `filter(predicate)`
|
|
128
|
+
- `find(predicate)`
|
|
129
|
+
- `findLast(predicate)`
|
|
130
|
+
- `flatMap(mapper)`
|
|
131
|
+
- `forEach(fn)`
|
|
132
|
+
- `includes(search)`
|
|
133
|
+
- `map(mapper)`
|
|
134
|
+
- `reduce(accumulator, initial)`
|
|
135
|
+
- `some(predicate)`
|
|
136
|
+
- `take(limit)`
|
|
137
|
+
- `toArray()`
|
|
138
|
+
|
|
139
|
+
### `Lazy`
|
|
140
|
+
|
|
141
|
+
Object that wraps a lazily instantiated value, similar to C# [`Lazy<T>`](https://learn.microsoft.com/en-us/dotnet/framework/performance/lazy-initialization).
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
import { Lazy } from "@elgato/utils";
|
|
145
|
+
|
|
146
|
+
const lazy = new Lazy(() => "Hello world");
|
|
147
|
+
lazy.value; // "Hello world";
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Objects
|
|
151
|
+
|
|
152
|
+
### `get(source, path)`
|
|
153
|
+
|
|
154
|
+
Gets the value at the specified (deep) path.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
import { get } from "@elgato/utils";
|
|
158
|
+
|
|
159
|
+
const obj = {
|
|
160
|
+
name: "Elgato",
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
get(obj, "name"); // Elgato
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### `set(target, path, value)`
|
|
167
|
+
|
|
168
|
+
Sets the value at the specified (deep) path.
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
import { get } from "@elgato/utils";
|
|
172
|
+
|
|
173
|
+
const obj = {
|
|
174
|
+
name: "Gato",
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
set(obj, "name", "Elgato"); // { name: "Elgato" }
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Parsers
|
|
181
|
+
|
|
182
|
+
### `parseBoolean(value)`
|
|
183
|
+
|
|
184
|
+
Parses the value a truthy-boolean; the strings `"0"` and `"false"` are parsed as `false`.
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
import { parseBoolean } from "@elgato/utils";
|
|
188
|
+
|
|
189
|
+
const a = parseBoolean(1); // true
|
|
190
|
+
const b = parseBoolean("false"); // false
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### `parseNumber(value)`
|
|
194
|
+
|
|
195
|
+
Attempts to parse a value to a number; returns `undefined` when parsing was unsuccessful.
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
import { parseNumber } from "@elgato/utils";
|
|
199
|
+
|
|
200
|
+
const number = parseNumber("13"); // 13
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Processes
|
|
204
|
+
|
|
205
|
+
### `getProcesses()`
|
|
206
|
+
|
|
207
|
+
Gets the running processes in a cross-platform way.
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
import { getProcesses } from "@elgato/utils";
|
|
211
|
+
|
|
212
|
+
const processes = await getProcesses();
|
|
213
|
+
console.log(processes);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Promises
|
|
217
|
+
|
|
218
|
+
### `withResolvers()`
|
|
219
|
+
|
|
220
|
+
Function that returns an object that contains the promise, and two functions to resolve or reject it. Polyfill of [Promise.withResolvers()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers).
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
import { withResolvers } from "@elgato/utils";
|
|
224
|
+
|
|
225
|
+
const { promise, resolve, reject } = withResolvers<string>();
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Strings
|
|
229
|
+
|
|
230
|
+
### `format(format, ...args)`
|
|
231
|
+
|
|
232
|
+
Formats the specified string, replacing placeholders with their associated arguments.
|
|
233
|
+
|
|
234
|
+
```js
|
|
235
|
+
import { format } from "@elgato/utils";
|
|
236
|
+
|
|
237
|
+
format("Hello {0}, from {1}", "world", "Elgato"); // Hello world, from Elgato
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Timers
|
|
241
|
+
|
|
242
|
+
### `debounce(fn, delay)`
|
|
243
|
+
|
|
244
|
+
Wraps a function; subsequent invocations of the wrapped function made within the specified delay are debounced to prevent multiple calls.
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
import { debounce } from "@elgato/utils";
|
|
248
|
+
|
|
249
|
+
const fn = debounce(() => console.log("Hello world"), 1000);
|
|
250
|
+
|
|
251
|
+
fn(); // Debounced
|
|
252
|
+
fn(); // "Hello world"
|
|
253
|
+
```
|
package/dist/i18n/provider.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { IDisposable } from "../explicit-resource-management/disposable.js"
|
|
|
2
2
|
import type { JsonObject } from "../json.js";
|
|
3
3
|
import { type Language } from "./language.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* “Internationalization (i18n) provider, responsible for managing localizations and translating resources.
|
|
6
6
|
*/
|
|
7
7
|
export declare class I18nProvider<T extends string> {
|
|
8
8
|
#private;
|
package/dist/i18n/provider.js
CHANGED
|
@@ -2,7 +2,7 @@ import { EventEmitter } from "../event-emitter.js";
|
|
|
2
2
|
import { freeze, get } from "../objects.js";
|
|
3
3
|
import { defaultLanguage } from "./language.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* “Internationalization (i18n) provider, responsible for managing localizations and translating resources.
|
|
6
6
|
*/
|
|
7
7
|
export class I18nProvider {
|
|
8
8
|
/**
|
|
@@ -26,8 +26,9 @@ export declare class FileTarget implements LogTarget {
|
|
|
26
26
|
*/
|
|
27
27
|
private getLogFiles;
|
|
28
28
|
/**
|
|
29
|
-
* Re-indexes the existing log files associated with this file target, removing old log files whose
|
|
30
|
-
* remaining log files, leaving index "0" free
|
|
29
|
+
* Re-indexes the existing log files associated with this file target, removing old log files whose
|
|
30
|
+
* index exceeds the `maxFileCount`, and renaming the remaining log files, leaving index "0" free
|
|
31
|
+
* for a new log file.
|
|
31
32
|
*/
|
|
32
33
|
private reIndex;
|
|
33
34
|
}
|
|
@@ -40,8 +41,8 @@ export type FileTargetOptions = {
|
|
|
40
41
|
*/
|
|
41
42
|
dest: string;
|
|
42
43
|
/**
|
|
43
|
-
* Name of the log file. The filename extension will be `.log`, and the file will be indexed, e.g.
|
|
44
|
-
* filename will be `com.elgato.test.1.log`.
|
|
44
|
+
* Name of the log file. The filename extension will be `.log`, and the file will be indexed, e.g.
|
|
45
|
+
* when `fileName` is `com.elgato.test`, the resulting output filename will be `com.elgato.test.1.log`.
|
|
45
46
|
*/
|
|
46
47
|
fileName: string;
|
|
47
48
|
/**
|
|
@@ -49,11 +50,13 @@ export type FileTargetOptions = {
|
|
|
49
50
|
*/
|
|
50
51
|
format: LogEntryFormatter;
|
|
51
52
|
/**
|
|
52
|
-
* Maximum number of files that can be created as part of the target before old logs should be truncated
|
|
53
|
+
* Maximum number of files that can be created as part of the target before old logs should be truncated
|
|
54
|
+
* and removed.
|
|
53
55
|
*/
|
|
54
56
|
maxFileCount: number;
|
|
55
57
|
/**
|
|
56
|
-
* Maximum size of a log file; when exceeded, file rotation occurs and older log files are removed
|
|
58
|
+
* Maximum size of a log file; when exceeded, file rotation occurs and older log files are removed
|
|
59
|
+
* based on `maxFileCount`.
|
|
57
60
|
*/
|
|
58
61
|
maxSize: number;
|
|
59
62
|
};
|
|
@@ -78,13 +78,16 @@ export class FileTarget {
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
* Re-indexes the existing log files associated with this file target, removing old log files whose
|
|
82
|
-
* remaining log files, leaving index "0" free
|
|
81
|
+
* Re-indexes the existing log files associated with this file target, removing old log files whose
|
|
82
|
+
* index exceeds the `maxFileCount`, and renaming the remaining log files, leaving index "0" free
|
|
83
|
+
* for a new log file.
|
|
83
84
|
*/
|
|
84
85
|
reIndex() {
|
|
85
86
|
// When the destination directory is new, create it, and return.
|
|
86
87
|
if (!fs.existsSync(this.#options.dest)) {
|
|
87
|
-
fs.mkdirSync(this.#options.dest
|
|
88
|
+
fs.mkdirSync(this.#options.dest, {
|
|
89
|
+
recursive: true,
|
|
90
|
+
});
|
|
88
91
|
return;
|
|
89
92
|
}
|
|
90
93
|
const logFiles = this.getLogFiles();
|
package/dist/parsers.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @param value Value to parse.
|
|
4
4
|
* @returns `true` when the value is truthy; otherwise `false`.
|
|
5
5
|
*/
|
|
6
|
-
export declare function parseBoolean(value: unknown): boolean
|
|
6
|
+
export declare function parseBoolean(value: unknown): boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Parses the specified value to a number (using {@link parseFloat}).
|
|
9
9
|
* @param value Value to parse.
|
|
@@ -46,7 +46,7 @@ export declare const JsonRpcErrorResponse: z.ZodMiniType<JsonRpcErrorResponse>;
|
|
|
46
46
|
/**
|
|
47
47
|
* Response object sent to a client.
|
|
48
48
|
*/
|
|
49
|
-
export declare const JsonRpcResponse: z.ZodMiniUnion<readonly [z.ZodMiniType<JsonRpcSuccessResponse, unknown
|
|
49
|
+
export declare const JsonRpcResponse: z.ZodMiniUnion<readonly [z.ZodMiniType<JsonRpcSuccessResponse, unknown, z.core.$ZodTypeInternals<JsonRpcSuccessResponse, unknown>>, z.ZodMiniType<JsonRpcErrorResponse, unknown, z.core.$ZodTypeInternals<JsonRpcErrorResponse, unknown>>]>;
|
|
50
50
|
/**
|
|
51
51
|
* Response object sent to a client.
|
|
52
52
|
*/
|
package/package.json
CHANGED
|
@@ -1,70 +1,72 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"test": "vitest run --typecheck",
|
|
14
|
-
"test:coverage": "vitest run --coverage",
|
|
15
|
-
"test:watch": "vitest --typecheck",
|
|
16
|
-
"type:check": "tsc",
|
|
17
|
-
"watch": "tsc --project tsconfig.build.json --watch"
|
|
2
|
+
"name": "@elgato/utils",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Utilities used throughout the Elgato ecosystem.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"./dist/"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
18
13
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"default": "./dist/index.js"
|
|
23
|
-
},
|
|
24
|
-
"./i18n": {
|
|
25
|
-
"types": "./dist/i18n/index.d.ts",
|
|
26
|
-
"default": "./dist/i18n/index.js"
|
|
27
|
-
},
|
|
28
|
-
"./logging": {
|
|
29
|
-
"types": "./dist/logging/index.d.ts",
|
|
30
|
-
"default": "./dist/logging/index.js"
|
|
31
|
-
},
|
|
32
|
-
"./logging/*": {
|
|
33
|
-
"types": "./dist/logging/node/*.d.ts",
|
|
34
|
-
"default": "./dist/logging/node/*"
|
|
35
|
-
},
|
|
36
|
-
"./rpc": {
|
|
37
|
-
"types": "./dist/rpc/index.d.ts",
|
|
38
|
-
"default": "./dist/rpc/index.js"
|
|
39
|
-
}
|
|
14
|
+
"./i18n": {
|
|
15
|
+
"types": "./dist/i18n/index.d.ts",
|
|
16
|
+
"default": "./dist/i18n/index.js"
|
|
40
17
|
},
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"url": "git+https://github.com/elgatosf/js-utils.git"
|
|
18
|
+
"./logging": {
|
|
19
|
+
"types": "./dist/logging/index.d.ts",
|
|
20
|
+
"default": "./dist/logging/index.js"
|
|
45
21
|
},
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"author": {
|
|
50
|
-
"name": "Elgato",
|
|
51
|
-
"url": "https://www.elgato.com"
|
|
22
|
+
"./logging/*": {
|
|
23
|
+
"types": "./dist/logging/node/*.d.ts",
|
|
24
|
+
"default": "./dist/logging/node/*"
|
|
52
25
|
},
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
"homepage": "https://github.com/elgatosf/js-utils#readme",
|
|
58
|
-
"devDependencies": {
|
|
59
|
-
"@elgato/eslint-config": "^0.1.0",
|
|
60
|
-
"@elgato/prettier-config": "^0.2.6",
|
|
61
|
-
"@tsconfig/node20": "^20.1.5",
|
|
62
|
-
"@types/node": "^22.15.19",
|
|
63
|
-
"@vitest/coverage-v8": "^3.1.4",
|
|
64
|
-
"typescript": "^5.8.3",
|
|
65
|
-
"vitest": "^3.1.3"
|
|
66
|
-
},
|
|
67
|
-
"dependencies": {
|
|
68
|
-
"zod": "^3.25.24"
|
|
26
|
+
"./rpc": {
|
|
27
|
+
"types": "./dist/rpc/index.d.ts",
|
|
28
|
+
"default": "./dist/rpc/index.js"
|
|
69
29
|
}
|
|
70
|
-
}
|
|
30
|
+
},
|
|
31
|
+
"prettier": "@elgato/prettier-config",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/elgatosf/streamdeck.git"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"elgato"
|
|
38
|
+
],
|
|
39
|
+
"author": {
|
|
40
|
+
"name": "Elgato",
|
|
41
|
+
"url": "https://www.elgato.com"
|
|
42
|
+
},
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/elgatosf/streamdeck/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/elgatosf/streamdeck/tree/main/packages/utils#readme",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@elgato/eslint-config": "^0.3.2",
|
|
50
|
+
"@elgato/prettier-config": "^0.3.3",
|
|
51
|
+
"@tsconfig/node20": "^20.1.5",
|
|
52
|
+
"@types/node": "^22.15.19",
|
|
53
|
+
"@vitest/coverage-v8": "^3.1.4",
|
|
54
|
+
"eslint": "^9.39.4",
|
|
55
|
+
"prettier": "^3.8.1",
|
|
56
|
+
"typescript": "^5.8.3",
|
|
57
|
+
"vitest": "^3.1.3"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"zod": "^3.25.24"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "rm -rf dist/ && tsc --project tsconfig.build.json",
|
|
64
|
+
"dev": "tsc --project tsconfig.build.json --watch",
|
|
65
|
+
"lint": "eslint --max-warnings 0",
|
|
66
|
+
"preversion": "npm run build && npm test && npm run lint",
|
|
67
|
+
"test": "vitest run --typecheck",
|
|
68
|
+
"test:coverage": "vitest run --coverage",
|
|
69
|
+
"test:watch": "vitest --typecheck",
|
|
70
|
+
"type:check": "tsc"
|
|
71
|
+
}
|
|
72
|
+
}
|