Fixd is a JavaScript library for creating reference-free, immutable (frozen) objects. It supports immutability on all native types, including deeply nested objects and arrays.
The use-case Fixd was built around is "locking" reusable fixtures to prevent mutations, an in-turn, side-effects during testing.
npm i fixd --save
'use strict'constfixd=require('fixd')// Add a new objectfixd.foo={fizz: 'buzz',baz: {quz: 'baz'}}// Access objectfixd.foo// -> { fizz: 'buzz', baz: { quz: 'baz' }}// Throws error, prevents mutationsfoo.fizz='bazz'// -> ERROR: Cannot assign to read only propertyNote: While Object.freeze will prevent modifications, use strict must be applied to the document in order to throw an error on attempted mutation.
Because the objects are frozen, Fixd provides the create method for returning a new, modified instance.
fixd.create('foo',(foo)=>{foo.fizz='bazz'returnfoo})// -> { fizz: 'bazz', baz: { quz: 'baz' }}The above will not modify the foo object, it will return a new, reference-free, frozen instance of the object based on the modification performed in the callback.
The prefered dependency manager for Fixd is Yarn. To run tests, execute the following after dependencies have been installed:
yarn test
Fixd is developed and maintained by TechnologyAdvice and released under the ISC license.