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

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

set-options

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by30%
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,

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: 1} 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)
var options = set({a: undefined}, {a: 1}, function (value, key, object) {
  return key in object
})

options  // {a: undefined}

## License

MIT

Keywords

FAQs

Package last updated on 20 Dec 2015

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