Skip to content

Create a nested object easily using object path key format in JavaScript.

License

Notifications You must be signed in to change notification settings

CodeCrunchIO/objectree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ObjecTree

Install

1. Development

<script type="text/javascript" src="objectree.js"></script>

2. Production

<script type="text/javascript" src="objectree.min.js"></script>

Basic Usage

Manually creating complex deep object structure is tedious, ObjecTree makes it easy for us using "." dot separated path to create object tree given it's value.

Figure 1. Initialization

var object = ObjecTree([object...]);

NOTE Parameter in initialization is an optional existing object.

Figure 2. Creating a path and Getting it's value

var structure = object
.set('query.bool.term.user', 'Charles')
.set('filter', [{ user : 'charles' }])
.add('filter', { user : 'richard' });

// get the specific path
var user = structure.get('query.bool.term.user');
// get the entire object
var structure = structure.get();

OUTPUT

{
    "query" : {
        "bool" : {
            "term" : {
                "user" : "Charles"
            }
        }
    },
    "filter" : [
        {
            "user" : "charles"
        },
        {
            "user" : "richard"
        }
    ]
}

License

MIT

About

Create a nested object easily using object path key format in JavaScript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published