Skip to content

FronterAS/fm-object-path-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fng-object-path-utils

A stripped down version of chaijs libraries to give both front and backend path parse and value retrieval functionality without having to compile libraries with Browserify etc.

Usage

As with chaijs (and filtr which uses the same code), usage is a string path to the desired property.

var data = {
    nested: [
        {'body': 'foobar'}
    ]
};

ObjectPathUtils.getValue('nested[0].body', data);
// 'foobar'

Compatibility

Module written to work in nodejs, vanilla frontend and angularjs.

Vanilla

<script src="fm-object-path-utils.js"></script>
<script>
    var data = {
        nested: [
            {'body': 'foobar'}
        ]
    };

    ObjectPathUtils.getValue('nested[0].body', data);
    // 'foobar'
</script>

NodeJS

var ObjectPathUtils = require('./fm-object-path-utils'),

    data = {
        nested: [
            {'body': 'foobar'}
        ]
    };

ObjectPathUtils.getValue('nested[0].body', data);
// 'foobar'

AngularJS

angular.module('myApp', ['fng.utils.object.path'])
    .controller(function (ObjectPathUtils) {
        var data = {
            nested: [
                {'body': 'foobar'}
            ]
        };

        ObjectPathUtils.getValue('nested[0].body', data);
        // 'foobar'
    });

About

Object path value retrieval by string

Resources

License

Stars

Watchers

Forks

Packages

No packages published