@basket/get

1.3.0 • Public • Published

get

<a target="_blank" href="https://travis-ci.org/borovin/get"><img src="https://travis-ci.org/borovin/get.svg?branch=master" /></a>
<a target="_blank" href="https://codecov.io/gh/borovin/get"><img src="https://codecov.io/gh/borovin/get/branch/master/graph/badge.svg" /></a>
<a target="_blank" href="https://www.bithound.io/github/borovin/get"><img src="https://www.bithound.io/github/borovin/get/badges/score.svg"></a>

Smart property getter

Install

  npm install @basket/get --save

Usage

  const get = require('@basket/get');
  const object = {a: {b: {c: 'value'}}};
  const path = 'a.b.c';

const value = get(object, path); // => 'value'

Gets the value at path of object. If some segment of the path is undefined or null the result value will be undefined.

  const get = require('@basket/get');
  const object = {};
  const path = 'a.b.c';

  const value = get(object, path);
  // => undefined

If some segment of the path is function it will be invoked with object context and returned value will be used.

  const get = require('@basket/get');
  const object = {a: b() {return {c: 'value'}}};
  const path = 'a.b.c';

  const value = get(object, path);
  // => 'value'

Readme

Keywords

none

Package Sidebar

Install

npm i @basket/get

Weekly Downloads

4

Version

1.3.0

License

MIT

Last publish

Collaborators

  • borovin