Code Monkey home page Code Monkey logo

freezly's Introduction

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

freezly's People

Stargazers

 avatar

Watchers

 avatar  avatar

freezly's Issues

Wire up to CI

Get continuous integration setup to automatically bump version and append to changelog on pull requests merges. Also need to run tests before allowing pull requests to be merged and verify coverage doesn't drop.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.