New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

object-path-wild

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-path-wild

Access subtree elements using keypath, with wildcard ('*') support.

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

object-path-wild

Access subtree elements using keypath, with wildcard ('*') support.

Introduction

BFS search through the object tree. Nothing special, utterly stupid and inefficient, but works.

Usage

Typical

Wildcard ('*') will select all that is possible, regardless of array/object.

'use strict';
const lookup = require('object-path-wild');
const obj = {
  a: { b: { c: { d: { e: [
    { f: { g: { h: { i: { j: 'This'}}}}},
    { f: { g: { h: { i: { j: 'is'}}}}},
    { f: { g: { h: { i: { j: 'mad'}}}}},
    { f: { g: { h: { i: { j: 'deep'}}}}}
  ]}}}};
};

lookup(obj, 'a.b.c.d.e.*.f.g.h.i.j');
// ['This', 'is', 'mad', 'deep'];

Asymmetric subtrees (more realistic maybe)

Any key/idx that is not present along the subtree will be omitted.

const obj = {
  a: { b: { c: { d: { e: [
    { f: { g: { h: { i: { j: 'Hello!'}}}}},
    { f: { g: { h: 1 }}},
    { f: { g: { h: 2 }}},
    { f: { g: { h: 3 }}}
  ]}}}};
};

lookup(obj, 'a.b.c.d.e.*.f.g.h.i.j');
// ['Hello!']

Keywords

key

FAQs

Package last updated on 06 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts