@aercolino/object-paths

0.1.0 • Public • Published

Object Paths Build Status Coverage Status

Find all nodes of a tree object whose values match a regular expression and get their paths from the root as a list of keys separated by dots.

Installation

$ npm install @aercolino/object-paths

Example

const { selectPaths } = require('@aercolino/object-paths');

const someObject = {
    a: {
        b: {
            c: [
                {
                    d: 123,
                    e: 456
                }
            ],
            h: 'hello'
        },
        f: 23,
        g: 45
    },
    j: 'world'
};

selectPaths(someObject); 
// [ 'a.b.c.0.d', 'a.b.c.0.e', 'a.b.h', 'a.f', 'a.g', 'j' ]

selectPaths(someObject, /^..$/); 
// [ 'a.f', 'a.g' ]

selectPaths(someObject, { test: x => 34 < x && x < 345 }); 
// [ 'a.b.c.0.d', 'a.g' ]

Tests

$ npm test

Readme

Keywords

Package Sidebar

Install

npm i @aercolino/object-paths

Weekly Downloads

2

Version

0.1.0

License

ISC

Last publish

Collaborators

  • aercolino