# @jkempema/replace-state

> function that replaces a section of state

Latest version **1.0.3** (published 2017-10-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jkempema/replace-state
pnpm add @jkempema/replace-state
yarn add @jkempema/replace-state
bun add @jkempema/replace-state
```

## 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.0.3 |
| Published | 2017-10-22 |
| First published | 2017-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | jkempema |

## Links

- npm: https://www.npmjs.com/package/@jkempema/replace-state
- Repository: https://github.com/jamie-kempema/replace-state
- Homepage: https://github.com/jamie-kempema/replace-state#readme
- Issues: https://github.com/jamie-kempema/replace-state/issues
- npm.io page: https://npm.io/package/@jkempema/replace-state

## Recent versions

- 1.0.3 (latest) — 2017-10-22
- 1.0.2 — 2017-10-22
- 1.0.1 — 2017-10-20

## README

# replace-state

function that allows replacing sections of an object graph

## Usage

Replace using a path of properties

```
import replaceState from 'replace-state';

const state = {
    p1: {
        p2: 'some-value'
    }
};

const newState = replaceState( state, 'p1.p2', 'new-value' );
```

Replace using an array of properties

```
import replaceState from 'replace-state';

const state = {
    p1: {
        p2: 'some-value'
    }
};

const newState = replaceState( state, [ 'p1', 'p2' ], 'new-value' );
```

Replace when the value is an array

```
import replaceState from 'replace-state';

const state = {
    p1: {
        p2: [ {
            id: 1,
            value: 'some-value'
        }, {
            id: 2,
            value: 'some-other-value'
        } ]
    }
};

const newState = replaceState( state, [ 'p1', ( item ) => item.id === 1 ],  'new-value' );
```

Replace with a function

```
import replaceState from 'replace-state';

const state = {
    p1: {
        p2: 'some-value'
    }
};

const newState = replaceState( state, 'p1.p2', ( p2 ) => 'new-value' );
```

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