flat-wrap
v1.0.2
Published
Flattening/unflattening nested objects without losing keys for blank objects / empty arrays
Downloads
5
Maintainers
Readme
flat-wrap
Flattening/unflattening nested objects without losing keys for blank objects / empty arrays
Installation
$ npm install flat-wrap
The catch
A manual updation on the flatten/unflatten logic to mark empty objects ({}) and empty arrays([]) while flattening and replacing them with appropriate values upon unflattening
Methods
flatten(original, options)
Flattens the object - it'll return an object one level deep, regardless of how nested the original object was:
const { flatten } = require('flat-wrap')
flatten({
key1: {
keyA: 'valueI'
},
key2: {
keyB: 'valueII'
},
key3: { a: { b: { c: 2 } } }
})
// {
// 'key1.keyA': 'valueI',
// 'key2.keyB': 'valueII',
// 'key3.a.b.c': 2
// }
unflatten(original, options)
const { unflatten } = require('flat-wrap');
unflatten({
'three.levels.deep': 42,
'three.levels': {
nested: true
}
})
// {
// three: {
// levels: {
// deep: 42,
// nested: true
// }
// }
// }
Options
delimiter
Use a custom delimiter for (un)flattening your objects, instead of .
.