Socket
Socket
Sign inDemoInstall

set-options

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

set-options

Merges default options to the user-given options.


Version published
Weekly downloads
12
decreased by-36.84%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

set-options

Merges default options to the user-given options.

Install

$ npm install set-options --save

set(options, defaults)

Always returns an object. For a key k, if options does not have k as an own property, and defaults does, defaults[k] will copied to options.

var set = require('set-options')
var defaults = {
  a: 1
}

function factory (options) {
  var config = set(options, defaults)
  // `options` and `defaults` will not be ruined after `set()`
  console.log(config, config === options, config === defaults)
}

factory()
// {a: 1} false false

factory(undefined)
// {a: 1} false false

factory(null)
// {a: 1} false false

factory(1)
// {a: 1} false false

factory({})
// {a: 1} false false

factory({b: 1})
// {a: 1, b: 1} false false

factory({a: 0})
// {a: 0} false false
  • options Object= can be undefined.
  • defaults Object not defining defaults is silly, since that's the whole purpose of this lib.
Define whether should override properties
set(options, defaults, filter)
let options = set({a: undefined}, {a: 1}, function (value, key, object) {
  return key in object
})

options  // {a: undefined}
Deep merge? Nope

Do something below instead.

options = set(options, defaults)
options.config = set(options.config, default_config)

License

MIT

Keywords

FAQs

Package last updated on 20 Nov 2017

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