0.1.3 • Published 8 years ago
optree v0.1.3
Optree
Optree is a function thats provide a plain object with the tree path of properties and their own values.
Motivation
Sometimes, you need simplify a complex JSON structure to compare objects or iterate several times, so this method provides a flatten object to make easier the access to values. it's really usefull when you want compare two objects without nested child.
Installation
Install with npm install optree --save
.
Usage
To use, add the require
node module:
const optree = require('optree');
const json = {
'foo': [
'apple',
'pear'
],
'bar': {
'apple': 0,
'pear': 1
},
'first': {
'second': {
'third': 'last'
}
}
};
const foo = optree(json),
bar = optree(json, true);
console.log(foo);
/******
{
"foo": ['apple', 'pear'],
"bar.apple": '0',
"bar.pear": '1',
"first.second.third": 'last'
}
*******/
console.log(bar);
/******
{
"foo.0": 'apple',
"foo.1": 'pear',
"bar.apple": '0',
"bar.pear": '1',
"first.second.third": 'last'
}
*******/