Merge pull request #6033 from chrootsu/lodash-findKey

lodash: changed _.findKey() method
This commit is contained in:
Masahiro Wakame
2015-10-05 22:30:20 +09:00
2 changed files with 86 additions and 27 deletions
+25 -3
View File
@@ -1793,9 +1793,31 @@ var TestDefaultsDeepSource = {'user': {'name': 'fred', 'age': 36}};
result = <DefaultsDeepResult>_.defaultsDeep(TestDefaultsDeepObject, TestDefaultsDeepSource);
result = <DefaultsDeepResult>_(TestDefaultsDeepObject).defaultsDeep<DefaultsDeepResult>(TestDefaultsDeepSource).value();
result = <string>_.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) {
return num % 2 == 0;
});
// _.findKey
module TestFindKey {
let predicateFn: (value: any, key?: string, object?: {}) => boolean;
let result: string;
result = _.findKey<{a: string;}>({a: ''});
result = _.findKey<{a: string;}>({a: ''}, predicateFn);
result = _.findKey<{a: string;}>({a: ''}, predicateFn, any);
result = _.findKey<{a: string;}>({a: ''}, '');
result = _.findKey<{a: string;}>({a: ''}, '', any);
result = _.findKey<{a: number;}, {a: string;}>({a: ''}, {a: 42});
result = _<{a: string;}>({a: ''}).findKey();
result = _<{a: string;}>({a: ''}).findKey(predicateFn);
result = _<{a: string;}>({a: ''}).findKey(predicateFn, any);
result = _<{a: string;}>({a: ''}).findKey('');
result = _<{a: string;}>({a: ''}).findKey('', any);
result = _<{a: string;}>({a: ''}).findKey<{a: number;}>({a: 42});
}
result = <string>_.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) {
return num % 2 == 1;
+61 -24
View File
@@ -6925,33 +6925,70 @@ declare module _ {
//_.findKey
interface LoDashStatic {
/**
* 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.
**/
findKey(
object: any,
callback: (value: any) => boolean,
thisArg?: any): string;
* This method is like _.find except that it returns the key of the first element predicate returns truthy for
* instead of the element itself.
*
* If a property name is provided for predicate the created _.property style callback returns the property
* value of the given element.
*
* If a value is also provided for thisArg the created _.matchesProperty style callback returns true for
* elements that have a matching property value, else false.
*
* If an object is provided for predicate the created _.matches style callback returns true for elements that
* have the properties of the given object, else false.
*
* @param object The object to search.
* @param predicate The function invoked per iteration.
* @param thisArg The this binding of predicate.
* @return Returns the key of the matched element, else undefined.
*/
findKey<TObject>(
object: TObject,
predicate?: ObjectIterator<any, boolean>,
thisArg?: any
): string;
/**
* @see _.findKey
* @param pluckValue _.pluck style callback
**/
findKey(
object: any,
pluckValue: string): string;
* @see _.findKey
*/
findKey<TObject>(
object: TObject,
predicate?: string,
thisArg?: any
): string;
/**
* @see _.findKey
* @param whereValue _.where style callback
**/
findKey<W extends Dictionary<any>, T>(
object: T,
whereValue: W): string;
* @see _.findKey
*/
findKey<TWhere extends Dictionary<any>, TObject>(
object: TObject,
predicate?: TWhere
): string;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.findKey
*/
findKey(
predicate?: ObjectIterator<any, boolean>,
thisArg?: any
): string;
/**
* @see _.findKey
*/
findKey(
predicate?: string,
thisArg?: any
): string;
/**
* @see _.findKey
*/
findKey<TWhere extends Dictionary<any>>(
predicate?: TWhere
): string;
}
//_.findLastKey
@@ -8793,7 +8830,7 @@ declare module _ {
}
interface ObjectIterator<T, TResult> {
(element: T, key: string, collection: any): TResult;
(element: T, key?: string, collection?: any): TResult;
}
interface MemoVoidIterator<T, TResult> {