deep-unfreeze
v0.1.1
Published
Unfreezes a JavaScript object/array/function etc. that has previously been frozen, by doing a deep copy.
Downloads
1,425
Maintainers
Readme
deep-unfreeze
Unfreeze a JavaScript object/array/function that has previously been frozen (and deeply frozen) with Object.freeze, by doing a copy.
Usage
import deepUnfreeze from 'deep-unfreeze';
let subject,
result;
subject = {};
Object.freeze(subject);
// Doesn't add the property.
// subject.lorem = 'LOREM';
result = deepUnfreeze(subject);
result.lorem = 'LOREM';
import deepUnfreeze from 'deep-unfreeze';
let subject,
result;
subject = [];
Object.freeze(subject);
// Throws an error.
// subject.push('LOREM');
result = deepUnfreeze(subject);
result.push('LOREM');
import deepUnfreeze from 'deep-unfreeze';
let subject,
result;
subject = function() {
};
Object.freeze(subject);
Object.freeze(subject.prototype);
// This won't work.
// subject.prototype.sayLorem = function() { console.log('LOREM'); };
// new subject().sayLorem() // TypeError: (intermediate value).sayIpsum is not a function
result = deepUnfreeze(subject);
result.prototype.sayIpsum = function() { console.log('IPSUM'); };
// new result().sayIpsum() // "IPSUM"
Download
Download using NPM:
npm install deep-unfreeze
Tests
Run unit tests (check that all dependencies are installed):
npm install && npm run test