js-select-from-object

0.0.1 • Public • Published

js-select-from-object

A JS util to select a property from an object, and if it doesn't exist, return a default value, instead of throwing an error or returning an undefined value.

npm version

Installation

To start using this library, first install the package:

npm install js-select-from-object --save

Usage

An example of how it can be used:

import select from 'js-select-from-object';

const o = {
  foo: 'bar',
  xxx: {
    yyy: 'zzz'
  }
};

select(o, 'foo', 'wut?'); // => returns 'bar'
select(o, 'xxx.yyy', 'wut?'); // => returns 'zzz'
select(o, 'aaa.bbb'); // => returns null
select(o, 'aaa.bbb', 'wut?'); // => returns 'wut?'

Todo

  • Allow for selection of arrays within objects

Package Sidebar

Install

npm i js-select-from-object

Weekly Downloads

1

Version

0.0.1

License

ISC

Last publish

Collaborators

  • operatino