UNPKG

@zsnout/ithkuil

Version:

A set of tools which can generate and parse romanized Ithkuil text and which can generate Ithkuil script from text and JSON data.

41 lines (40 loc) 1.4 kB
import {} from "./with-wy-alternative.js"; /** * Deeply freezes a value. This prevents properties from being added, removed, * or changed, and deeply freezes all values of the object. For arrays, elements * will be deeply frozen. * * No other values (such as `Set`s and `Map`s) are treated specially, as this * project does not use them. * * @param value The value to be deeply frozen. * @returns A reference to the original value, now deeply frozen. */ export function deepFreeze(value) { if (value && typeof value == "object") { Object.freeze(value); Object.values(value).forEach(deepFreeze); } return value; } /** * Deeply freezes a value. This prevents properties from being added, removed, * or changed, and deeply freezes all values of the object. For arrays, elements * will be deeply frozen. * * In addition, all objects in the tree will have their prototypes removed. * * No other values (such as `Set`s and `Map`s) are treated specially, as this * project does not use them. * * @param value The value to be deeply frozen. * @returns A reference to the original value, now deeply frozen. */ export function deepFreezeAndNullPrototype(value) { if (value && typeof value == "object") { Object.setPrototypeOf(value, null); Object.freeze(value); Object.values(value).forEach(deepFreeze); } return value; }