1.0.0 • Published 6 years ago

safeget-json v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

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!