parameters-named
v0.3.3
Published
Named parameters supporting default value, validation, and environment variables.
Downloads
5
Maintainers
Readme
parameters-named
Named parameters supporting default value, validation, and environment variables.
npm install parameters-named --save
npm stats
Example
var assert = require('assert')
var params = require('parameters-named')({
app: {
def: 'awesome',
env: 'AWESOME_APP_NAME'
},
max: {
req: true,
env: 'AWESOME_APP_MAX',
val: function (val) { return /\d+$/.test(val) } // must be numeric
}
})
assert.deepEqual(params({ max: 5 }).params, {
app: 'awesome',
max: 5
})
process.env.AWESOME_APP_MAX = 30
assert.deepEqual(params({}).params, {
app: 'awesome',
max: process.env.AWESOME_APP_MAX
})
Features
- Handles
options = options || {}
so you don't have to. - Support for default parameter values.
- Support for validation.
- Support for input via environment variable.
API
parameters(spec)
Arguments
spec: (Object)
parameter definition object:key (Object)
argument name:def
default value.env
environment variable name.req
whether requiredval
validation predicate function (must returnBoolean
value).