@elgato/utils 0.0.0 → 0.1.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.
Files changed (3) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +210 -210
  3. package/package.json +65 -65
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,210 +1,210 @@
1
- <div align="center">
2
-
3
- # @elgato/utils
4
-
5
- Utilities used throughout the Elgato ecosystem.
6
-
7
- [![@elgato/utils npm package](https://img.shields.io/npm/v/%40elgato/utils?logo=npm&logoColor=white)](https://www.npmjs.com/package/@elgato/utils)
8
- [![Elgato homepage](https://img.shields.io/badge/Elgato-3431cf?labelColor=grey&logo=Elgato)](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
- const cleanup = () => console.log("Hello world")
28
- using (deferredDisposable(cleanup)) {
29
- // ...
30
- }
31
-
32
- // "Hello world"
33
- ```
34
-
35
- ## Events
36
-
37
- ### `EventEmitter`
38
-
39
- An strongly-typed event emitter that enables the listening for, and emitting of, events; supported in browser and Node.js environments.
40
-
41
- ```ts
42
- import { EventEmitter } from "@elgato/utils";
43
-
44
- type EventMap = {
45
- created: [name: string];
46
- };
47
-
48
- const emitter = new EventEmitter<EventMap>();
49
- emitter.on("created", (name: string) => {
50
- // ...
51
- });
52
- ```
53
-
54
- ## JSON
55
-
56
- ### `JsonObject`
57
-
58
- Type that represents an object within JSON.
59
-
60
- ```ts
61
- import { type JsonObject } from "@elgato/utils";
62
-
63
- const obj: JsonObject = {
64
- name: "Elgato",
65
- };
66
- ```
67
-
68
- ### `JsonPrimitive`
69
-
70
- Type that represents a primitive within JSON, for example a string or number.
71
-
72
- ```ts
73
- import { type JsonPrimitive } from "@elgato/utils";
74
-
75
- const value: JsonPrimitive = "Elgato";
76
- ```
77
-
78
- ### `JsonValue`
79
-
80
- Type that represents a valid JSON value, for example an object, array, or primitive.
81
-
82
- ```ts
83
- import { type JsonValue } from "@elgato/utils";
84
-
85
- const value: JsonValue = ["Hello", "World"];
86
- ```
87
-
88
- ## Miscellaneous
89
-
90
- ### `Enumerable`
91
-
92
- Provides a read-only iterable collection of items that also acts as a partial polyfill for iterator helpers.
93
-
94
- ```js
95
- import { Enumerable } from "@elgato/utils";
96
-
97
- const items = new Enumerable(["One", "Two", "Three", "Four"]);
98
- items
99
- .drop(1) // Drop "One"
100
- .take(2); // Take "Two" & "Three"
101
- ```
102
-
103
- Polyfilled iterator helpers:
104
-
105
- - `Symbol.iterator`
106
- - `asIndexedPairs()`
107
- - `drop(limit)`
108
- - `every(predicate)`
109
- - `filter(predicate)`
110
- - `find(predicate)`
111
- - `findLast(predicate)`
112
- - `flapMap(mapper)`
113
- - `forEach(fn)`
114
- - `includes(search)`
115
- - `map(mapper)`
116
- - `reduce(accumulator, initial)`
117
- - `some(predicate)`
118
- - `take(limit)`
119
- - `toArray()`
120
-
121
- ### `Lazy`
122
-
123
- Object that wraps a lazily instantiated value, similar to C# [`Lazy<T>`](https://learn.microsoft.com/en-us/dotnet/framework/performance/lazy-initialization).
124
-
125
- ```js
126
- import { Lazy } from "@elgato/utils";
127
-
128
- const lazy = new Lazy(() => "Hello world");
129
- lazy.value; // "Hello world";
130
- ```
131
-
132
- ## Objects
133
-
134
- ### `get(source, path)`
135
-
136
- Gets the value at the specified (deep) path.
137
-
138
- ```js
139
- import { get } from "@elgato/utils";
140
-
141
- const obj = {
142
- name: "Elgato",
143
- };
144
-
145
- get(obj, "name"); // Elgato
146
- ```
147
-
148
- ### `set(target, path, value)`
149
-
150
- Sets the value at the specified (deep) path.
151
-
152
- ```js
153
- import { get } from "@elgato/utils";
154
-
155
- const obj = {
156
- name: "Gato",
157
- };
158
-
159
- set(obj, "name", "Elgato"); // { name: "Elgato" }
160
- ```
161
-
162
- ## Parsers
163
-
164
- ### `parseBoolean(value)`
165
-
166
- Parses the value a truthy-boolean; the strings `"0"` and `"false"` are parsed as `false`.
167
-
168
- ```js
169
- import { parseBoolean } from "@elgato/utils";
170
-
171
- const a = parseBoolean(1); // true
172
- const b = parseBoolean("false"); // false
173
- ```
174
-
175
- ### `parseNumber(value)`
176
-
177
- Attempts to parse a value to a number; returns `undefined` when parsing was unsuccessful.
178
-
179
- ```js
180
- import { parseNumber } from "@elgato/utils";
181
-
182
- const number = parseNumber("13"); // 13
183
- ```
184
-
185
- ## Promises
186
-
187
- ### `withResolvers()`
188
-
189
- 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).
190
-
191
- ```js
192
- import { withResolvers } "@elgato/utils";
193
-
194
- const { promise, resolve, reject } = withResolvers<string>();
195
- ```
196
-
197
- ## Timers
198
-
199
- ### `debounce(fn, delay)`
200
-
201
- Wraps a function; subsequent invocations of the wrapped function made within the specified delay are debounced to prevent multiple calls.
202
-
203
- ```js
204
- import { debounce } from "@elgato/utils";
205
-
206
- const fn = debounce(() => console.log("Hello world"), 1000);
207
-
208
- fn(); // Debounced
209
- fn(); // "Hello world"
210
- ```
1
+ <div align="center">
2
+
3
+ # @elgato/utils
4
+
5
+ Utilities used throughout the Elgato ecosystem.
6
+
7
+ [![@elgato/utils npm package](https://img.shields.io/npm/v/%40elgato/utils?logo=npm&logoColor=white)](https://www.npmjs.com/package/@elgato/utils)
8
+ [![Elgato homepage](https://img.shields.io/badge/Elgato-3431cf?labelColor=grey&logo=Elgato)](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
+ const cleanup = () => console.log("Hello world")
28
+ using (deferredDisposable(cleanup)) {
29
+ // ...
30
+ }
31
+
32
+ // "Hello world"
33
+ ```
34
+
35
+ ## Events
36
+
37
+ ### `EventEmitter`
38
+
39
+ An strongly-typed event emitter that enables the listening for, and emitting of, events; supported in browser and Node.js environments.
40
+
41
+ ```ts
42
+ import { EventEmitter } from "@elgato/utils";
43
+
44
+ type EventMap = {
45
+ created: [name: string];
46
+ };
47
+
48
+ const emitter = new EventEmitter<EventMap>();
49
+ emitter.on("created", (name: string) => {
50
+ // ...
51
+ });
52
+ ```
53
+
54
+ ## JSON
55
+
56
+ ### `JsonObject`
57
+
58
+ Type that represents an object within JSON.
59
+
60
+ ```ts
61
+ import { type JsonObject } from "@elgato/utils";
62
+
63
+ const obj: JsonObject = {
64
+ name: "Elgato",
65
+ };
66
+ ```
67
+
68
+ ### `JsonPrimitive`
69
+
70
+ Type that represents a primitive within JSON, for example a string or number.
71
+
72
+ ```ts
73
+ import { type JsonPrimitive } from "@elgato/utils";
74
+
75
+ const value: JsonPrimitive = "Elgato";
76
+ ```
77
+
78
+ ### `JsonValue`
79
+
80
+ Type that represents a valid JSON value, for example an object, array, or primitive.
81
+
82
+ ```ts
83
+ import { type JsonValue } from "@elgato/utils";
84
+
85
+ const value: JsonValue = ["Hello", "World"];
86
+ ```
87
+
88
+ ## Miscellaneous
89
+
90
+ ### `Enumerable`
91
+
92
+ Provides a read-only iterable collection of items that also acts as a partial polyfill for iterator helpers.
93
+
94
+ ```js
95
+ import { Enumerable } from "@elgato/utils";
96
+
97
+ const items = new Enumerable(["One", "Two", "Three", "Four"]);
98
+ items
99
+ .drop(1) // Drop "One"
100
+ .take(2); // Take "Two" & "Three"
101
+ ```
102
+
103
+ Polyfilled iterator helpers:
104
+
105
+ - `Symbol.iterator`
106
+ - `asIndexedPairs()`
107
+ - `drop(limit)`
108
+ - `every(predicate)`
109
+ - `filter(predicate)`
110
+ - `find(predicate)`
111
+ - `findLast(predicate)`
112
+ - `flapMap(mapper)`
113
+ - `forEach(fn)`
114
+ - `includes(search)`
115
+ - `map(mapper)`
116
+ - `reduce(accumulator, initial)`
117
+ - `some(predicate)`
118
+ - `take(limit)`
119
+ - `toArray()`
120
+
121
+ ### `Lazy`
122
+
123
+ Object that wraps a lazily instantiated value, similar to C# [`Lazy<T>`](https://learn.microsoft.com/en-us/dotnet/framework/performance/lazy-initialization).
124
+
125
+ ```js
126
+ import { Lazy } from "@elgato/utils";
127
+
128
+ const lazy = new Lazy(() => "Hello world");
129
+ lazy.value; // "Hello world";
130
+ ```
131
+
132
+ ## Objects
133
+
134
+ ### `get(source, path)`
135
+
136
+ Gets the value at the specified (deep) path.
137
+
138
+ ```js
139
+ import { get } from "@elgato/utils";
140
+
141
+ const obj = {
142
+ name: "Elgato",
143
+ };
144
+
145
+ get(obj, "name"); // Elgato
146
+ ```
147
+
148
+ ### `set(target, path, value)`
149
+
150
+ Sets the value at the specified (deep) path.
151
+
152
+ ```js
153
+ import { get } from "@elgato/utils";
154
+
155
+ const obj = {
156
+ name: "Gato",
157
+ };
158
+
159
+ set(obj, "name", "Elgato"); // { name: "Elgato" }
160
+ ```
161
+
162
+ ## Parsers
163
+
164
+ ### `parseBoolean(value)`
165
+
166
+ Parses the value a truthy-boolean; the strings `"0"` and `"false"` are parsed as `false`.
167
+
168
+ ```js
169
+ import { parseBoolean } from "@elgato/utils";
170
+
171
+ const a = parseBoolean(1); // true
172
+ const b = parseBoolean("false"); // false
173
+ ```
174
+
175
+ ### `parseNumber(value)`
176
+
177
+ Attempts to parse a value to a number; returns `undefined` when parsing was unsuccessful.
178
+
179
+ ```js
180
+ import { parseNumber } from "@elgato/utils";
181
+
182
+ const number = parseNumber("13"); // 13
183
+ ```
184
+
185
+ ## Promises
186
+
187
+ ### `withResolvers()`
188
+
189
+ 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).
190
+
191
+ ```js
192
+ import { withResolvers } "@elgato/utils";
193
+
194
+ const { promise, resolve, reject } = withResolvers<string>();
195
+ ```
196
+
197
+ ## Timers
198
+
199
+ ### `debounce(fn, delay)`
200
+
201
+ Wraps a function; subsequent invocations of the wrapped function made within the specified delay are debounced to prevent multiple calls.
202
+
203
+ ```js
204
+ import { debounce } from "@elgato/utils";
205
+
206
+ const fn = debounce(() => console.log("Hello world"), 1000);
207
+
208
+ fn(); // Debounced
209
+ fn(); // "Hello world"
210
+ ```
package/package.json CHANGED
@@ -1,65 +1,65 @@
1
- {
2
- "name": "@elgato/utils",
3
- "version": "0.0.0",
4
- "description": "Utilities used throughout the Elgato ecosystem.",
5
- "type": "module",
6
- "files": [
7
- "./dist/"
8
- ],
9
- "scripts": {
10
- "build": "rm -rf dist/ && tsc --project tsconfig.build.json",
11
- "lint": "eslint --max-warnings 0",
12
- "preversion": "npm run build && npm test && npm run lint",
13
- "test": "vitest run --typecheck",
14
- "test:coverage": "vitest run --coverage",
15
- "test:watch": "vitest --typecheck",
16
- "type:check": "tsc"
17
- },
18
- "exports": {
19
- ".": {
20
- "types": "./dist/index.d.ts",
21
- "default": "./dist/index.js"
22
- },
23
- "./i18n": {
24
- "types": "./dist/i18n/index.d.ts",
25
- "default": "./dist/i18n/index.js"
26
- },
27
- "./logging": {
28
- "types": "./dist/logging/index.d.ts",
29
- "default": "./dist/logging/index.js"
30
- },
31
- "./rpc": {
32
- "types": "./dist/rpc/index.d.ts",
33
- "default": "./dist/rpc/index.js"
34
- }
35
- },
36
- "prettier": "@elgato/prettier-config",
37
- "repository": {
38
- "type": "git",
39
- "url": "git+https://github.com/elgatosf/js-utils.git"
40
- },
41
- "keywords": [
42
- "elgato"
43
- ],
44
- "author": {
45
- "name": "Elgato",
46
- "url": "https://www.elgato.com"
47
- },
48
- "license": "MIT",
49
- "bugs": {
50
- "url": "https://github.com/elgatosf/js-utils/issues"
51
- },
52
- "homepage": "https://github.com/elgatosf/js-utils#readme",
53
- "devDependencies": {
54
- "@elgato/eslint-config": "^0.1.0",
55
- "@elgato/prettier-config": "^0.2.6",
56
- "@tsconfig/node20": "^20.1.5",
57
- "@types/node": "^22.15.19",
58
- "@vitest/coverage-v8": "^3.1.4",
59
- "typescript": "^5.8.3",
60
- "vitest": "^3.1.3"
61
- },
62
- "dependencies": {
63
- "zod": "^3.25.24"
64
- }
65
- }
1
+ {
2
+ "name": "@elgato/utils",
3
+ "version": "0.1.0",
4
+ "description": "Utilities used throughout the Elgato ecosystem.",
5
+ "type": "module",
6
+ "files": [
7
+ "./dist/"
8
+ ],
9
+ "scripts": {
10
+ "build": "rm -rf dist/ && tsc --project tsconfig.build.json",
11
+ "lint": "eslint --max-warnings 0",
12
+ "preversion": "npm run build && npm test && npm run lint",
13
+ "test": "vitest run --typecheck",
14
+ "test:coverage": "vitest run --coverage",
15
+ "test:watch": "vitest --typecheck",
16
+ "type:check": "tsc"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./i18n": {
24
+ "types": "./dist/i18n/index.d.ts",
25
+ "default": "./dist/i18n/index.js"
26
+ },
27
+ "./logging": {
28
+ "types": "./dist/logging/index.d.ts",
29
+ "default": "./dist/logging/index.js"
30
+ },
31
+ "./rpc": {
32
+ "types": "./dist/rpc/index.d.ts",
33
+ "default": "./dist/rpc/index.js"
34
+ }
35
+ },
36
+ "prettier": "@elgato/prettier-config",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/elgatosf/js-utils.git"
40
+ },
41
+ "keywords": [
42
+ "elgato"
43
+ ],
44
+ "author": {
45
+ "name": "Elgato",
46
+ "url": "https://www.elgato.com"
47
+ },
48
+ "license": "MIT",
49
+ "bugs": {
50
+ "url": "https://github.com/elgatosf/js-utils/issues"
51
+ },
52
+ "homepage": "https://github.com/elgatosf/js-utils#readme",
53
+ "devDependencies": {
54
+ "@elgato/eslint-config": "^0.1.0",
55
+ "@elgato/prettier-config": "^0.2.6",
56
+ "@tsconfig/node20": "^20.1.5",
57
+ "@types/node": "^22.15.19",
58
+ "@vitest/coverage-v8": "^3.1.4",
59
+ "typescript": "^5.8.3",
60
+ "vitest": "^3.1.3"
61
+ },
62
+ "dependencies": {
63
+ "zod": "^3.25.24"
64
+ }
65
+ }