normalize-object-inheritance
v1.0.1
Published
Normalize all values of an object recursively, making sure there are no [Object: null prototype] objects.
Downloads
1
Maintainers
Readme
Normalize object
A small recursive library which makes sure that all objects are an instance of the Object class.
Some libraries do not provide interoperability by returning arrays with completely empty objects (no toString()
or keys()
or hasOwnProperty()
functions) which most libraries cannot deal with.
You do not need this library
The following line fixes this problem as well: obj = JSON.parse(JSON.stringify(obj))
However this is ~20% slower than this library because it does not work in place and take cpu to serialize the object, which is not actually what we want.
Usage
import normalizeObject from 'normalizeObject';
obj = normalizeObject(obj);
To be able to normalize the root object, in case it is a null type object, it is needed to reassign the value to the output of the function. If you are 100% sure the root object will not be a null type object this is not needed.