Naysayers Promote Misery

    parameters-named

    0.3.3 • Public • Published

    parameters-named

    Named parameters supporting default value, validation, and environment variables.

    Build Status Code Climate js-standard-style

    npm install parameters-named --save
    npm stats

    npm NPM downloads Dependency Status

    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 required
        • val validation predicate function (must return Boolean value).

    Reference

    Alternatives

    Licenses

    GitHub license

    Install

    npm i parameters-named

    DownloadsWeekly Downloads

    11

    Version

    0.3.3

    License

    MIT

    Last publish

    Collaborators

    • wilmoore