diggerize

1.0.5 • Public • Published

diggerize

Usage

Import the functions

const {dig, digg, digs} = require("diggerize")
import {dig, digg, digs} from "diggerize"

dig

Traverses through objects to find the given path.

const myObject = {
  people: [
    {
      firstName: "Kasper",
      lastName: "Nielsen"
    }
  ]
}

dig(myObject, "people", 0, "firstName") //=> "Kasper"
dig(myObject, "people", 1, "firstName") //=> null

digg

This functions like dig but it will fail if one of the keys isn't found.

const myObject = {
  people: [
    {
      firstName: "Kasper",
      lastName: "Nielsen"
    }
  ]
}

digg(myObject, "people", 0, "firstName") //=> "Kasper"
digg(myObject, "people", 1, "firstName") //=> Fails because 1 isn't found in the people array

digs

This will fail is object doesn't contain keys named firstKey and secondKey.

const {firstKey, secondKey} = digs(object, "firstKey", "secondKey")

Readme

Keywords

none

Package Sidebar

Install

npm i diggerize

Weekly Downloads

58

Version

1.0.5

License

ISC

Unpacked Size

5.66 kB

Total Files

10

Last publish

Collaborators

  • kaspernj