rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
29 lines (28 loc) • 1.08 kB
text/typescript
/**
* Utility functions for working with JSON in CLI output
*/
/**
* Attempt to extract the last JSON object or array from a string by
* first finding closing braces/brackets and then matching them to their
* opening counterparts.
*
* @param output - The string to parse
* @returns JSON object or null if invalid
*/
export declare function extractLastJson(output: string | undefined): any;
/**
* Extract all valid JSON objects or arrays from a string
*
* @param input - The string that might contain multiple JSON objects
* @returns Array of parsed JSON objects
*/
export declare function extractAllJson(input: string | undefined): any[];
/**
* Safely parses JSON from a string that might include other content
*
* @param input - The string that might contain JSON
* @param defaultValue - Default value to return if no JSON is found
* @param findUuid - If true, look for an object with a uuid property
* @returns The parsed JSON or the default value
*/
export declare function parseJson<T>(input: string | undefined, defaultValue: T, findUuid?: boolean): T;