Files
plainleaf/client/plugos/util.ts
T
Zef Hemel 0c9c07b3e6 Config: schema defaults, UI categories and annotations
`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.
2026-04-21 10:03:40 +02:00

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;
}
}