# options-checker

> check mandatories options, even with conditionals

Latest version **1.1.0** (published 2018-10-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install options-checker
pnpm add options-checker
yarn add options-checker
bun add options-checker
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-10-15 |
| First published | 2018-10-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniele Brugnara |
| Maintainers | brugnara |
| Keywords | options, check, mandatory |

## Links

- npm: https://www.npmjs.com/package/options-checker
- Repository: https://github.com/brugnara/options-checker
- Homepage: https://github.com/brugnara/options-checker#readme
- Issues: https://github.com/brugnara/options-checker/issues
- npm.io page: https://npm.io/package/options-checker

## Dependencies (1)

- [debug](https://npm.io/package/debug.md) 4.1.0

## Recent versions

- 1.1.0 (latest) — 2018-10-15
- 1.0.4 — 2018-10-12
- 1.0.3 — 2018-10-11
- 1.0.2 — 2018-10-11
- 1.0.1 — 2018-10-11
- 1.0.0 — 2018-10-11

## README

# options-checker
> 11/10/18

[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Build Status](https://travis-ci.org/brugnara/options-checker.svg?branch=master)](https://travis-ci.org/brugnara/options-checker)
[![Try options-checker on RunKit](https://badge.runkitcdn.com/options-checker.svg)](https://npm.runkit.com/options-checker)

### 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

```js
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

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

---
_Source: https://npm.io/package/options-checker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
