Skip to content

tiaanduplessis/freezo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

freezo

Deeply freeze/thaw a array or object



Built with ❤︎ by tiaanduplessis and contributors

Table of Contents

Table of Contents
  • Install
  • Usage
  • Contribute
  • License
  • Install

    $ npm install @tiaanduplessis/freezo
    # OR
    $ yarn add @tiaanduplessis/freezo

    Usage

    import { freeze, thaw } from '@tiaanduplessis/freezo'
    
    const frozenArr = freeze([1, 2, 3, { foo: 1, bar: 2 }, 5])
    const frozenObj = freeze({ foo: 1, bar: 2, baz: { foo: 1, bar: 2 } })
    
    console.log(Object.isFrozen(frozenArr)) // true
    console.log(Object.isFrozen(frozenArr[3])) // true
    console.log(Object.isFrozen(frozenObj)) // true
    console.log(Object.isFrozen(frozenObj.baz)) // true
    
    const unfrozenArr = thaw(frozenArr)
    const unfrozenObj = thaw(frozenObj)
    
    console.log(Object.isFrozen(unfrozenArr)) // false
    console.log(Object.isFrozen(unfrozenArr[3])) // false
    console.log(Object.isFrozen(unfrozenObj)) // false
    console.log(Object.isFrozen(unfrozenObj.baz)) // false

    Contributing

    Contributions are welcome!

    1. Fork it.
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request :D

    Or open up a issue.

    License

    Licensed under the MIT License.