Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

optioner

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

optioner

Process and validate options for your module.

  • 0.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.3K
increased by19.87%
Maintainers
1
Weekly downloads
 
Created
Source

optioner

Process and validate options for your module.

npm version Build Status Gitter

Specify a deeply-merged set of hapijs 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, 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

var Optioner = require('optioner')

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

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

Questions?

@rjrodger Gitter

License

Copyright (c) 2016, Richard Rodger and other contributors. Licensed under MIT.

Keywords

FAQs

Package last updated on 27 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc