@springworks/frozen-json
v3005.261.0
Published
Recursively freeze JSON data structures
Downloads
877
Readme
@springworks/frozen-json
Recursively freeze JSON data structures.
yarn add @springworks/frozen-json
Usage
freezeDeep<T extends JsonValue>(value: T): ReadonlyDeep<T>
Recursively freeze the data structure passed in. Like Object.freeze()
but recursively.
import { freezeDeep, parseJsonFrozen } from '@springworks/frozen-json';
freezeDeep({ a: { b: 1 } });
// -> { readonly a: { readonly b: 1 } }
parseJsonFrozen(json: string): ReadonlyDeep<JsonValue>
Pase a string as JSON. This will call JSON.parse()
with a reviver function. The reviver function will then call Object.freeze()
on each leaf node as it is being parsed.
import { freezeDeep, parseJsonFrozen } from '@springworks/frozen-json';
parseJsonFrozen('{"a":{"b":1}}');
// -> { readonly a: { readonly b: 1 } }