JSPM

default-options

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 120
  • Score
    100M100P100Q63904F
  • License MIT

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

Package Exports

  • default-options

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (default-options) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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