UNPKG

@stryke/json

Version:

A package containing JSON parsing/stringify utilities used by Storm Software.

60 lines (59 loc) 2.29 kB
import { Class, JsonParseOptions, JsonParserResult, JsonSerializeOptions, JsonValue } from "./types.mjs"; import { SuperJSON } from "superjson"; //#region src/storm-json.d.ts /** * A static JSON parser class used by Storm Software to serialize and deserialize JSON data * * @remarks * This class uses the [SuperJSON](https://github.com/blitz-js/superjson) library under the hood. */ declare class StormJSON extends SuperJSON { #private; static get instance(): StormJSON; /** * Deserialize the given value with superjson using the given metadata */ static deserialize<TData = unknown>(payload: JsonParserResult): TData; /** * Serialize the given value with superjson */ static serialize(object: JsonValue): JsonParserResult; /** * Parse the given string value with superjson using the given metadata * * @param value - The string value to parse * @returns The parsed data */ static parse<TData = unknown>(value: string, options?: JsonParseOptions): TData; /** * Serializes the given data to a JSON string. * By default the JSON string is formatted with a 2 space indentation to be easy readable. * * @param value - Object which should be serialized to JSON * @param options - JSON serialize options * @returns the formatted JSON representation of the object */ static stringify<T>(value: T, options?: JsonSerializeOptions): string; /** * Register a custom schema with superjson * * @param name - The name of the schema * @param serialize - The function to serialize the schema * @param deserialize - The function to deserialize the schema * @param isApplicable - The function to check if the schema is applicable */ static register<TData = any, TJsonObject extends JsonValue = JsonValue>(name: string, serialize: (data: TData) => TJsonObject, deserialize: (json: TJsonObject) => TData, isApplicable: (data: any) => data is TData): void; /** * Register a class with superjson * * @param classConstructor - The class constructor to register */ static registerClass(classConstructor: Class, options?: { identifier?: string; allowProps?: string[]; } | string): void; private constructor(); } //#endregion export { StormJSON }; //# sourceMappingURL=storm-json.d.mts.map