New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

js-nested-pick

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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
Source
npmnpm
Version
1.1.3
Version published
Weekly downloads
14
180%
Maintainers
1
Weekly downloads
 
Created
Source

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

Edit frosty-bash-sgj4j

Dependencies:

Test with jest enter image description here

Keywords

deep

FAQs

Package last updated on 28 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts