Skip to content

rubeniskov/optree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Plain Object path tree generator

Resources

License

Stars

Watchers

Forks

Packages

No packages published