1.1.0 • Published 6 years ago

options-checker v1.1.0

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

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'
  }
})
1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago