Create objects that can be freezed and un-freezed
npm i @bellisario/icecube
import { IceCube } from '@bellisario/icecube';
const obj = new IceCube({ test: true });
obj.test; // returns true
obj.test = false; // throws an error
obj.iced = false; // disables freezing
obj.test = false; // succeeds
obj.test; // false
Creates a new instance of the IceCube
class.
Returns an usable object that can be freezed/un-freezed.
Type: object
The object to be freezed. Can also be an array.
Type: object
Required: false
Initialization options.
Type: boolean
Default: true
If true
, the object will be freezed when created.
If false
, the object will not be freezed when created and can be edited.
Type: object
The object that can be freezed/un-freezed.
- iced:
boolean
Default: specified by the usericed
option
Controls whether or not the object is frozen.
Edit this property to freeze/un-freeze the object.
Since I started learning JavaScript, I noticed that freezing objects will not allow you to un-freeze them later, this is very useful in certain situations, but some others you just want to prevent the user from editing the object now, but allow them to edit it later...
So I created this library to solve this problem.
You can see on the source code of the library that I used Proxy to "watch" the object, then allow editing (or throw an error) by looking for the iced
property (which is instead always editable).
We ❤️ contributions!
Feel free to open an issue or a pull request but follow Contributing Guidelines.
Tip: if you don't know where to start, check out the help wanted issues!
MIT License here.
Ice Cube original image from vexels.com