# js-nested-pick

> Creates an object composed of the picked object properties from a nested object using a dot path, select specific fields based conditions with filter arrays with MongoDB queries

Latest version **1.1.3** (published 2019-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-nested-pick
pnpm add js-nested-pick
yarn add js-nested-pick
bun add js-nested-pick
```

## 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.1.3 |
| Published | 2019-09-28 |
| First published | 2019-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 25.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | doron.nahum@gmail.com |
| Maintainers | doronn |
| Keywords | deep, deeply, javascript, key, merge, mixin, nested, object, pick, prop, properties, property, util, utility, value, typescript, ts |

## Links

- npm: https://www.npmjs.com/package/js-nested-pick
- Repository: https://github.com/doronnahum/js-nested-pick
- Homepage: https://github.com/doronnahum/js-nested-pick#readme
- Issues: https://github.com/doronnahum/js-nested-pick/issues
- npm.io page: https://npm.io/package/js-nested-pick

## Dependencies (3)

- [sift](https://npm.io/package/sift.md) ^8.5.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [@types/node](https://npm.io/package/@types/node.md) ^12.7.3

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 1.1.3 (latest) — 2019-09-28
- 1.1.2 — 2019-09-28
- 1.1.1 — 2019-09-24
- 1.1.0 — 2019-09-23
- 1.0.0 — 2019-09-03
- 0.0.7 — 2019-09-01

## README

# js-nested-pick

### Creates an object composed of the picked object properties from a nested object using a dot path, select specific fields based conditions with filter arrays with MongoDB queries

Can be used in js/ts projects in node/browser.

Support select number of fields from nested object with dot and object with query:

## How to use:

```
const pick = require('js-nested-pick');

const data = {
	name: 'Dan',
	age: 30,
}

const values = pick(data, ['name']) // {name: 'Dan'}
```
- Simple select<br/>
```['name', 'age'] ```<br/>
	<small>Select name and age from object</small>
	<br/>
- Deep select with dot<br/>
```['user.firstname']``` <br/>
	<small>Select user.name from inner object</small><br/>
	
- Ommit fileds<br/>
```['-password']``` <br/>
	<small>Select all fields except the password</small>
	<br/>
	
- Deep ommit fileds with dot<br/>
```['-user.address']``` <br/>
	<small>Select all fields except the user address</small>
	<br/>
	
- Deep select/ ommit using object with path <br/>
```['*', {path: 'user',  select: ['-paasword']}]```<br/>
	<small>Select all fields, but in the user object, remove the password field</small>
	<br/>

- Select field in root object  base of query on the data - <small>using [sift](https://github.com/crcn/sift.js) (read [sift docs](https://github.com/crcn/sift.js) to see the options)</small><br/>
```[{when: {isPublic: true}, then: ['*'], otherwise: ['title']}]``` <br/>
	<small>When the data.isPublic equal to true then in the data.posts  select all fields, otherwise select only the title <small>(post can be object or array)</small>
	<br/>
	
	
- Select field in inner object or array base of query on the data - <small>using [sift](https://github.com/crcn/sift.js) (read [sift docs](https://github.com/crcn/sift.js) to see the options)</small><br/>
```[{path: 'post',  when: {isPublic: true}, then: ['*'], otherwise: ['title']}]``` <br/>
	<small>When the data.isPublic equal to true then in the data.posts  select all fields, otherwise select only the title <small>(post can be object or array)</small>
	<br/>
	
- Select field in inner object or array base of query on the item data - <small>using [sift](https://github.com/crcn/sift.js) (read [sift docs](https://github.com/crcn/sift.js) to see the options)<br/>
</small>```[{path: 'posts',  where: {isPublic: true}, then: ['*'], otherwise: ['title']}]```<br/>
<small>When the post.isPublic equal to true then select all post  fields, otherwise select only the title (post can be object or array)</small>
		<br/>

###  In-browser Playgrounds
[![Edit frosty-bash-sgj4j](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/frosty-bash-sgj4j?fontsize=14)

**Dependencies:**
1. [lodash/get](https://www.npmjs.com/package/lodash)
2.  [lodash/set](https://www.npmjs.com/package/lodash)
3.  [lodash/omit](https://www.npmjs.com/package/lodash)
5. [sift](https://github.com/crcn/sift.js)

**Test with jest**
![enter image description here](https://lh3.googleusercontent.com/8el0YMHAPgkTQD3frNRjhzkKZip7QEynQ66pK3rwvZc0REz50165KASZM7qt2TsOkJiUP-fBZxQztw "jest test result")

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