`config.define` now propagates schema `default` values, so features like smart quotes no longer need their own fallback constants. Adds `defineCategory` / `getCategories` for the upcoming configuration manager UI.
35 lines
916 B
TypeScript
35 lines
916 B
TypeScript
/**
|
|
* Deep-clone a value, replacing any functions with null.
|
|
* Needed because values containing functions can't be serialized
|
|
* via postMessage or validated with JSON Schema.
|
|
*/
|
|
export function stripFunctions(value: any): any {
|
|
if (typeof value === "function") return null;
|
|
if (value === null || value === undefined || typeof value !== "object") {
|
|
return value;
|
|
}
|
|
if (Array.isArray(value)) {
|
|
return value.map(stripFunctions);
|
|
}
|
|
const result: Record<string, any> = {};
|
|
for (const key of Object.keys(value)) {
|
|
result[key] = stripFunctions(value[key]);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Checks if an object is sendable across the plugos worker boundary.
|
|
*
|
|
* @param o - The object to check.
|
|
* @returns `true` if the object is sendable, `false` otherwise.
|
|
*/
|
|
export function isSendable(o: any): boolean {
|
|
try {
|
|
structuredClone(o);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|