Git Product home page Git Product logo

pluck-deep's Introduction

pluck-deep

Build Status

Pluck values of a collection given a 'dot' separated string

module.exports = function pluckDeep(coll, selector) { ... }

Install

npm i -S pluck-deep

Usage

pluckDeep accepts an array or object as an initial argument.

You can pick a value or array of values by passing in a selector.

Selectors

For the purpose of pluckDeep a selector is a string with object value accessors separated with a .. In other words, you can retrieve a value just like you would on any object, except that these selectors will automatically map an array of values for you.

// Example selectors
'planet.earth.size'; // returns a single value set a size
'planet.saturn.moons.name'; // Will return an array of moon names

See below examples and tests for more selectors

Value plucking

var sel = 'mercury.venus';
var o = {
  mercury: {
    venus: 'earth'
  }
};

var v = pluckDeep(o, sel);
assert.equal(v, o.mercury.venus);

Array plucking

var sel = 'saturn.moons.name';
var o = {
  saturn: {
    moons: [{ name: 'titan' }, { name: 'enceladus' }, { name: 'rhea' }]
  }
};

var arr = pluckDeep(o, sel);
var expect = o.saturn.moons.map(prop('name'));
assert.deepEqual(arr, expect);

Filterable

Add a filterable statment to filter out return values based on some comparable

var sel = 'system.planets.name[type=dwarf]';
var o = {
  system: {
    planets: [
      {
        name: 'earth',
        type: 'ocean'
      },
      {
        name: 'pluto',
        type: 'dwarf'
      }
    ]
  }
};

var v = pluckDeep(o, sel);
assert(Array.isArray(v));
assert.equal(v.length, 1);
assert.equal(v[0], 'pluto');

// With an object
var sel = 'rings[type=gas]';
var venus = {
  type: 'gas',
  rings: false
};

var v = pluckDeep(venus, sel);
assert.equal(v, false);

pluck-deep's People

Contributors

renovate-bot avatar landau avatar renovate[bot] avatar

Stargazers

Tes avatar kokokele avatar crosshj avatar Ricky Reusser avatar Athan avatar Filip Malinowski avatar Kimani Nielsen avatar Ryan J avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

papajuans

pluck-deep's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency eslint-plugin-prettier to v4.2.1
  • chore(deps): update dependency prettier to v2.8.8
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-config-prettier to v9
  • chore(deps): update dependency eslint-plugin-jsdoc to v50
  • chore(deps): update dependency eslint-plugin-mocha to v10
  • chore(deps): update dependency eslint-plugin-prettier to v5
  • chore(deps): update dependency mocha to v10
  • chore(deps): update dependency nyc to v17
  • chore(deps): update dependency prettier to v3
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @landau/eslint-config 4.0.7
  • eslint 8.6.0
  • eslint-config-prettier 8.3.0
  • eslint-plugin-import 2.25.4
  • eslint-plugin-jsdoc 37.0.3
  • eslint-plugin-mocha 9.0.0
  • eslint-plugin-prettier 4.0.0
  • jshint-stylish 2.2.1
  • mocha 9.2.2
  • nyc 15.1.0
  • prettier 2.4.1
  • node >= 10.0.0
travis
.travis.yml
  • node 10
  • node 12

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.