# optioner

> Process and validate options for your module.

Latest version **5.0.1** (published 2020-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install optioner
pnpm add optioner
yarn add optioner
bun add optioner
```

## 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 | 5.0.1 |
| Published | 2020-03-11 |
| First published | 2016-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Richard Rodger richardrodger.com |
| Maintainers | rjrodger |
| Keywords | options, optioner, validate, merge |

## Links

- npm: https://www.npmjs.com/package/optioner
- Repository: https://github.com/rjrodger/optioner
- Issues: https://github.com/rjrodger/optioner/issues
- npm.io page: https://npm.io/package/optioner

## Dependencies (2)

- [@hapi/joi](https://npm.io/package/@hapi/joi.md) ^17.1.0
- [@hapi/hoek](https://npm.io/package/@hapi/hoek.md) ^9.0.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

- 5.0.1 (latest) — 2020-03-11
- 5.0.0 — 2020-01-27
- 4.2.0 — 2019-09-20
- 4.1.2 — 2019-09-06
- 4.0.0 — 2019-05-14
- 3.0.0 — 2018-08-07
- 2.1.0 — 2018-07-15
- 2.0.0 — 2018-07-14
- 1.1.0 — 2018-03-17
- 1.0.1 — 2018-03-13
- 1.0.0 — 2018-03-11
- 0.9.1 — 2017-10-14
- 0.9.0 — 2017-10-14
- 0.8.0 — 2016-07-27
- 0.7.0 — 2016-07-27
- … 5 more at https://npm.io/package/optioner/versions

## README

# optioner
> Process and validate options for your module.

[![npm version][npm-badge]][npm-url]
[![Build Status][travis-badge]][travis-url]
[![Gitter][gitter-badge]][gitter-url]

Specify a deeply-merged set of [hapijs joi][joi] rules and defaults to
process options provided to your module.

Users of your module can quickly debug issues as they get immediate
feedback on configuration issues, and you can provide a user friendly
set of defaults.
 
This provides essentially the same behavior as
[lodash.defaultsDeep](https://lodash.com/docs#defaultsDeep), but also
gives you validation, and more intelligent array handling (per element
control).

You can use [joi] rules directly, or literal values, which are
translated into rules of the form: `Joi.<type>().default(<value>)`
where _type_ is the type of the value.


## Quick Example


```js
var Optioner = require('optioner')

var check = Optioner({beatles: 4}).check

// prints { beatles: 4, stones: 5 }
console.log(check({stones: 5}))


var optioner = Optioner({
  color: 'red',
  size: Joi.number().integer().max(5).min(1).default(3),
  range: [100, 200]
})

var promise = optioner({size: 2})

// prints: { color: 'red', size: 2, range: [ 100, 200 ] }
promise
  .then(console.log)

// prints: { color: 'red', size: 2, range: [ 100, 200 ] }
console.log(promise.value)

optioner({}, function (err, out) {
  // prints: { color: 'red', size: 3, range: [ 100, 200 ] }
  console.log(out)
})

optioner({range: [50]}, function (err, out) {
  // prints: { range: [ 50, 200 ], color: 'red', size: 3 }
  console.log(out)
})

optioner({size: 6}, function (err, out) {
  // prints: child "size" fails because ["size" must be less than or equal to 5
  console.log(err)
})
```

## Options

`Optioner({ ... spec ... }, { ... options ... }})`

* _allow_unknown_: `true|false`, default `true`; allow unknown properties
* _must_match_literals_: `true|false`, default `false`; force exact matches of literal values


## Dependencies

* NOTE: requires `@hapi/joi` >= 16, as: https://github.com/hapijs/joi/issues/2037



## Questions?

[@rjrodger](https://twitter.com/rjrodger)
[![Gitter][gitter-badge]][gitter-url]

## License
Copyright (c) 2016, Richard Rodger and other contributors.
Licensed under [MIT][].

[MIT]: ./LICENSE
[npm-badge]: https://badge.fury.io/js/optioner.svg
[npm-url]: https://badge.fury.io/js/optioner
[travis-badge]: https://travis-ci.org/rjrodger/optioner.svg
[travis-url]: https://travis-ci.org/rjrodger/optioner
[gitter-badge]: https://badges.gitter.im/Join%20Chat.svg
[gitter-url]: https://gitter.im/rjrodger/seneca
[github issue]: https://github.com/rjrodger/optioner/issues
[joi]: https://github.com/hapijs/joi

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