mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 20:05:46 -06:00
964c8c84c1
* refactor: consolidate coercion ownership Centralize four canonical coercion helpers, migrate exact core and plugin duplicates through narrow Plugin SDK facades, and enforce declaration and plugin-normalization ownership boundaries. The sweep adds eight focused SDK exports while deleting more production and tooling code than it adds. User-visible behavior is unchanged except for safer equivalent object and UI parsing at existing boundaries. * fix: guard integer option ownership Register resolveIntegerOption with the canonical function owner and extend the declaration-guard fixture so future local duplicates fail validation. * fix: keep integer helpers on numeric facade Remove the unshipped duplicate string-coerce exports and route every affected plugin consumer through the existing number-runtime contract. * fix: point numeric coercion to number runtime Make boundary and declaration diagnostics recommend the canonical numeric facade, with failing-before coverage for both guidance paths.
16 lines
507 B
TypeScript
16 lines
507 B
TypeScript
import { asOptionalRecord } from "./record-coerce.js";
|
|
|
|
/** Parses JSON without throwing, returning undefined for invalid input. */
|
|
export function safeParseJson(value: string): unknown {
|
|
try {
|
|
return JSON.parse(value) as unknown;
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
/** Parses JSON into a non-array record, returning undefined for every other result. */
|
|
export function safeParseJsonRecord(value: string): Record<string, unknown> | undefined {
|
|
return asOptionalRecord(safeParseJson(value));
|
|
}
|