diggerize
v1.0.5
Published
Fetch keys for object with a default or fail
Downloads
471
Readme
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")