@elgato/utils 0.5.0 → 0.6.1
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/dist/i18n/provider.js +2 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/objects/freeze.d.ts +5 -0
- package/dist/objects/freeze.js +10 -0
- package/dist/objects/get.d.ts +7 -0
- package/dist/objects/get.js +10 -0
- package/dist/objects/set.d.ts +7 -0
- package/dist/objects/set.js +42 -0
- package/dist/rpc/json-rpc/request.js +1 -4
- package/package.json +20 -23
- package/dist/objects.d.ts +0 -19
- package/dist/objects.js +0 -33
package/dist/i18n/provider.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "../event-emitter.js";
|
|
2
|
-
import { freeze
|
|
2
|
+
import { freeze } from "../objects/freeze.js";
|
|
3
|
+
import { get } from "../objects/get.js";
|
|
3
4
|
import { defaultLanguage } from "./language.js";
|
|
4
5
|
/**
|
|
5
6
|
* “Internationalization (i18n) provider, responsible for managing localizations and translating resources.
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ export * from "./event-emitter.js";
|
|
|
3
3
|
export * from "./explicit-resource-management/index.js";
|
|
4
4
|
export * from "./json.js";
|
|
5
5
|
export * from "./lazy.js";
|
|
6
|
-
export
|
|
6
|
+
export { freeze } from "./objects/freeze.js";
|
|
7
|
+
export { get } from "./objects/get.js";
|
|
8
|
+
export { set } from "./objects/set.js";
|
|
7
9
|
export * from "./parsers.js";
|
|
8
10
|
export * from "./processes.js";
|
|
9
11
|
export * from "./promises.js";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,9 @@ export * from "./event-emitter.js";
|
|
|
3
3
|
export * from "./explicit-resource-management/index.js";
|
|
4
4
|
export * from "./json.js";
|
|
5
5
|
export * from "./lazy.js";
|
|
6
|
-
export
|
|
6
|
+
export { freeze } from "./objects/freeze.js";
|
|
7
|
+
export { get } from "./objects/get.js";
|
|
8
|
+
export { set } from "./objects/set.js";
|
|
7
9
|
export * from "./parsers.js";
|
|
8
10
|
export * from "./processes.js";
|
|
9
11
|
export * from "./promises.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prevents the modification of existing property attributes and values on the value, and all of its child properties, and prevents the addition of new properties.
|
|
3
|
+
* @param value Value to freeze.
|
|
4
|
+
*/
|
|
5
|
+
export function freeze(value) {
|
|
6
|
+
if (value !== undefined && value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
7
|
+
Object.freeze(value);
|
|
8
|
+
Object.values(value).forEach(freeze);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the value at the specified {@link path}.
|
|
3
|
+
* @param source Source object that is being read from.
|
|
4
|
+
* @param path Path to the property to get.
|
|
5
|
+
* @returns Value of the property.
|
|
6
|
+
*/
|
|
7
|
+
export function get(source, path) {
|
|
8
|
+
const props = path.split(".");
|
|
9
|
+
return props.reduce((obj, prop) => obj && obj[prop], source);
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the specified `value` on the `target` object at the desired property `path`.
|
|
3
|
+
* @param target The target object that is being written to.
|
|
4
|
+
* @param path The path to the property to set.
|
|
5
|
+
* @param value The value to write.
|
|
6
|
+
*/
|
|
7
|
+
export declare function set(target: object, path: string, value: unknown): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const FORBIDDEN_PROP_NAMES = new Set(["", "__proto__", "prototype", "constructor"]);
|
|
2
|
+
/**
|
|
3
|
+
* Sets the specified `value` on the `target` object at the desired property `path`.
|
|
4
|
+
* @param target The target object that is being written to.
|
|
5
|
+
* @param path The path to the property to set.
|
|
6
|
+
* @param value The value to write.
|
|
7
|
+
*/
|
|
8
|
+
export function set(target, path, value) {
|
|
9
|
+
const props = path.split(".");
|
|
10
|
+
// Validate the path does not contain forbidden segments.
|
|
11
|
+
for (const prop of props) {
|
|
12
|
+
if (FORBIDDEN_PROP_NAMES.has(prop)) {
|
|
13
|
+
throw new Error(`Unsafe path segment "${prop}" in "${path}"`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Ensure there is a path to the value.
|
|
17
|
+
let curr = target;
|
|
18
|
+
for (let i = 0; i < props.length - 1; i++) {
|
|
19
|
+
const prop = props[i];
|
|
20
|
+
let value = Object.hasOwn(curr, prop) ? curr[prop] : undefined;
|
|
21
|
+
if (value === null || (typeof value !== "object" && typeof value !== "function")) {
|
|
22
|
+
defineProperty(curr, prop, (value = {}));
|
|
23
|
+
}
|
|
24
|
+
curr = value;
|
|
25
|
+
}
|
|
26
|
+
// Set the value.
|
|
27
|
+
defineProperty(curr, props[props.length - 1], value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Defines a property on the specified object.
|
|
31
|
+
* @param obj Object where the property will be defined.
|
|
32
|
+
* @param prop Property name.
|
|
33
|
+
* @param value Initial value.
|
|
34
|
+
*/
|
|
35
|
+
function defineProperty(obj, prop, value) {
|
|
36
|
+
Object.defineProperty(obj, prop, {
|
|
37
|
+
value,
|
|
38
|
+
writable: true,
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -5,9 +5,6 @@ import { z } from "zod/v4-mini";
|
|
|
5
5
|
export const JsonRpcRequest = z.object({
|
|
6
6
|
jsonrpc: z.literal("2.0"),
|
|
7
7
|
method: z.string(),
|
|
8
|
-
params: z.optional(z.union([
|
|
9
|
-
z.record(z.string(), z.any()),
|
|
10
|
-
z.array(z.any()),
|
|
11
|
-
])),
|
|
8
|
+
params: z.optional(z.union([z.record(z.string(), z.any()), z.array(z.any())])),
|
|
12
9
|
id: z.optional(z.string()),
|
|
13
10
|
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elgato/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Utilities used throughout the Elgato ecosystem.",
|
|
5
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"elgato"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/elgatosf/streamdeck/tree/main/packages/utils#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/elgatosf/streamdeck/issues"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "Elgato",
|
|
15
|
+
"url": "https://www.elgato.com"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/elgatosf/streamdeck.git"
|
|
20
|
+
},
|
|
6
21
|
"files": [
|
|
7
22
|
"./dist/"
|
|
8
23
|
],
|
|
24
|
+
"type": "module",
|
|
9
25
|
"exports": {
|
|
10
26
|
".": {
|
|
11
27
|
"types": "./dist/index.d.ts",
|
|
@@ -28,37 +44,18 @@
|
|
|
28
44
|
"default": "./dist/rpc/index.js"
|
|
29
45
|
}
|
|
30
46
|
},
|
|
31
|
-
"
|
|
32
|
-
|
|
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"
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"zod": "^3.25.24"
|
|
46
49
|
},
|
|
47
|
-
"homepage": "https://github.com/elgatosf/streamdeck/tree/main/packages/utils#readme",
|
|
48
50
|
"devDependencies": {
|
|
49
51
|
"@elgato/eslint-config": "^0.3.2",
|
|
50
|
-
"@elgato/prettier-config": "^0.3.3",
|
|
51
52
|
"@tsconfig/node20": "^20.1.5",
|
|
52
53
|
"@types/node": "^22.15.19",
|
|
53
54
|
"@vitest/coverage-v8": "^3.1.4",
|
|
54
55
|
"eslint": "^9.39.4",
|
|
55
|
-
"prettier": "^3.8.1",
|
|
56
56
|
"typescript": "^5.8.3",
|
|
57
57
|
"vitest": "^3.1.3"
|
|
58
58
|
},
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"zod": "^3.25.24"
|
|
61
|
-
},
|
|
62
59
|
"scripts": {
|
|
63
60
|
"build": "rm -rf dist/ && tsc --project tsconfig.build.json",
|
|
64
61
|
"dev": "tsc --project tsconfig.build.json --watch",
|
package/dist/objects.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prevents the modification of existing property attributes and values on the value, and all of its child properties, and prevents the addition of new properties.
|
|
3
|
-
* @param value Value to freeze.
|
|
4
|
-
*/
|
|
5
|
-
export declare function freeze<T>(value: T): void;
|
|
6
|
-
/**
|
|
7
|
-
* Gets the value at the specified {@link path}.
|
|
8
|
-
* @param source Source object that is being read from.
|
|
9
|
-
* @param path Path to the property to get.
|
|
10
|
-
* @returns Value of the property.
|
|
11
|
-
*/
|
|
12
|
-
export declare function get(source: unknown, path: string): unknown;
|
|
13
|
-
/**
|
|
14
|
-
* Sets the specified `value` on the `target` object at the desired property `path`.
|
|
15
|
-
* @param target The target object that is being written to.
|
|
16
|
-
* @param path The path to the property to set.
|
|
17
|
-
* @param value The value to write.
|
|
18
|
-
*/
|
|
19
|
-
export declare function set(target: any, path: string, value: unknown): void;
|
package/dist/objects.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prevents the modification of existing property attributes and values on the value, and all of its child properties, and prevents the addition of new properties.
|
|
3
|
-
* @param value Value to freeze.
|
|
4
|
-
*/
|
|
5
|
-
export function freeze(value) {
|
|
6
|
-
if (value !== undefined && value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
7
|
-
Object.freeze(value);
|
|
8
|
-
Object.values(value).forEach(freeze);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Gets the value at the specified {@link path}.
|
|
13
|
-
* @param source Source object that is being read from.
|
|
14
|
-
* @param path Path to the property to get.
|
|
15
|
-
* @returns Value of the property.
|
|
16
|
-
*/
|
|
17
|
-
export function get(source, path) {
|
|
18
|
-
const props = path.split(".");
|
|
19
|
-
return props.reduce((obj, prop) => obj && obj[prop], source);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Sets the specified `value` on the `target` object at the desired property `path`.
|
|
23
|
-
* @param target The target object that is being written to.
|
|
24
|
-
* @param path The path to the property to set.
|
|
25
|
-
* @param value The value to write.
|
|
26
|
-
*/
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
-
export function set(target, path, value) {
|
|
29
|
-
const props = path.split(".");
|
|
30
|
-
props.reduce((obj, prop, i) => {
|
|
31
|
-
return i === props.length - 1 ? (obj[prop] = value) : obj[prop] || (obj[prop] = {});
|
|
32
|
-
}, target);
|
|
33
|
-
}
|