An ultra-fast and efficient library for deeply freezing JavaScript objects and preventing unintended mutations. Supports all data types, including complex objects like maps and sets, and guarantees immutability without recursion. Ideal for applications th
npm install deep-freeze-plusnpm install deep-freeze-plus
yarn add deep-freeze-plus
deepFreeze function and pass in the object or array you want to freeze:
javascript
const { deepFreeze } = require('deep-freeze-plus');
const obj = {
a: 1,
b: {
c: 2,
d: [3, 4],
e: new Set([5, 6, 7]),
f: new Map([['foo', 'bar'], ['baz', 'qux']]),
},
};
deepFreeze(obj);
obj.a = 100; // Throws an error
obj.b.c = 200; // Throws an error
obj.b.d[0] = 300; // Throws an error
obj.b.e.add(8); // Throws an error
obj.b.f.set('hello', 'world'); // Throws an error
``