# prop-by-string

> Get and set object properties by string literals

Latest version **1.0.1** (published 2015-02-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install prop-by-string
pnpm add prop-by-string
yarn add prop-by-string
bun add prop-by-string
```

## 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.1 |
| Published | 2015-02-02 |
| First published | 2015-02-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Eirik Vullum |
| Maintainers | eiriklv |
| Keywords | object, string, property |

## Links

- npm: https://www.npmjs.com/package/prop-by-string
- Repository: https://github.com/eiriklv/prop-by-string
- Issues: https://github.com/eiriklv/prop-by-string/issues
- npm.io page: https://npm.io/package/prop-by-string

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-02-02
- 1.0.0 — 2015-02-02

## README

prop-by-string
==============

[![Build Status](https://travis-ci.org/eiriklv/prop-by-string.svg?branch=master)](https://travis-ci.org/eiriklv/prop-by-string)

#### Introduction:
Get and set an object property by string.
Supports nested array notation.

---------------------------------------

### .get(propString, object)

Get an object property by string literal.
Any erroneous request will return `undefined`.

__Arguments__

* `propString` - A string specification of what you want to fetch.
* `object` - The object you want to fetch from.

__Example__

```js
var propByString = require('prop-by-string');

var myObject = {
  myList: [{
    myNestedList: [{
      name: 'Eirik',
      age: 28
    }]
  }]
};

var result = propByString.get('myList[0].myNestedList[0].name', myObject);
// Eirik

var result = propByString.get('myList[0].myNestedList[0].notHere', myObject);
// undefined
```

---------------------------------------

### .set(propString, update, object)

Mutate an object by specifying the location as a string literal.

__Arguments__

* `propString` - A string specification of what you want to fetch.
* `update` - The update you want to insert (any primitive / object).
* `object` - The object you want to mutate.

The method returns the mutated object as a convenience.

__Example__

```js
var propByString = require('prop-by-string');

var original = {
  a: {
    b: {
      c: {
        d: [['hello']]
      }
    }
  }
}

var mutated = propByString.set('a.b.c.d[0][1]', 'world', original);
// {
//   a: {
//     b: {
//       c: {
//         d: [['hello', 'world']]
//       }
//     }
//   }
// }
```

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