Package Exports
- js-nested-pick
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (js-nested-pick) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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
['name', 'age']
Select name and age from object
- Deep select with dot
['user.firstname']
Select user.name from inner object
- Ommit fileds
['-password']
Select all fields except the password
- Deep ommit fileds with dot
['-user.address']
Select all fields except the user address
- Deep select/ ommit using object with path
['*', {path: 'user', select: ['-paasword']}]
Select all fields, but in the user object, remove the password field
- Select field in root object base of query on the data - using sift (read sift docs to see the options)
[{when: {isPublic: true}, then: ['*'], otherwise: ['title']}]
When the data.isPublic equal to true then in the data.posts select all fields, otherwise select only the title (post can be object or array)
- Select field in inner object or array base of query on the data - using sift (read sift docs to see the options)
[{path: 'post', when: {isPublic: true}, then: ['*'], otherwise: ['title']}]
When the data.isPublic equal to true then in the data.posts select all fields, otherwise select only the title (post can be object or array)
- Select field in inner object or array base of query on the item data - using sift (read sift docs to see the options)
[{path: 'posts', where: {isPublic: true}, then: ['*'], otherwise: ['title']}]
When the post.isPublic equal to true then select all post fields, otherwise select only the title (post can be object or array)
In-browser Playgrounds
Dependencies:
Test with jest