2.2.0 • Published 2 years ago

@alexaivars/get-in v2.2.0

Weekly downloads
25
License
MIT
Repository
github
Last release
2 years ago

getIn codecov npm version CircleCI

Get a value from object by path. Path can be a number string or array. When any value in a path is undefined then getIn will return undefined or defaultValue if this is provided.

Installation

yarn add @alexaivars/get-in

Usage

const getIn = require("@alexaivars/get-in");
const context = {
  foo: {
    bar: {
      baz: "waldo"
    }
  }
};

console.log(getIn(context, ["foo", "bar", "baz"])); // waldo
console.log(getIn(context, ["foo", "quux"])); // undefined
console.log(getIn(context, ["foo", "quux"], "notSetValue")); // "notSetValue"

Tests

yarn test