New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

default-options

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

default-options

Assigns default values to an object along with validating for required and unknown property keys.

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
303
206.06%
Maintainers
1
Weekly downloads
 
Created
Source

default-options

Assigns default values to an object along with validating for required and unknown property keys.

Usage

dopts(options, defaults, [doptsOptions]);

  • options - The user specified options object
  • defaults - An object of defaults for values not specified in options. If a default property value is set specifically to undefined, it will be treated as a required property.
  • doptsOptions - Optional object of options for the dopts function.
    • doptsOptions.allowUnknown If set to true, will not throw an error if an unknown property is specified. (default is false)
  • Returns defaults merged with options

Example:

var dopts = require('default-options');

dopts({foo: 1, bar: 1}, {
  foo: undefined, // undefined means required
  bar: 2,         // optional
  baz: null,      // optional
});
// Returns {foo: 1, bar: 1, baz: null}

dopts({foo:1}, {
  foo: undefined,
  bar: undefined
});
// Throws an Error because `bar` is not defined

dopts({foo: 1, biz: 2}, {
  foo: undefined
});
// Throws an Error because `biz` is an unknown property

Keywords

options

FAQs

Package last updated on 23 Dec 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