optree

0.1.3 • Public • Published

Optree

Build Status Coverage Status Climate Status Issues Open Issue Resolution

Version Node Downloads Slack Status License

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.

NPM GRID

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'
    }
    *******/
 

WTF

Readme

Keywords

none

Package Sidebar

Install

npm i optree

Weekly Downloads

2

Version

0.1.3

License

none

Last publish

Collaborators

  • rubeniskov