From 495fcc1b11bc1f250e99c61513a3ef2ee648dbb4 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 9 May 2014 15:34:58 -0700 Subject: [PATCH] Include pick in lodash build --- Makefile | 3 +++ js/lib/lodash.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++- package.json | 1 + 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 885df0a94..691a1a860 100644 --- a/Makefile +++ b/Makefile @@ -124,3 +124,6 @@ D3_FILES = \ js/lib/d3.v3.js: $(D3_FILES) node_modules/.bin/smash $(D3_FILES) > $@ @echo 'd3 rebuilt. Please reapply 7e2485d, 4da529f, and 223974d' + +js/lib/lodash.js: + node_modules/.bin/lodash --debug --output $@ include="any,assign,bind,clone,compact,contains,debounce,difference,each,every,extend,filter,find,first,forEach,groupBy,indexOf,intersection,isEmpty,isEqual,isFunction,keys,last,map,omit,pairs,pluck,reject,some,throttle,union,uniq,unique,values,without,flatten,value,chain,cloneDeep,merge,pick" exports="global,node" diff --git a/js/lib/lodash.js b/js/lib/lodash.js index cda72370c..4c8cb489e 100644 --- a/js/lib/lodash.js +++ b/js/lib/lodash.js @@ -1,7 +1,7 @@ /** * @license * Lo-Dash 2.3.0 (Custom Build) - * Build: `lodash include="any,assign,bind,clone,compact,contains,debounce,difference,each,every,extend,filter,find,first,forEach,groupBy,indexOf,intersection,isEmpty,isEqual,isFunction,keys,last,map,omit,pairs,pluck,reject,some,throttle,union,uniq,unique,values,without,flatten,value,chain,cloneDeep,merge" exports="global,node"` + * Build: `lodash --debug --output js/lib/lodash.js include="any,assign,bind,clone,compact,contains,debounce,difference,each,every,extend,filter,find,first,forEach,groupBy,indexOf,intersection,isEmpty,isEqual,isFunction,keys,last,map,omit,pairs,pluck,reject,some,throttle,union,uniq,unique,values,without,flatten,value,chain,cloneDeep,merge,pick" exports="global,node"` * Copyright 2012-2013 The Dojo Foundation * Based on Underscore.js 1.5.2 * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors @@ -2304,6 +2304,57 @@ return result; } + /** + * Creates a shallow clone of `object` composed of the specified properties. + * Property names may be specified as individual arguments or as arrays of + * property names. If a callback is provided it will be executed for each + * property of `object` picking the properties the callback returns truey + * for. The callback is bound to `thisArg` and invoked with three arguments; + * (value, key, object). + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The source object. + * @param {Function|...string|string[]} [callback] The function called per + * iteration or property names to pick, specified as individual property + * names or arrays of property names. + * @param {*} [thisArg] The `this` binding of `callback`. + * @returns {Object} Returns an object composed of the picked properties. + * @example + * + * _.pick({ 'name': 'fred', '_userid': 'fred1' }, 'name'); + * // => { 'name': 'fred' } + * + * _.pick({ 'name': 'fred', '_userid': 'fred1' }, function(value, key) { + * return key.charAt(0) != '_'; + * }); + * // => { 'name': 'fred' } + */ + function pick(object, callback, thisArg) { + var result = {}; + if (typeof callback != 'function') { + var index = -1, + props = baseFlatten(arguments, true, false, 1), + length = isObject(object) ? props.length : 0; + + while (++index < length) { + var key = props[index]; + if (key in object) { + result[key] = object[key]; + } + } + } else { + callback = lodash.createCallback(callback, thisArg, 3); + forIn(object, function(value, key, object) { + if (callback(value, key, object)) { + result[key] = value; + } + }); + } + return result; + } + /** * Creates an array composed of the own enumerable property values of `object`. * @@ -3830,6 +3881,7 @@ lodash.merge = merge; lodash.omit = omit; lodash.pairs = pairs; + lodash.pick = pick; lodash.pluck = pluck; lodash.reject = reject; lodash.throttle = throttle; diff --git a/package.json b/package.json index aa5f36818..92653c600 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "devDependencies": { "d3": "3.4.6", "smash": "0.0", + "lodash-cli": "2.3.0", "uglify-js": "~2.2.5", "maki": "0.4", "jshint": "2.3.0",