safeget-json

1.0.0 • Public • Published

safeget 🛡

V1.0

Build Status

Super simple NPM module which allows to safely unwrap complex JSON files and provide default value in case of failure

Build Setup

In order to add safeget to your project, run:

npm i safeget-json

You can use safeget by passing JSON as a result of an anonymous function + default value as follows:

const safeget = require("safeget-json")
 
const really = {
  what: {
    can: {
      go: {
        wrong: '?'
      }
    }
  }
}
 
const core = safeget(() => really.what.can.go.wrong, 'stub!')

If JSON contains required node, it will be retrieved. In case node doesn't exist, defauls value ('stub!' in example) will be assigned instead.

Feel free to contribute!

Package Sidebar

Install

npm i safeget-json

Weekly Downloads

2

Version

1.0.0

License

ISC

Unpacked Size

2.15 kB

Total Files

5

Last publish

Collaborators

  • nickshulhin