freezly
Small utility for deeply freezing objects in JavaScript.
Table of Contents
Installation
npm
npm install freezly
yarn
yarn add freezly
Documentation
This project literally exports a single function which is used to deeply freeze any Javascript object. All nested arrays and objects become frozen, ensuring the entire object can't be mutated. This is primarily useful in functional programming, if you want to guarantee an object passed into a function isn't mutated by said function. However in practice deeply freezing objects comes with some amount of a performance cost so it is recommended to only deep freeze objects in a development environment and/or tests.
Below is an example of how to use freezly.
const frozenObject = // The following will throw an error as you can't mutate frozen objectsfrozenObjectbaz = 'spam' // Can't add properties to frozen objectfrozenObjectfoo // Can't push items to frozen array
Note: Once you freeze an object any attempts to mutate any part of the object will result in an error being thrown.
Code of Conduct
Please see the code of conduct.
Contributing
Please see the contributing guide.