deep-freeze-plus
v1.1.4
Published
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
Downloads
503
Maintainers
Readme
deep-freeze-plus
A fast and efficient implementation of the deepFreeze function for freezing JavaScript objects and arrays without recursion. Supports all primitive types, objects, arrays, Maps, Sets, and other complex data structures.
Installation
To install deep-freeze-plus using npm:
npm install deep-freeze-plus
To install deep-freeze-plus using yarn:
yarn add deep-freeze-plus
Usage
To use deep-freeze-plus in your project, simply import the deepFreeze
function and pass in the object or array you want to freeze:
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
Contributing
We welcome contributions to deep-freeze-plus! If you find a bug or have a feature request, please open an issue or submit a pull request.
Before contributing, please review the contributing guidelines.