npm.io
1.0.3 • Published 8 years ago

get-object-property

Licence
MIT
Version
1.0.3
Deps
0
Vulns
0
Weekly
0

get-object-property

Safely get javascript object property with fallback value and error reporting

API

get-object-property exposes only one function:

  getObjectProperty(executor, fallbackValue, logFunction);

Examples

  import getObjectProperty from 'get-object-property';

  const foo = {};

  const result = getObjectProperty(() => foo.bar.foo, 'default');

  // expect 'default'
  console.log(result);

In order to log failures in executor pass log function as a third argument:

  import getObjectProperty from 'get-object-property';

  logFn = (err) => { console.log(err); };

  const foo = {};

  const result = getObjectProperty(() => foo.bar.foo, 'default', logFn);
  // expect to see error in console