export type TGetJSONFromStrArgs = Parameters; export type TGetJSONFromStrReturn = ReturnType; /** * Safely parses a JSON string. * * @template T * @param {string} str Source string to parse * @param {(this: any, key: string, value: any) => any} [reviver] Optional reviver function * @param {(err: unknown) => void} [onError] Optional error callback * @returns {T | Record} Parsed object or empty object on error * @throws {TypeError} getJSONFromStr: str must be a string * @throws {TypeError} getJSONFromStr: reviver must be a function if provided * @throws {TypeError} getJSONFromStr: onError must be a function if provided * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse * @example * // How to convert string to JSON? * const json = getJSONFromStr<{ hello: string }>('{"hello":"world"}'); * console.log(json.hello); // => "world" * @example * // Parse cached application settings and report malformed JSON * const settings = getJSONFromStr( * localStorage.getItem("settings") ?? "{}", * undefined, * (error) => reportInvalidSettings(error) * ); */ export declare const getJSONFromStr: (str: string, reviver?: (this: any, key: string, value: any) => any, onError?: (err: unknown) => void) => T | Record;