Skip to content

Safely get javascript object property with fallback value and error reporting

License

Notifications You must be signed in to change notification settings

vadirn/get-object-property

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Safely get javascript object property with fallback value and error reporting

Resources

License

Stars

Watchers

Forks

Packages

No packages published