The object to be deeply frozen is expected to be a key-value pair object, where the keys are strings and the values can be anything.
Return the object after deep freezing, keeping the same type.
This function performs a deep freeze on the object and all its nested properties. It also mutates the original object (frozen in place).
import { deepFreeze } from '@selize/utils';
const obj = {
list: [1, 2, { nested: new Set([3, 4]) }],
meta: new Map([['version', 1]]),
};
const frozen = deepFreeze(obj);
frozen.list[2].nested.add(5); // Output: TypeError: Cannot modify a frozen object
frozen.meta.set('version', 2); // Output: TypeError: Cannot modify a frozen object
Deep freeze an object, making it and its nested objects immutable.