Nukem's Possible Manifestation

    object-traversed
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.6 • Public • Published

    #Object Traversed

    Build Status view on npm Software License npm npm

    A very simple, lightweight utility on traversing object graphs using a string.

    How to use

    npm install --save object-traversed
    
    yarn add  object-traversed
    

    If using via normal javascript include, then it is exported as window.objectTraverse.

    API

    var traversed = require('object-traversed');
    
    var graph = {  
       field : {
          deep : {
             x : 1,
             y: 2
          }
       },
       field2: [],
       deepFunc : { someFunc: function(arg) {} }
       
    };
    //get a value
    traversed(graph).get('field.deep');
    //get with a default
    traversed(graph).get('field.deep','default return val if not found'); 
    
    //check if something is defined
    traversed(graph).has('field.deep.missing');
    
    //sets a value
    traversed(graph).set('field.deep.z',5);
       
    //helpers
    traversed(graph).isArray('field2');
    traversed(graph).isString('field2');
    traversed(graph).isObject('field2');
    traversed(graph).isNumber('field2');
              
    //exec
    traversed(graph).exec('deepFunc.someFunc','arg');         
    
    //delete
    traversed(graph).delete('field.deep.x');
    
    //push - add vall to the array, will create if it doesn't exists
    traversed(graph).push('a.b.c',val);
    
    //create create the given path if it doesn't exists, will skip none object types
    traversed(graph).create('a.b.c');
    traversed(graph).get('a.b.c'); //{ a : { b : { c: {} } }

    🔑 License

    MIT © ChantouchSek

    Install

    npm i object-traversed

    DownloadsWeekly Downloads

    22

    Version

    0.0.6

    License

    MIT

    Unpacked Size

    21.2 kB

    Total Files

    12

    Last publish

    Collaborators

    • chantouchsek