is-deep-frozen

check if an object or function is deeply frozen

Usage no npm install needed!

<script type="module">
  import isDeepFrozen from 'https://cdn.skypack.dev/is-deep-frozen';
</script>

README

is-deep-frozen? npm version Build Status

dkconfused.png

The question that has plagued monkey-kind and human-kind for millions of years. 🙉🙊🙈

About:

Find out if your javascript object, function, or class is deeply frozen.

What this module checks:
  1. This module checks that any object, function, or class you input, or any object, function, or class that is inside your input value will be frozen.

  2. If your Node version is greater or equal to 6, this module checks that any buffers you input, or any buffers inside your input value are sealed (buffers cannot be frozen).

Note: Primitive javascript types (e.g. string or number) are considered to be frozen in this module.

If you want to deeply freeze your objects, you can use the following:
  1. subzero
  2. deep-freeze
  3. immutablejs

install:

npm install is-deep-frozen

usage:

'use strict';

const isDeepFrozen = require( 'is-deep-frozen' );


const o = Object.freeze({ xxx: 69 });

const passingResult = isDeepFrozen( o );

// passingResult will be {}, indicating o is deeply frozen


const f = function() {};

f.a = Object.freeze({ b: {} });

const failingResult = isDeepFrozen( f );

// failingResult.notDeeplyFrozen will be set to true

console.log( failingResult.error );

/*
    the resulting log is:

    { NotDeeplyFrozenError: property: inputValue, value: function () {}
        property: inputValue[ "prototype" ], value: {}
        property: inputValue[ "a" ][ "b" ], value: {}
            at isDeepFrozen (/Users/test_dir/index.js:20:23)
            ...
    }
*/