Object Freezer
The purpose of this module is to freeze an object and all its nested objects. What differentiates this project from others, such as deep-freeze and deep-freeze-strict, is the ability to flag specific nested objects as antifreeze to avoid freezing.
Disclaimer
This is not a new idea or a common need. The project originated from a single very specific use case. Your chances of needing this module are slim.
Installation
npm install object-freezer --save
Use Strict
Object.freeze() is the method used to freeze the objects. It is highly recommended to use strict mode. With strict mode, frozen objects will throw an TypeError on a change attempt. Without strict mode, frozen objects silently ignore changes.
Examples
The following is a basic example of how to deepFreeze
an object and what happens when changes are attempted.
'use strict';; const frozen = ; frozenint = 2017; // throws a TypeErrorfrozenstr = 'sample'; // throws a TypeErrorfrozenarr = 1 ; // throws a TypeErrorfrozenobj = {}; // throws a TypeError
The following is an example of how to antiFreeze
nested objects to avoid a deepFreeze
.
'use strict';; const frozen = ; frozenobj = {}; // success!