mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
_ function documentation, added _ function core array methods
This commit is contained in:
+15
-2
@@ -93,6 +93,19 @@ result = <_.LoDashWrapper<string[]>>_(['test1', 'test2']).chain();
|
||||
result = <_.LoDashWrapper<string>>_.chain('test');
|
||||
result = <_.LoDashWrapper<string[]>>_.chain(['test1', 'test2']);
|
||||
|
||||
result = <_.LoDashWrapper<number[]>>_([1, 2, 3, 4]).concat([5, 6, 7]);
|
||||
result = <_.LoDashWrapper<string>>_([1, 2, 3, 4]).join(',');
|
||||
result = <_.LoDashWrapper<number>>_([1, 2, 3, 4]).pop();
|
||||
_([1, 2, 3, 4]).push(5, 6, 7);
|
||||
result = <_.LoDashWrapper<number[]>>_([1, 2, 3, 4]).reverse();
|
||||
result = <_.LoDashWrapper<number>>_([1, 2, 3, 4]).shift();
|
||||
result = <_.LoDashWrapper<number[]>>_([1, 2, 3, 4]).slice(1, 2);
|
||||
result = <_.LoDashWrapper<number[]>>_([1, 2, 3, 4]).slice(2);
|
||||
result = <_.LoDashWrapper<number[]>>_([1, 2, 3, 4]).sort((a, b) => 1);
|
||||
result = <_.LoDashWrapper<number[]>>_([1, 2, 3, 4]).splice(1);
|
||||
result = <_.LoDashWrapper<number[]>>_([1, 2, 3, 4]).splice(1, 2, 5, 6);
|
||||
result = <_.LoDashWrapper<number>>_([1, 2, 3, 4]).unshift(5, 6);
|
||||
|
||||
result = <number[]>_.tap([1, 2, 3, 4], function(array) { console.log(array); });
|
||||
result = <_.LoDashWrapper<number[]>>_([1, 2, 3, 4]).tap(function(array) { console.log(array); });
|
||||
|
||||
@@ -483,8 +496,8 @@ var greet = function(formatted) {
|
||||
return 'Hiya ' + formatted + '!';
|
||||
};
|
||||
|
||||
var welcome: Function = _.compose(greet, format);
|
||||
welcome('curly');
|
||||
result = <Function>_.compose(greet, format);
|
||||
result = <_.LoDashWrapper<Function>>_(greet).compose(format);
|
||||
|
||||
var createCallbackObj = { name: 'Joe' };
|
||||
var pluckCallback: () => any = _.createCallback('name');
|
||||
|
||||
Vendored
+54
-6
@@ -6,16 +6,42 @@
|
||||
// Heavily based on Underscore definitions by Boris Yankov
|
||||
|
||||
/**
|
||||
* Lo-Dash OOP Wrapper, all Lo-Dash functions that take an object
|
||||
* as the first parameter can be invoked through this function.
|
||||
* @param key First argument to Lo-Dash object functions.
|
||||
* Creates a lodash object which wraps the given value to enable intuitive method chaining.
|
||||
*
|
||||
* In addition to Lo-Dash methods, wrappers also have the following Array methods:
|
||||
* concat, join, pop, push, reverse, shift, slice, sort, splice, and unshift
|
||||
*
|
||||
* Chaining is supported in custom builds as long as the value method is implicitly or explicitly
|
||||
* included in the build.
|
||||
*
|
||||
* The chainable wrapper functions are:
|
||||
* after, assign, bind, bindAll, bindKey, chain, compact, compose, concat, countBy, createCallback,
|
||||
* curry, debounce, defaults, defer, delay, difference, filter, flatten, forEach, forEachRight,
|
||||
* forIn, forInRight, forOwn, forOwnRight, functions, groupBy, indexBy, initial, intersection,
|
||||
* invert, invoke, keys, map, max, memoize, merge, min, object, omit, once, pairs, partial,
|
||||
* partialRight, pick, pluck, pull, push, range, reject, remove, rest, reverse, shuffle, slice, sort,
|
||||
* sortBy, splice, tap, throttle, times, toArray, transform, union, uniq, unshift, unzip, values,
|
||||
* where, without, wrap, and zip
|
||||
*
|
||||
* The non-chainable wrapper functions are:
|
||||
* clone, cloneDeep, contains, escape, every, find, findIndex, findKey, findLast, findLastIndex,
|
||||
* findLastKey, has, identity, indexOf, isArguments, isArray, isBoolean, isDate, isElement, isEmpty,
|
||||
* isEqual, isFinite, isFunction, isNaN, isNull, isNumber, isObject, isPlainObject, isRegExp,
|
||||
* isString, isUndefined, join, lastIndexOf, mixin, noConflict, parseInt, pop, random, reduce,
|
||||
* reduceRight, result, shift, size, some, sortedIndex, runInContext, template, unescape, uniqueId,
|
||||
* and value
|
||||
*
|
||||
* The wrapper functions first and last return wrapped values when n is provided, otherwise they
|
||||
* return unwrapped values.
|
||||
*
|
||||
* Explicit chaining can be enabled by using the _.chain method.
|
||||
* @param value The value to wrap in a lodash instance.
|
||||
* @return A lodash instance.
|
||||
**/
|
||||
declare function _<T>(value: Array<T>): _.LoDashWrapper<Array<T>>;
|
||||
declare function _<T>(value: T): _.LoDashWrapper<T>;
|
||||
declare function _<T>(value: T[]): _.LoDashWrapper<T[]>;
|
||||
|
||||
declare module _ {
|
||||
interface LoDashWrapper<T> {}
|
||||
|
||||
/**
|
||||
* lodash.js _.debounce options
|
||||
**/
|
||||
@@ -190,6 +216,21 @@ declare module _ {
|
||||
/*********
|
||||
* Chaining *
|
||||
**********/
|
||||
|
||||
//Wrapper Array methods
|
||||
interface LoDashWrapper<T> {
|
||||
concat(...items: any[]): LoDashWrapper<T>;
|
||||
join(seperator?: string): LoDashWrapper<string>;
|
||||
pop(): LoDashWrapper<any>;
|
||||
push(...items: any[]): void;
|
||||
reverse(): LoDashWrapper<T>;
|
||||
shift(): LoDashWrapper<any>;
|
||||
slice(start: number, end?: number): LoDashWrapper<T>;
|
||||
sort(compareFn?: (a: any, b: any) => number): LoDashWrapper<T>;
|
||||
splice(start: number): LoDashWrapper<T>;
|
||||
splice(start: number, deleteCount: number, ...items: any[]): LoDashWrapper<T>;
|
||||
unshift(...items: any[]): LoDashWrapper<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a lodash object that wraps the given value with explicit method chaining enabled.
|
||||
@@ -1970,6 +2011,13 @@ declare module _ {
|
||||
**/
|
||||
export function compose(...funcs: Function[]): Function;
|
||||
|
||||
interface LoDashWrapper<T> {
|
||||
/**
|
||||
* @see _.compose
|
||||
**/
|
||||
compose(...funcs: Function[]): LoDashWrapper<Function>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a callback bound to an optional thisArg. If func is a property name the created
|
||||
* callback will return the property value for a given element. If func is an object the created
|
||||
|
||||
Reference in New Issue
Block a user