Skip to content
Simple Javascript Option Resolver
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist
src
.gitignore
.jshintrc
LICENSE
README.md
bower.json
gulpfile.js
package.json

README.md

option-resolver.js

Simple Javascript Option Resolver

Install:

bower install --save tom32i-option-resolver.js

Usage:

var options = new OptionResolver()
    .setTypes({
        animation: 'boolean',
        color: 'string',
        length: 'number',
        debug: false
    })
    .setRequired(['color'])
    .setOptional(['debug', length])
    .setDefaults({
        animation: true
    })
    .resolve({
        animation: false,
        color: 'red',
    });

/**
 * This will get you:
 * {
 *     animation: false,
 *     color: 'red',
 *     debug: false
 * }
 */

Exception:

Throws exeptions when:

  • A option is of the wrong type
  • A required option is not given
  • A unknown option is given
Something went wrong with that request. Please try again.