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

object-pluck

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-pluck

pluck values from an object and deposit them into a new object

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

pluck

Helps pluck multiple values out of an object and deposits them into a new object, optionally under a specific key. Allows chaining and plucking from an array of objects.

Installation

npm install object-pluck --save

Usage

pluck(['keyName1', 'keyName2'], fromObject, 'optionalNamespace').end();

.end() returns the final object. Failing to end the pluck would be catastrophic.

Example

const pluck = require('object-pluck');
  
const object = {
  a: 1,
  b: 2,
  c: 3,
  nest: {
    d: 4,
    e: 5,
  },
  array: [
    {
      lame: 'sauce',
      proto: 'buff',
    },
    {
      lame: 'dance',
      proto: 'rage',
    }
  ]
};
 
// standard plucking (pretty much just destructing)
pluck(['a', 'c'], object).end(); // { a: 1, c: 3 }
 
// namespacing
pluck(['a', 'b'], object, 'foo').end();
// returns { foo: { a: 1, b: 2 } }
 
// chaining
pluck(['a', 'c'], object, 'foo').pluck(['d', 'e'], object.nest, 'bar').end();
// returns { foo: { a: 1, c: 3 }, bar: { d: 4, e: 5 } }
 
// plucks from an array of objects too (requires a namespace)
pluck(['lame', 'proto'], object.array, 'fromArray').end();
// returns { fromArray: [ { lame: 'sauce', proto: 'buff' }, { lame: 'dance', proto: 'rage' } ] }

FAQs

Package last updated on 03 Aug 2017

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