npm.io
1.0.10 • Published 6 months ago

diggerize

Licence
ISC
Version
1.0.10
Deps
0
Size
8 kB
Vulns
0
Weekly
0

diggerize

Usage

Import the functions

import {dig, digg, digs} from "diggerize"
dig

Traverses through objects to find the given path.

const myObject = {
  people: [
    {
      firstName: "Kasper",
      lastName: "Stöckel"
    }
  ]
}

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")