obj-search

1.0.1 • Public • Published

Table of Contents

Get a property from an object using dot path or Regexp.


Built with ❤︎ by Tiaan du Plessis

Table of Contents

Table of Contents
  • Install
  • Usage
  • OSS
  • Contribute
  • License
  • Install

    Install with npm

    $ npm install --save obj-search

    Install with yarn

    $ yarn add obj-search

    Usage

    To use, require/import the module and call the function in the format:

    objSearch(objectToSearch, patternToLookFor, optionalDefaultValue)

    An example of usage:

     
    const objSearch = require('obj-search')
    const nestedObject = {
      foo: {
        bar: {
          baz: 'Hai',
          foo: 'Hi'
        }
      },
      foos: [
        1,
        2,
        3
      ]
    }
     
    console.log(objSearch(nestedObject, 'foo.bar')) // { baz: 'Hai', foo: 'Hi' }
    console.log(objSearch(nestedObject, 'foo.bar.baz')) // 'Hai'
    console.log(objSearch(nestedObject, /foo/)) // [ { bar: { baz: 'Hai', foo: 'Hi' } }, 'Hi', [ 1, 2, 3 ] ]
     

    OSS

    obj-search is made possible through Open Source Software. A very special thanks to all the modules used.

    Contributing

    All Contributions are welcome! Please open up an issue if you would like to help out. 😄

    License

    Licensed under the MIT License.

    Readme

    Keywords

    none

    Package Sidebar

    Install

    npm i obj-search

    Weekly Downloads

    4

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • tiaanduplessis