From 50121d7a01e2c38e9553fc5b35a7ea5222ed4694 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sun, 20 Oct 2013 17:32:13 -0400 Subject: [PATCH] added _.pick definitions --- lodash/lodash-tests.ts | 6 ++++++ lodash/lodash.d.ts | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 55f3272c2..39e2ad335 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -693,6 +693,12 @@ result = _.omit({ 'name': 'moe', 'age': 40 }, function(value) { result = _.pairs({ 'moe': 30, 'larry': 40 }); +result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, 'name'); +result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, ['name']); +result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key) { + return key.charAt(0) != '_'; +}); + //////////////////////////////////////////////////////////////////////////////////////// //WHAT'S LEFT //////////////////////////////////////////////////////////////////////////////////////// diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 5f78e5d3f..347cbe8df 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2649,7 +2649,34 @@ declare module _ { **/ export function pairs(object: any): any[][]; + /** + * 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). + * @param object Object to strip unwanted key/value pairs. + * @param keys Property names to pick + * @return An object composed of the picked properties. + **/ + export function pick( + object: any, + ...keys: string[]): any; + /** + * @see _.pick + **/ + export function pick( + object: any, + keys: string[]): any; + + /** + * @see _.pick + **/ + export function pick( + object: any, + callback: ObjectIterator, + thisArg?: any): any; @@ -2702,16 +2729,7 @@ declare module _ { - /** - * Return a copy of the object, filtered to only have values for the whitelisted keys - * (or array of valid keys). - * @param object Object to strip unwanted key/value pairs. - * @keys The key/value pairs to keep on `object`. - * @return Copy of `object` with only the `keys` properties. - **/ - export function pick( - object: any, - ...keys: string[]): any; +