lodash.pluck
Advanced tools
Comparing version 3.0.2 to 3.1.0
132
index.js
/** | ||
* lodash 3.0.2 (Custom Build) <https://lodash.com/> | ||
* lodash 3.1.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
*/ | ||
var baseProperty = require('lodash._baseproperty'), | ||
var baseGet = require('lodash._baseget'), | ||
toPath = require('lodash._topath'), | ||
isArray = require('lodash.isarray'), | ||
map = require('lodash.map'); | ||
/** Used to match property names within property paths. */ | ||
var reIsDeepProp = /\.|\[(?:[^[\]]+|(["'])(?:(?!\1)[^\n\\]|\\.)*?)\1\]/, | ||
reIsPlainProp = /^\w*$/; | ||
/** | ||
* Gets the value of `key` from all elements in `collection`. | ||
* The base implementation of `_.property` without support for deep paths. | ||
* | ||
* @private | ||
* @param {string} key The key of the property to get. | ||
* @returns {Function} Returns the new function. | ||
*/ | ||
function baseProperty(key) { | ||
return function(object) { | ||
return object == null ? undefined : object[key]; | ||
}; | ||
} | ||
/** | ||
* A specialized version of `baseProperty` which supports deep paths. | ||
* | ||
* @private | ||
* @param {Array|string} path The path of the property to get. | ||
* @returns {Function} Returns the new function. | ||
*/ | ||
function basePropertyDeep(path) { | ||
var pathKey = (path + ''); | ||
path = toPath(path); | ||
return function(object) { | ||
return baseGet(object, path, pathKey); | ||
}; | ||
} | ||
/** | ||
* Checks if `value` is a property name and not a property path. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @param {Object} [object] The object to query keys on. | ||
* @returns {boolean} Returns `true` if `value` is a property name, else `false`. | ||
*/ | ||
function isKey(value, object) { | ||
var type = typeof value; | ||
if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') { | ||
return true; | ||
} | ||
if (isArray(value)) { | ||
return false; | ||
} | ||
var result = !reIsDeepProp.test(value); | ||
return result || (object != null && value in toObject(object)); | ||
} | ||
/** | ||
* Converts `value` to an object if it is not one. | ||
* | ||
* @private | ||
* @param {*} value The value to process. | ||
* @returns {Object} Returns the object. | ||
*/ | ||
function toObject(value) { | ||
return isObject(value) ? value : Object(value); | ||
} | ||
/** | ||
* Gets the property value of `path` from all elements in `collection`. | ||
* | ||
* @static | ||
@@ -19,3 +84,3 @@ * @memberOf _ | ||
* @param {Array|Object|string} collection The collection to iterate over. | ||
* @param {string} key The key of the property to pluck. | ||
* @param {Array|string} path The path of the property to pluck. | ||
* @returns {Array} Returns the property values. | ||
@@ -36,6 +101,59 @@ * @example | ||
*/ | ||
function pluck(collection, key) { | ||
return map(collection, baseProperty(key)); | ||
function pluck(collection, path) { | ||
return map(collection, property(path)); | ||
} | ||
/** | ||
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. | ||
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(1); | ||
* // => false | ||
*/ | ||
function isObject(value) { | ||
// Avoid a V8 JIT bug in Chrome 19-20. | ||
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details. | ||
var type = typeof value; | ||
return type == 'function' || (!!value && type == 'object'); | ||
} | ||
/** | ||
* Creates a function which returns the property value at `path` on a | ||
* given object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Utility | ||
* @param {Array|string} path The path of the property to get. | ||
* @returns {Function} Returns the new function. | ||
* @example | ||
* | ||
* var objects = [ | ||
* { 'a': { 'b': { 'c': 2 } } }, | ||
* { 'a': { 'b': { 'c': 1 } } } | ||
* ]; | ||
* | ||
* _.map(objects, _.property('a.b.c')); | ||
* // => [2, 1] | ||
* | ||
* _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c'); | ||
* // => [1, 2] | ||
*/ | ||
function property(path) { | ||
return isKey(path) ? baseProperty(path) : basePropertyDeep(path); | ||
} | ||
module.exports = pluck; |
Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
Based on Underscore.js 1.7.0, copyright 2009-2015 Jeremy Ashkenas, | ||
Based on Underscore.js, copyright 2009-2015 Jeremy Ashkenas, | ||
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> | ||
@@ -4,0 +4,0 @@ |
{ | ||
"name": "lodash.pluck", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "The modern build of lodash’s `_.pluck` as a module.", | ||
@@ -20,5 +20,7 @@ "homepage": "https://lodash.com/", | ||
"dependencies": { | ||
"lodash._baseproperty": "^3.0.0", | ||
"lodash._baseget": "^3.0.0", | ||
"lodash._topath": "^3.0.0", | ||
"lodash.isarray": "^3.0.0", | ||
"lodash.map": "^3.0.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# lodash.pluck v3.0.2 | ||
# lodash.pluck v3.1.0 | ||
@@ -20,2 +20,2 @@ The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.pluck` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
See the [documentation](https://lodash.com/docs#pluck) or [package source](https://github.com/lodash/lodash/blob/3.0.2-npm-packages/lodash.pluck) for more details. | ||
See the [documentation](https://lodash.com/docs#pluck) or [package source](https://github.com/lodash/lodash/blob/3.1.0-npm-packages/lodash.pluck) for more details. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7103
148
4
+ Addedlodash._baseget@^3.0.0
+ Addedlodash._topath@^3.0.0
+ Addedlodash.isarray@^3.0.0
+ Addedlodash._baseget@3.7.2(transitive)
+ Addedlodash._topath@3.8.1(transitive)
- Removedlodash._baseproperty@^3.0.0
- Removedlodash._baseproperty@3.0.0(transitive)