@dfinity/utils
Version:
A collection of utilities and constants for NNS/SNS projects.
30 lines (29 loc) • 1.36 kB
TypeScript
/**
* A custom replacer for `JSON.stringify` that converts specific types not natively supported
* by the API into JSON-compatible formats.
*
* Supported conversions:
* - `BigInt` → `{ "__bigint__": string }`
* - `Principal` → `{ "__principal__": string }`
* - `Uint8Array` → `{ "__uint8array__": number[] }`
*
* @param {string} _key - Ignored. Only provided for API compatibility.
* @param {unknown} value - The value to transform before stringification.
* @returns {unknown} The transformed value if it matches a known type, otherwise the original value.
*/
export declare const jsonReplacer: (_key: string, value: unknown) => unknown;
/**
* A custom reviver for `JSON.parse` that reconstructs specific types from their JSON-encoded representations.
*
* This reverses the transformations applied by `jsonReplacer`, restoring the original types.
*
* Supported conversions:
* - `{ "__bigint__": string }` → `BigInt`
* - `{ "__principal__": string }` → `Principal`
* - `{ "__uint8array__": number[] }` → `Uint8Array`
*
* @param {string} _key - Ignored but provided for API compatibility.
* @param {unknown} value - The parsed value to transform.
* @returns {unknown} The reconstructed value if it matches a known type, otherwise the original value.
*/
export declare const jsonReviver: (_key: string, value: unknown) => unknown;