# validate-option

> Validates option parameters against a default option

Latest version **0.0.6** (published 2016-09-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install validate-option
pnpm add validate-option
yarn add validate-option
bun add validate-option
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2016-09-14 |
| First published | 2016-03-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Henryk Wollik |
| Maintainers | automat |
| Keywords | object, key, validation |

## Links

- npm: https://www.npmjs.com/package/validate-option
- Repository: https://github.com/automat/validate-option
- Issues: https://github.com/automat/validate-option/issues
- npm.io page: https://npm.io/package/validate-option

## Dependencies (1)

- [deepcopy](https://npm.io/package/deepcopy.md) 0.6.3

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2016-09-14
- 0.0.5 — 2016-03-19
- 0.0.4 — 2016-03-13
- 0.0.3 — 2016-03-13
- 0.0.2 — 2016-03-07
- 0.0.1 — 2016-03-06

## README

#validate-options
   
Validates option argument against a default option.

| arg              | type    | description                                                                 |
|------------------|---------|-----------------------------------------------------------------------------|
| options          | object  | Option object to be validated                                               |
| defaults         | object  | Default option object to validate against                                   |
| setDefaultValues | boolean | Indicates whether default values should be set or which keys (default:true) |
   
```
    var validateOptions = require('validate-option');
    
    var defaults = {
        a : 0,
        b : 1,
        c : 2
    };
    
    function foo(options){
        options = validateOptions(options,defaults);
        console.log(options);
    }
    
    function foo2(options){
        options = validateOptions(options,defaults,false);
        console.log(options);
    }
    
    function foo3(options,defaultValueKeys){
        options = validateOptions(options,defaults,defaultValueKeys);
        console.log(options);
    }
    
    foo(); //logs {a: 0, b: 1, c: 2}
    foo({a:0}); //logs {a: 0, b: 1, c: 2}
    foo({a:0,b:0}); //logs {a: 0, b: 0, c: 2}
    
    foo2(); //logs {}
    foo2({a:0}); //logs {a: 0}
    foo2({a:0,b:0}); //logs {a: 0, b: 0}
    
    foo3(null,['b']); //logs {b:1}
    foo3({a:0},['b']); //logs {a:0, b: 1};
    foo3({a:0,b:0},['b']); //logs {a: 0, b: 0}
    
    //...
    foo({a:0,d:0}); //throws Invalid option "d". Available options: ["a", "b", "c"]
    //...
    foo2({a:0,d:0}); //throws Invalid option "d". Available options: ["a", "b", "c"]
    //...
    foo3({a:0,b:0},['d']); //throws Invalid defaults key "d". Available keys: ["a", "b", "c"]

 ```

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