deep-unfreeze

0.1.1 • Public • Published

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

Package Sidebar

Install

npm i deep-unfreeze

Weekly Downloads

302

Version

0.1.1

License

MIT

Unpacked Size

8.87 kB

Total Files

5

Last publish

Collaborators

  • vicsstar