# object-funcs

> A very limited subset of object functions I use every day

Latest version **0.4.0** (published 2016-07-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install object-funcs
pnpm add object-funcs
yarn add object-funcs
bun add object-funcs
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2016-07-12 |
| First published | 2016-03-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jérôme Decoster |
| Maintainers | jeromedecoster |
| Keywords | object, defined, merge, only, similar |

## Links

- npm: https://www.npmjs.com/package/object-funcs
- Repository: https://github.com/jeromedecoster/object-funcs
- Homepage: https://github.com/jeromedecoster/object-funcs#readme
- Issues: https://github.com/jeromedecoster/object-funcs/issues
- npm.io page: https://npm.io/package/object-funcs

## Dependencies (1)

- [is-funcs](https://npm.io/package/is-funcs.md) ^0.5.0

## Recent versions

- 0.4.0 (latest) — 2016-07-12
- 0.3.0 — 2016-07-08
- 0.2.1 — 2016-07-04
- 0.2.0 — 2016-07-04
- 0.1.1 — 2016-06-14
- 0.1.0 — 2016-06-08
- 0.0.0 — 2016-03-30

## README

# object-funcs

> A very limited subset of object functions I use every day

## Install

```bash
npm i object-funcs
```

Package [on npm](https://www.npmjs.com/package/object-funcs)

## API

* [defined](#definedarg-arg-)
* [merge](#mergeobj-obj-)
* [only](#onlyobj-keys)
* [similar](#similarobj-search)

## defined([arg], [arg], [...])

Return the first defined `arg`

`arg` is considered not defined when

* `arg` is `null`
* `arg` is `undefined`
* `arg` is `NaN`

```js
const defined = require('object-funcs/defined')

var opts = {y:false, w:4}

// false
defined(opts.x, opts.y, 100)

// 'yes'
defined(null, undefined, NaN, 'yes')
```

---

## merge([obj], [obj], [...])

Merge properties of a **Plain Object** or a serie of **Plain Objects** into a new one

```js
const merge = require('object-funcs/merge')

var ref = {a:'foo'}

// {a:'foo', b:'bar'}
var obj = merge(ref, {b:'bar'})

// {a:'foo'}
ref
```

Always overwrite properties

```js
const merge = require('object-funcs/merge')

// {a:'foo', b:'baz', c:'quux'}
merge({a:'foo'}, {b:'bar'}, {b:'baz'}, {c:'quux'})
```

No deep merge, only first level of properties are injected

```js
const merge = require('object-funcs/merge')

var ref = {foo:{bar:'baz'}}

// {foo:{bar:'baz'}, a:1}
merge(ref, {a:1})

// {foo:{b:2}}
merge(ref, {foo:{b:2}})
```

---

## only(obj, keys)

Return a new **Plain Object** with filtered properties

`keys` can be a **String** or an **Array** of targeted keys

`keys` can also be a **RegExp**

```js
const only = require('object-funcs/only')

// {a:1, b:2}
only({a:1, b:2, c:3}, 'a b')

// {b:2, c:3}
only({a:1, b:2, c:3}, ['b', 'c'])

// {bar:1, baz:2}
only({foo:0, bar:1, baz:2, quux:3}, /^ba/)
```

---

## similar(obj, search)

Partial comparison of two objects

Check if the **keys / values** in `search` are equals in `obj`

```js
const similar = require('object-funcs/similar')

// true
similar({foo:'bar', baz:54}, {baz:54})

// false
similar({foo:'bar', baz:54}, {baz:54, a:1})

// true
similar({foo:{bar:{baz:'quux', c:3}, b:2}, a:1}, {foo:{bar:{baz:'quux'}}})
```

## Thanks

Mainly forked / inspired on
- [defined](https://github.com/substack/defined)
- [node-partial-compare](https://github.com/defunctzombie/node-partial-compare)
- [only](https://github.com/tj/node-only)
- [xtend](https://github.com/Raynos/xtend)

## License

MIT

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