@akala/core
Version:
28 lines • 868 B
JavaScript
/**
* A formatter that converts values to and from JSON strings. Useful for serializing/deserializing data structures.
*/
export default class Json {
settings;
constructor(settings) {
this.settings = settings;
}
/**
* Converts a value to a JSON string using default serialization.
* @template T - The type of the input value.
* @param {T} value - The value to serialize.
* @returns {string} JSON string representation of the value.
*/
format(value) {
return JSON.stringify(value, null, this.settings?.space);
}
/**
* Parses a JSON string into its original data structure.
* @param {string} value - The JSON string to deserialize.
* @returns {T} The parsed object/array value.
*/
unformat(value) {
return JSON.parse(value);
}
}
;
//# sourceMappingURL=json.js.map