@alexaivars/get-in

2.2.0 • Public • Published

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

/@alexaivars/get-in/

    Package Sidebar

    Install

    npm i @alexaivars/get-in

    Weekly Downloads

    3

    Version

    2.2.0

    License

    MIT

    Unpacked Size

    2.55 kB

    Total Files

    3

    Last publish

    Collaborators

    • alexaivars