From 9d58c2ea97ee2701eea657a4ffb8c2e722864908 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sun, 20 Oct 2013 12:12:26 -0400 Subject: [PATCH] added _.findKey definitions --- lodash/lodash-tests.ts | 4 ++++ lodash/lodash.d.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 2edf674722..fdfc4603f2 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -546,6 +546,10 @@ var result = _.cloneDeep(stoogesAges, function(value) { var foodDefaults = { 'name': 'apple' }; result = _.defaults(foodDefaults, { 'name': 'banana', 'type': 'fruit' }); +result = _.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { + return num % 2 == 0; +}); + var mergeNames = { 'stooges': [ { 'name': 'moe' }, diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f8242ded81..d382417c48 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2206,6 +2206,35 @@ declare module _ { object: any, ...sources: any[]): any; + /** + * This method is like _.findIndex except that it returns the key of the first element that + * passes the callback check, instead of the element itself. + * @param object The object to search. + * @param callback The function called per iteration. + * @param thisArg The this binding of callback. + * @return The key of the found element, else undefined. + **/ + export function findKey( + object: any, + callback: (value: any) => boolean, + thisArg?: any): string; + + /** + * @see _.findKey + * @param pluckValue _.pluck style callback + **/ + export function findKey( + object: any, + pluckValue: string): string; + + /** + * @see _.findKey + * @param whereValue _.where style callback + **/ + export function findKey( + object: any, + whereValue: Dictionary): string; + /** * Recursively merges own enumerable properties of the source object(s), that don't resolve * to undefined into the destination object. Subsequent sources will overwrite property