Freeze-Mutate: An Immutable Object Management Library for JS and TS

I was looking for a nice little module that would help me make my DTOs immutable. The libraries I found were either an overkill (immutable.js), lacking support for deep merging of objects during mutations, or they were making my code ugly with lots of function calls for each change. So that’s how freeze-mutate came to life: a Javascript/Typescript-based npm module that helps me keep things simple and neat.

Freeze any object and it becomes deeply-immutable: all its properties and child-objects are frozen in the process. This is done by recursively calling JavaScript’s native Object.freeze.
Mutate a frozen object with a change-set and you get a new frozen object that is a merge, or an overlay, of the change-set on top of the original object. Again, this is a deep-merge that also you to works with Arrays, Sets, Maps, and your own custom classes. For the brave: you can provide custom freeze and merge functions.
Using TypeScript you get all the goodies of generics, enforcing the validity of the change-set, Readonly returned types and interfaces for the custom functions.

Enough talking. Let’s dive in…