1.0.2 • Published 7 months ago

deep-freeze-utility v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Deep Freeze Utility

A lightweight TypeScript utility for deeply freezing nested objects and arrays.

Installation

npm install deep-freeze-utility

Usage

import { deepFreeze } from 'deep-freeze-utility';

const obj = {
  name: 'Example',
  details: {
    age: 30,
    address: {
      city: 'Wonderland'
    }
  }
};

const frozenObj = deepFreeze(obj);

// Now the entire object and all its nested properties are immutable
console.log(Object.isFrozen(frozenObj)); // true
console.log(Object.isFrozen(frozenObj.details)); // true

Features

  • Recursively freezes nested objects and arrays
  • Preserves type information
  • Handles already frozen objects efficiently
  • Works with complex nested structures

API

deepFreeze<T>(obj: T): Readonly<T>

Deeply freezes the given object, making it and all its nested properties immutable.

  • obj: The object to freeze
  • Returns: A frozen version of the input object

License

MIT

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago