# deepdown

> Safely drill into your JavaScript objects with dynamically defined paths

Latest version **1.0.9** (published 2023-01-01) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2023-01-01 |
| First published | 2019-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | John K. Grant |
| Maintainers | cyrfer |
| Keywords | boilerplate, npm, module, node, javascript |

## Links

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

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.9 (latest) — 2023-01-01
- 1.0.8 — 2021-11-12
- 1.0.7 — 2020-01-04
- 1.0.6 — 2019-10-22
- 1.0.5 — 2019-10-21
- 1.0.4 — 2019-06-30
- 1.0.3 — 2019-06-15
- 1.0.2 — 2019-06-14
- 1.0.1 — 2019-06-14
- 1.0.0 — 2019-03-09

## README

# deepdown
Safely drill into your JavaScript objects with dynamically defined paths

[![Build Status](https://travis-ci.org/cyrfer/deepdown.svg?branch=master)](https://travis-ci.org/cyrfer/deepdown) [![dependencies Status](https://david-dm.org/cyrfer/deepdown/status.svg)](https://david-dm.org/cyrfer/deepdown) [![devDependencies Status](https://david-dm.org/cyrfer/deepdown/dev-status.svg)](https://david-dm.org/cyrfer/deepdown?type=dev) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

# Install
`npm install --save deepdown`

# Example assignByKey

```javascript
const parent = {
  child: {
    grandchild: {
      attribute: 'placeholder'
    }
  }
}
const path = 'child.grandchild.attribute'.split('.')
const value = 'value'
assignByKey(parent, path, value)
console.log(drillDown(parent, path))
/* prints
value
*/
```

# Example drillDown

```javascript
const drillDown = require('deepdown').drillDown;

const appState = {
  nested: {
    dynamic: {
      data: true,
      error: false
    },
    static: {
      other: 'stuff'
    }
  }
};

const route = 'data';
const choice = true;
const path = ['nested', choice ? 'dynamic' : 'static'];
path.push(route);

// --- no crashes even if path is wrong
const result = drillDown(appState, path);

console.log('or be brave', drillDown(appState, `wrong.${!choice ? 'static' : null}.${route}`.split('.')));

// --- what you've been doing
// to avoid crashes involves tedious, statically defined checks
const safeResult = appState.nested && appState.nested.static && appState.nested.static.other;
```

# Example sortByKey

```javascript
const sortByKey = require('deepdown').sortByKey;
const data = [
  {child: {grandchild: {value: 'bbb'}}}, // 'bbb' is greater than 'aaa'
  {child: {grandchild: {value: 'aaa'}}},
];

const firstValueBeforeSort = data[0].child.grandchild.value;
console.log(firstValueBeforeSort)
/* prints
bbb
*/

// --- sort by a nested key --- //
const key = 'child.grandchild.value'.split('.')
data.sort(sortByKey({key, order: true}));

const firstValueAfterSort = data[0].child.grandchild.value;
console.log(firstValueAfterSort)
/* prints
aaa
*/
```

# Example equality

```javascript
const equality = require('deepdown').equality;

const data = [
  {child: {grandchild: {value: 'bbb'}}}, // 'bbb' is greater than 'aaa'
  {child: {grandchild: {value: 'aaa'}}},
];

const data = [
  {child: {grandchild: {value: 'bbb'}}},
  {child: {grandchild: {value: 'aaa'}}},
];
const found = data.find(equality('child.grandchild.value'.split('.'), 'aaa'));

console.log(found);
/* prints
{ child: { grandchild: { value: 'aaa' } } }
*/
```

# Example filterByKey

```javascript
const filterByKey = require('deepdown').filterByKey;

const data = [
  {child: {grandchild: {value: 'bbb'}}},
  {child: {grandchild: {value: 'aaa'}}},
];
const key = 'child.grandchild.value'.split('.')
const value = 'aaa' // only looking for matches with `aaa`
const result = data.filter(filterByKey({key, value}))
console.log(JSON.stringify(result))
/* prints
[{"child":{"grandchild":{"value":"aaa"}}}]
*/
```

# Example unwindByKey

```javascript
const unwindByKey = require('deepdown').unwindByKey;

const data = [
    {child: {grandchild: {value: ['aaa', 'bbb', 'ccc']}}},
    {child: {grandchild: {value: ['ddd', 'eee', 'fff']}}},
];
const keyPath = 'child.grandchild.value'.split('.')
const result = unwindByKey(data, keyPath)
console.log(JSON.stringify(result))
/* prints
[
  {"child":{"grandchild":{"value":"aaa"}}},
  {"child":{"grandchild":{"value":"bbb"}}},
  {"child":{"grandchild":{"value":"ccc"}}},
  {"child":{"grandchild":{"value":"ddd"}}},
  {"child":{"grandchild":{"value":"eee"}}},
  {"child":{"grandchild":{"value":"fff"}}}
]
*/
```

# Example indexByKey

```javascript
const indexByKey = require('deepdown').indexByKey;

const data = [
    {child: {grandchild: {value: 'bbb'}}},
    {child: {grandchild: {value: 'aaa'}}},
];
const keyPath = 'child.grandchild.value'.split('.')
const result = indexByKey(data, keyPath)
console.log(JSON.stringify(result))
/* prints
{
  "bbb":[{"child":{"grandchild":{"value":"bbb"}}}],
  "aaa":[{"child":{"grandchild":{"value":"aaa"}}}]
}
*/
```

# Commands
- `npm test` - Run tests with linting and coverage results.
- `npm run lint` - Run ESlint with airbnb-config
- `npm run build` - Babel will transpile ES6 => ES5 and minify the code.
- `npm run prepublish` - Hook for npm. Do all the checks before publishing your module.

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