MCPcopy Create free account
hub / github.com/tiann/hapi / parseMaybeJson

Function parseMaybeJson

cli/src/opencode/opencodeLocalLauncher.ts:45–61  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

43}
44
45function parseMaybeJson(value: unknown): unknown {
46 if (typeof value !== 'string') {
47 return value;
48 }
49 const trimmed = value.trim();
50 if (!trimmed) {
51 return value;
52 }
53 if ((trimmed.startsWith('{') && trimmed.endsWith('}')) || (trimmed.startsWith('[') && trimmed.endsWith(']'))) {
54 try {
55 return JSON.parse(trimmed);
56 } catch {
57 return value;
58 }
59 }
60 return value;
61}
62
63function getNumber(value: unknown): number | null {
64 if (typeof value === 'number' && Number.isFinite(value)) {

Callers 2

parseToolCallFunction · 0.85
handleHookEventFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected