# propx

> Safely accessing deeply nested values in JavaScript

Latest version **1.1.0** (published 2021-04-19) · MIT license · 0 weekly downloads

## Install

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

## 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.1.0 |
| Published | 2021-04-19 |
| First published | 2019-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | https://github.com/luispagarcia/ |
| Maintainers | luispa |
| Keywords | props, propx, dot, notation |

## Links

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

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2021-04-19
- 1.0.7 — 2019-07-23
- 1.0.6 — 2019-07-22
- 1.0.5 — 2019-07-22
- 1.0.4 — 2019-07-18
- 1.0.3 — 2019-07-18
- 1.0.2 — 2019-07-18
- 1.0.1 — 2019-07-18
- 1.0.0 — 2019-07-18
- 0.2.2 — 2019-06-26
- 0.2.1 — 2019-06-26
- 0.2.0 — 2019-06-26
- 0.1.0 — 2019-06-26

## README

# Safely accessing deeply nested values ⚡️

## For [deno.land](https://deno.land/) 

```typescript
import { get, set } from "https://raw.githubusercontent.com/LuisPaGarcia/propx/master/mod.ts";

var obj = {
  child:{
    value: 1
  }
}

// get
console.log( get(obj, 'child.value') ) // 1
console.log( get(obj, 'child.value.nonexist') ) // undefined
console.log( get(obj, 'child.value.nonexist', "10") ) // 10

// set
console.log( set(obj, 'child.otherValue', ['hey']) )
// -> 
// {
//   child:{
//     value: 1,
//     otherValue: ['hey']
//   }
// }
```

## For Node.js 

1. Install it using npm:

```bash
$ npm install propx 
```

 or yarn:
```bash
$ yarn add propx 
```

## Usage

```javascript
// Using require
const { set, get } = require('propx');

// Using import (es6)
import { set, get } from 'propx';

// Target example
const obj = {
    a: 1,
    b: 2,
    c: { d: { e: { f: 3 } } },
    g: undefined
};

// How to use get
console.log(get(obj, 'c.d.e.f', ''))
//-> 3

// How to use set
console.log(set(obj, 'g.x.y.z', ['hey']))
/* -> {
    a: 1,
    b: 2,
    c: { d: { e: { f: 3 } } },
    g: { x: { y: { z: [ 'hey' ] } } }
}

*/
```

## Definition

```javascript
/**
 * @param {object} object base object to inject new prop
 * @param {string} path path to set the object
 * @param {any} value value to set
 */
function set(object: Object, path: string, value: any): Object {
    ...
}

/**
 *
 * @param {object} object object to access
 * @param { string | string[] } key string or array with dot notation path
 * @param { any } def optional parameter for default if the full key in path is missing
 */
function get(object: Object, key: string | string[], def: any) {
...
}

```

## TODO:
- [ ] Write tests
- [ ] Use `microbundle` to generate module units.
- [ ] Configure umd ussage for `unpkg.com`.

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