Take a nested Javascript object and flatten it. Modified to not traverse into domains.
Installation
$ npm install @contrast/flat
Methods
flatten(original, options)
Flattens the object - it'll return an object one level deep, regardless of how
nested the original object was (will not traverse into domains stored on the object):
const flatten = require('flat');
flatten({
key1: {
keyA: 'valueI'
},
key2: {
keyB: 'valueII'
},
key3: { a: { b: { c: 2 } } }
});
Options
delimiter
Use a custom delimiter for (un)flattening your objects, instead of .
.
safe
When enabled, flat
will preserve arrays and their
contents. This is disabled by default.
const flatten = require('flat');
flatten({
this: [
{ contains: 'arrays' },
{ preserving: {
them: 'for you'
}}
]
}, {
safe: true
});