1.0.5 • Published 3 years ago
diggerize v1.0.5
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") //=> nulldigg
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 arraydigs
This will fail is object doesn't contain keys named firstKey and secondKey.
const {firstKey, secondKey} = digs(object, "firstKey", "secondKey")