# tread

> Update an object with another object containing just the new key-value pairs. Objects can be infinitely nested. Perfect for updating with PUT requests in your REST API.

Latest version **1.2.0** (published 2017-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install tread
pnpm add tread
yarn add tread
bun add tread
```

## 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 | 1.2.0 |
| Published | 2017-03-19 |
| First published | 2016-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Jared Reich |
| Maintainers | jaredreich |
| Keywords | traverse, object, objects, update, nested |

## Links

- npm: https://www.npmjs.com/package/tread
- Repository: https://github.com/jaredreich/tread
- Homepage: https://github.com/jaredreich/tread#readme
- Issues: https://github.com/jaredreich/tread/issues
- npm.io page: https://npm.io/package/tread

## Recent versions

- 1.2.0 (latest) — 2017-03-19
- 1.1.0 — 2016-08-01
- 1.0.0 — 2016-07-31

## README

## Installation

``` bash
npm install --save tread
```

## Usage

```javascript
// user from your database
var user = {
  details: {
    name: {
      first: 'Jane',
      last: 'Smith'
    },
    address: {
      street: {
        number: '5',
        name: 'Oak Lane'
      },
      coordinates: {
        lat: 50,
        lng: 50
      }
    }
  },
  gender: 'm'
}

// userUpdates from your PUT request
var userUpdates = {
  details: {
    name: {
      first: 'John'
    },
    address: {
      coordinates: {
        lat: 100
      }
    }
  }
}

// perform the update
user = tread(user, userUpdates, strict)

// save the updated user in the database
user.save(...)
```

#### Strict mode

strict (Boolean, default = false): only updates object if the key already existed.
For example:
```javascript
tread({ name: 'Jane' }, { name: 'John', age: 20 }, true)
// outputs
{ name: 'John' }

tread({ name: 'Jane' }, { name: 'John', age: 20 }, false)
// OR
tread({ name: 'Jane' }, { name: 'John', age: 20 })
// outputs
{ name: 'John', age: 20 }
```

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