Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 926 Bytes

.verb.md

File metadata and controls

59 lines (44 loc) · 926 Bytes

Usage

var globObject = require('{%= name %}');

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

Examples

Given the following object:

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

match properties using wildcards

globObject('*', obj);
//=> obj (matches all keys)

match properties using braces

globObject('a.*.{c,e}', obj);
//=> {a: {b: {c: 'd', e: 'f'}}}

match a nested property using a wildcard

A single star will match one level of the object:

globObject('a.*.g', obj);
//=> {a: {b: {g: 'h'}}}

match deep properties using globstars

A double star will match to any depth (note that the single star in the previous example did not match a.b.l.g):

globObject('a.**.g', obj);
//=> {a: {b: {g: 'h', l: {g: 'k'}}}}