# access-by-path

> Get and set values in object by path

Latest version **0.1.1** (published 2019-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install access-by-path
pnpm add access-by-path
yarn add access-by-path
bun add access-by-path
```

## 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.1.1 |
| Published | 2019-06-06 |
| First published | 2019-02-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | paulzi |

## Links

- npm: https://www.npmjs.com/package/access-by-path
- Repository: https://github.com/paulzi/access-by-path
- Homepage: https://github.com/paulzi/access-by-path#readme
- Issues: https://github.com/paulzi/access-by-path/issues
- npm.io page: https://npm.io/package/access-by-path

## Dependencies (1)

- [escaping](https://npm.io/package/escaping.md) ^0.1.2

## Recent versions

- 0.1.1 (latest) — 2019-06-06
- 0.1.0 — 2019-02-12

## README

# access-by-path

[![NPM version](http://img.shields.io/npm/v/access-by-path.svg?style=flat)](https://www.npmjs.org/package/access-by-path)
[![Build Status](https://img.shields.io/travis/paulzi/access-by-path/master.svg)](https://travis-ci.org/paulzi/access-by-path)
[![Downloads](https://img.shields.io/npm/dt/access-by-path.svg)](https://www.npmjs.org/package/access-by-path)
![License](https://img.shields.io/npm/l/access-by-path.svg)

Functions of getting and setting the values of the object fields by the string representation of the path to them.

[Russian readme](https://github.com/paulzi/access-by-path/blob/master/README.ru.md)

## Install

```sh
npm install access-by-path
```

## Usage

### getByPath

```javascript
import { getByPath } from 'access-by-path';

let obj = { a: 1, b: { c: 2, d: 3}};
let result = getByPath(obj, 'b.d'); // 3
```

`getByPath(obj, path[, defaultValue[, splitChar[, escapeChar]]])`

- `obj {Object}` - object
- `path {string}` - path to field
- `defaultValue {*} [undefined]` - return value if the field is not found in object
- `splitChar {string} ['.']` - path delimiter character
- `escapeChar {string} ['\\']` - character to escape delimiter

### setByPath

```javascript
import { setByPath } from 'access-by-path';

let obj = { a: 1, b: { c: 2, d: 3}};
setByPath(obj, 'b.d', 4); // { a: 1, b: { c: 2, d: 4}}
```

`setByPath(obj, path, value[, splitChar[, escapeChar]])`

- `obj {Object}` - object
- `path {string}` - path to field
- `value {*}` - set value
- `splitChar {string} ['.']` - path delimiter character
- `escapeChar {string} ['\\']` - character to escape delimiter

## Testing

To run tests, use:

```sh
npm test
```

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