options-checker

1.1.0 • Public • Published

options-checker

11/10/18

JavaScript Style Guide Build Status Try options-checker on RunKit

the heck!?111

Use this to check if all params are valid. All of them can be overridden with the _id section. The parameter will change its requirements while assuming the value passed.

In this example, when action assumes the value addE, name became not mandatory but fromName and toName yes.

The example also shows that you can pass values you accept. true simply means the key is mandatory to exists.

NEW! callback function support!

example

const neededOptions = {
  action: ['addE', 'addV', 'drop'],
  label: true,
  name: true,
  _if: {
    action: {
      'addE': {
        name: false,
        fromName: true,
        toName: true
      }
    }
  }
}

node example.js --action addV --name test --label lbl

const result = optionsChecker(require('minimist')(process.argv), neededOptions)
// {
//   "valid": true
// }

node example.js --action addE --name test --label lbl

const result = optionsChecker(require('minimist')(process.argv), neededOptions)
// {
//   "valid": false,
//   "option": "nameFrom"
// }

node example.js --action addM --name test --label lbl

const result = optionsChecker(require('minimist')(process.argv), neededOptions)
// {
//   "valid": false,
//   "option": "action",
//   "validOptions": ["addE", "addV", "drop"]
// }

use with functions

const field = rndm(19)
const result = Module({
    field,
    action: 'test'
  }, {
  action: true,
  field (value, key) {
    return value === field && key === 'field'
  }
})

Readme

Keywords

Package Sidebar

Install

npm i options-checker

Weekly Downloads

3

Version

1.1.0

License

ISC

Unpacked Size

14 kB

Total Files

8

Last publish

Collaborators

  • brugnara