JSPM

  • Created
  • Published
  • Downloads 34326
  • Score
    100M100P100Q149467F
  • License MIT

Find Keys using Wildcard matching and optional value function.

Package Exports

  • object-scan

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-scan) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Object-Scan

Build Status Test Coverage Greenkeeper Badge Dependencies NPM Downloads Semantic-Release Gardener Gitter

Find Keys using Wildcard matching and optional value function.

Install

Install with npm:

$ npm install --save object-scan

Usage

const objectScan = require('object-scan');

objectScan(["a.*.f"])({ a: { b: { c: 'd' }, e: { f: 'g' } } });
// => [ 'a.e.f' ]

Examples

More extensive examples can be found in the tests.

const objectScan = require('object-scan');

const obj = {
  a: {
    b: {
      c: 'd'
    },
    e: {
      f: 'g'
    },
    h: ["i", "j"]
  },
  k: "l"
};

// top level keys
objectScan(["*"])(obj);
// => ["a", "k"]

// nested keys
objectScan(["a.*.f"])(obj);
// => ["a.e.f"]
objectScan(["*.*.*"])(obj);
// => ["a.b.c", "a.e.f"]

// or filter
objectScan(["a.*.{c,f}"])(obj);
// => ["a.b.c", "a.e.f"]

// list filter
objectScan(["*.*[*]"])(obj);
// => ["a.h[0]", "a.h[1]"]
objectScan(["*[*]"])(obj);
// => []

// deep star filter
objectScan(["**"])(obj);
// => ["a", "a.b", "a.b.c", "a.e", "a.e.f", "a.h", "a.h[0]", "a.h[1]", "k"]
objectScan(["**.f"])(obj);
// => ["a.e.f"]
objectScan(["**[*]"])(obj);
// => ["a.h[0]", "a.h[1]"]

// value function
objectScan(["**"], e => typeof e === "string")(obj);
// => ["a.b.c", "a.e.f", "a.h[0]", "a.h[1]", "k"]

Special Characters

The following Characters are considered special and need to be escaped if they should be matched in a key: [, ], {, }, ,, . and *.