lodash: added _.callback() method (alias iteratee)

This commit is contained in:
Ilya Mochalov
2015-09-16 00:58:30 +05:00
parent 52b0ea5c97
commit 98bb252474
2 changed files with 158 additions and 3 deletions
+49 -3
View File
@@ -1941,9 +1941,32 @@ result = <string[]>_.words('fred, barney, & pebbles', /[^, ]+/g);
result = <string[]>_('fred, barney, & pebbles').words();
result = <string[]>_('fred, barney, & pebbles').words(/[^, ]+/g);
/**********
* Utilities *
***********/
/***********
* Utility *
***********/
// _.callback
{
let result: (...args: any[]) => TResult;
result = _.callback<TResult>(Function);
result = _.callback<TResult>(Function, any);
result = _(Function).callback<TResult>().value();
result = _(Function).callback<TResult>(any).value();
}
{
let result: (object: any) => TResult;
result = _.callback<TResult>('');
result = _.callback<TResult>('', any);
result = _('').callback<TResult>().value();
result = _('').callback<TResult>(any).value();
}
{
let result: (object: any) => boolean;
result = _.callback({});
result = _.callback({}, any);
result = _({}).callback().value();
result = _({}).callback(any).value();
}
// _.constant
result = <() => number>_.constant<number>(1);
@@ -1973,6 +1996,29 @@ result = <() => {}>_({}).constant<{}>();
result = _<boolean>([]).identity();
}
// _.iteratee
{
let result: (...args: any[]) => TResult;
result = _.iteratee<TResult>(Function);
result = _.iteratee<TResult>(Function, any);
result = _(Function).iteratee<TResult>().value();
result = _(Function).iteratee<TResult>(any).value();
}
{
let result: (object: any) => TResult;
result = _.iteratee<TResult>('');
result = _.iteratee<TResult>('', any);
result = _('').iteratee<TResult>().value();
result = _('').iteratee<TResult>(any).value();
}
{
let result: (object: any) => boolean;
result = _.iteratee({});
result = _.iteratee({}, any);
result = _({}).iteratee().value();
result = _({}).iteratee(any).value();
}
// _.method
class TestMethod {
a = {
+109
View File
@@ -8117,6 +8117,64 @@ declare module _ {
attempt<TResult>(): TResult|Error;
}
//_.callback
interface LoDashStatic {
/**
* Creates a function that invokes func with the this binding of thisArg and arguments of the created function.
* If func is a property name the created callback returns the property value for a given element. If func is
* an object the created callback returns true for elements that contain the equivalent object properties,
* otherwise it returns false.
*
* @param func The value to convert to a callback.
* @param thisArg The this binding of func.
* @result Returns the callback.
*/
callback<TResult>(
func: Function,
thisArg?: any
): (...args: any[]) => TResult;
/**
* @see _.callback
*/
callback<TResult>(
func: string,
thisArg?: any
): (object: any) => TResult;
/**
* @see _.callback
*/
callback(
func: Object,
thisArg?: any
): (object: any) => boolean;
/**
* @see _.callback
*/
callback<TResult>(): (value: TResult) => TResult;
}
interface LoDashWrapper<T> {
/**
* @see _.callback
*/
callback<TResult>(thisArg?: any): LoDashObjectWrapper<(object: any) => TResult>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.callback
*/
callback(thisArg?: any): LoDashObjectWrapper<(object: any) => boolean>;
/**
* @see _.callback
*/
callback<TResult>(thisArg?: any): LoDashObjectWrapper<(...args: any[]) => TResult>;
}
//_.identity
interface LoDashStatic {
/**
@@ -8148,6 +8206,57 @@ declare module _ {
identity(): T;
}
//_.iteratee
interface LoDashStatic {
/**
* @see _.callback
*/
iteratee<TResult>(
func: Function,
thisArg?: any
): (...args: any[]) => TResult;
/**
* @see _.callback
*/
iteratee<TResult>(
func: string,
thisArg?: any
): (object: any) => TResult;
/**
* @see _.callback
*/
iteratee(
func: Object,
thisArg?: any
): (object: any) => boolean;
/**
* @see _.callback
*/
iteratee<TResult>(): (value: TResult) => TResult;
}
interface LoDashWrapper<T> {
/**
* @see _.callback
*/
iteratee<TResult>(thisArg?: any): LoDashObjectWrapper<(object: any) => TResult>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.callback
*/
iteratee(thisArg?: any): LoDashObjectWrapper<(object: any) => boolean>;
/**
* @see _.callback
*/
iteratee<TResult>(thisArg?: any): LoDashObjectWrapper<(...args: any[]) => TResult>;
}
//_.method
interface LoDashStatic {
/**