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.