normalize-options
v1.0.0
Published
Helper for string or object methods
Downloads
15
Maintainers
Readme
normalize-options
Helper for string or object methods
Installation
> npm i normalize-options -SE
Usage
var normalizeOptions = require('normalize-options'),
Restify = require('restify')
function loadServer(options) {
options = normalizeOptions(options, 'server')
doSomething(options.server)
}
var server = Restify.createServer()
loadServer(server)
Docs
- It will convert a string to an object at the passed key
normalizeOptions('foo', 'bar') == { bar: 'foo' }
- It will return an object unmodified if the key is present
normalizeOptions({ bar: 'foo' }, 'bar') == { bar: 'foo' }
- It will throw if the desired key is not present
normalizeOptions({ bar: 'foo' }, 'baz') == ReferenceError