Skip to content

advanced handler for js object with unknown structures

Notifications You must be signed in to change notification settings

Mdhaker/object-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Object handler

This package is made to handle JS objects without knowing their structure, you perform actions such assign, getting and setting values without knowing their paths.

1.1.1

Install

npm i anonymous-object-handler

Usage

var aoh = require('anonymous-object-handler');
let obj = {
   "key1":{
      "key11":{
         "key111":"foo",
         "key112":"bar"
      },
      "key12":"lorem"
   },
   "key2":"value2",
   "key3":"value3"
};

aoh.getValueByPath(obj,"key1.key11.key112")  // returns "bar"

aoh.setValueBypath(obj,"key1.key11.key113.key1131","baz"); 
/** return
{
   "key1":{
      "key11":{
         "key111":"foo",
         "key112":"bar",
         "key113" : {
             "key1131" : "baz"
         }
      },
      "key12":"lorem"
   },
   "key2":"value2",
   "key3":"value3"
};
**/
let obj2 = {
   "key1":{
      "key11":{
         "key111":"foo",
         "key112":"baz",
         "key113" : {
             "key1131" : {"key11311":"value11311"}
         }
      }
};

aoh.deepAssign(obj,obj2);
/** return
{
   "key1":{
      "key11":{
         "key111":"foo",
         "key112":"baz",
         "key113" : {
             "key1131" : {"key11311":"value11311"}
         }
      },
      "key12":"lorem"
   },
   "key2":"value2",
   "key3":"value3"
};
**/

/** This is the key function to all the package **/

aoh.mapObject(obj);
/** return
{
   "key1.key11.key111":"foo",
   "key1.key11.key112":"bar",
    "key1.key12":"lorem",
    "key2":"value2",
    "key3":"value3"
};
**/
aoh.unMapObject(obj);
/**
return the same obj structure mentioned before
**/

License

MIT

About

advanced handler for js object with unknown structures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published