UNPKG

deep-freeze-plus

Version:

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

50 lines (34 loc) 1.8 kB
# deep-freeze-plus [![npm version](https://badge.fury.io/js/deep-freeze-plus.svg)](https://badge.fury.io/js/deep-freeze-plus) [![npm downloads](https://img.shields.io/npm/dt/deep-freeze-plus.svg)](https://www.npmjs.com/package/deep-freeze-plus) [![Build Status](https://travis-ci.org/example/deep-freeze-plus.svg?branch=master)](https://travis-ci.org/example/deep-freeze-plus) [![Coverage Status](https://coveralls.io/repos/github/example/deep-freeze-plus/badge.svg?branch=master)](https://coveralls.io/github/example/deep-freeze-plus?branch=master) 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: ```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 ``` ## 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](https://chat.openai.com/CONTRIBUTING.md).