propprop
Just a helper for plucking a property out of an object.
Last updated 10 years ago by stephenplusplus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install propprop 
SYNC missed versions from official npm registry.

propprop

pluck a property out of an object.

Before

var friendsAsJavaScriptLibraries = [
  {
    name: 'passy.js',
    hobby: 'clay'
  },
  {
    name: 'sindre.js',
    vehicle: 'unicorn taxi'
  },
  {
    name: 'addy.js',
    invented: 'google *'
  }
];

var names = friendsAsJavaScriptLibraries.map(function (item) {
  return item.name;
});

After

var friendsAsJavaScriptLibraries = [ /* ... */ ];

var names = friendsAsJavaScriptLibraries.map(prop('name'));

The benefit is more noticeable when you're using multiple Array.prototype methods to shape your objects:

var friendsAsJavaScriptLibraries = [ /* ... */ ];
var urls;

if (friendsAsJavaScriptLibraries.every(prop('name'))) {
  urls = friendsAsJavaScriptLibraries
    .map(function (item) {
      item.url = 'https://github.com/magical-library-land/' + item.name;
      return item;
    })
    .map(prop('url'));
}

Why?

Perhaps you're already using Lo-Dash, Underscore.js, or another utility library. This should not supplement those libraries, and definitely cannot replace. This is better suited towards applications that don't want to carry the weight and/or functionality of such libraries, and just want something simple and modular.

Install

prop can be used in the browser or within your Node.js apps.

Browser

$ bower install --save propprop
<script src="bower_components/propprop/browser.js"></script>

Node.js

$ npm install --save propprop
var prop = require('propprop');

License

MIT © Stephen Sawchuk

Current Tags

  • 0.3.1                                ...           latest (10 years ago)

4 Versions

  • 0.3.1                                ...           10 years ago
  • 0.3.0                                ...           12 years ago
  • 0.2.0                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |