# set-options

> Merges default options to the user-given options.

Latest version **2.0.2** (published 2017-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install set-options
pnpm add set-options
yarn add set-options
bun add set-options
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2017-11-20 |
| First published | 2015-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kaelzhang |
| Maintainers | kael |
| Keywords | set-options, options, merge, mix |

## Links

- npm: https://www.npmjs.com/package/set-options
- Repository: https://github.com/kaelzhang/node-set-options
- Homepage: https://github.com/kaelzhang/node-set-options#readme
- Issues: https://github.com/kaelzhang/node-set-options/issues
- npm.io page: https://npm.io/package/set-options

## Recent versions

- 2.0.2 (latest) — 2017-11-20
- 2.0.1 — 2016-07-18
- 2.0.0 — 2016-07-18
- 1.0.4 — 2016-01-21
- 1.0.3 — 2016-01-21
- 1.0.2 — 2015-12-20
- 1.0.1 — 2015-12-20
- 0.0.0 — 2015-12-19

## README

[![Build Status](https://travis-ci.org/kaelzhang/node-set-options.svg?branch=master)](https://travis-ci.org/kaelzhang/node-set-options)
<!-- optional npm version
[![NPM version](https://badge.fury.io/js/set-options.svg)](http://badge.fury.io/js/set-options)
-->
<!-- optional npm downloads
[![npm module downloads per month](http://img.shields.io/npm/dm/set-options.svg)](https://www.npmjs.org/package/set-options)
-->
<!-- optional dependency status
[![Dependency Status](https://david-dm.org/kaelzhang/node-set-options.svg)](https://david-dm.org/kaelzhang/node-set-options)
-->

# set-options

Merges default options to the user-given options.

## Install

```sh
$ 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`.

```js
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

```js
set(options, defaults, filter)
```

```js
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.

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

## License

MIT

---
_Source: https://npm.io/package/set-options · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
