Small utility for deeply freezing objects in JavaScript.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
src
.babelrc.js
.eslintrc.js
.flowconfig
.gitignore
.pr-bumper.json
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.md
jest.config.js
package.json
yarn.lock

README.md

freezly NPM Coverage

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.

import deepFreeze from 'freezly'

const frozenObject = deepFreeze({
  foo: ['bar'],
})

// The following will throw an error as you can't mutate frozen objects
frozenObject.baz = 'spam' // Can't add properties to frozen object
frozenObject.foo.push('baz') // 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.

License

MIT