Merge pull request #7376 from dfurtado/master

Functions introduced in underscore JS 1.8
This commit is contained in:
Masahiro Wakame
2016-01-10 01:20:10 +09:00
+147 -3
View File
@@ -900,6 +900,16 @@ interface UnderscoreStatic {
**/
zip(...arrays: any[]): any[];
/**
* The opposite of zip. Given a number of arrays, returns a series of new arrays, the first
* of which contains all of the first elements in the input arrays, the second of which
* contains all of the second elements, and so on. Use with apply to pass in an array
* of arrays
* @param arrays The arrays to unzip.
* @return Unzipped version of `arrays`.
**/
unzip(...arrays: any[][]): any[][];
/**
* Converts arrays into objects. Pass either a single list of [key, value] pairs, or a
* list of keys, and a list of values.
@@ -961,6 +971,30 @@ interface UnderscoreStatic {
array: _.List<T>,
value: T,
from?: number): number;
/**
* Returns the first index of an element in `array` where the predicate truth test passes
* @param array The array to search for the index of the first element where the predicate truth test passes.
* @param predicate Predicate function.
* @param context `this` object in `predicate`, optional.
* @return Returns the index of an element in `array` where the predicate truth test passes or -1.`
**/
findIndex<T>(
array: _.List<T>,
predicate: _.ListIterator<T, boolean>,
context?: any): number;
/**
* Returns the last index of an element in `array` where the predicate truth test passes
* @param array The array to search for the index of the last element where the predicate truth test passes.
* @param predicate Predicate function.
* @param context `this` object in `predicate`, optional.
* @return Returns the index of an element in `array` where the predicate truth test passes or -1.`
**/
findLastIndex<T>(
array: _.List<T>,
predicate: _.ListIterator<T, boolean>,
context?: any): number;
/**
* Uses a binary search to determine the index at which the value should be inserted into the list in order
@@ -1192,6 +1226,13 @@ interface UnderscoreStatic {
**/
keys(object: any): string[];
/**
* Retrieve all the names of object's own and inherited properties.
* @param object Retrieve the key or property names from this object.
* @return List of all the property names on `object`.
**/
allKeys(object: any): string[];
/**
* Return all of the values of the object's properties.
* @param object Retrieve the values of all the properties on this object.
@@ -1371,6 +1412,13 @@ interface UnderscoreStatic {
**/
property(key: string): (object: Object) => any;
/**
* Returns a function that will itself return the value of a object key property.
* @param key The object to get the property value from.
* @return Function which accept a key property in `object` and returns its value.
**/
propertyOf(object: Object): (key: string) => any;
/**
* Performs an optimized deep comparison between the two objects,
* to determine if they should be considered equal.
@@ -1387,6 +1435,14 @@ interface UnderscoreStatic {
**/
isEmpty(object: any): boolean;
/**
* Returns true if the keys and values in `properties` matches with the `object` properties.
* @param object Object to be compared with `properties`.
* @param properties Properties be compared with `object`
* @return True if `object` has matching keys and values, otherwise false.
**/
isMatch(object:any, properties:any): boolean;
/**
* Returns true if object is a DOM element.
* @param object Check if this object is a DOM element.
@@ -1422,6 +1478,13 @@ interface UnderscoreStatic {
* @return True if `object` is a Function, otherwise false.
**/
isFunction(object: any): boolean;
/**
* Returns true if object inherits from an Error.
* @param object Check if this object is an Error.
* @return True if `object` is a Error, otherwise false.
**/
isError(object:any): boolean;
/**
* Returns true if object is a String.
@@ -1598,9 +1661,10 @@ interface UnderscoreStatic {
* If the value of the named property is a function then invoke it; otherwise, return it.
* @param object Object to maybe invoke function `property` on.
* @param property The function by name to invoke on `object`.
* @param defaultValue The value to be returned in case `property` doesn't exist or is undefined.
* @return The result of invoking the function `property` on `object.
**/
result(object: any, property: string): any;
result(object: any, property: string, defaultValue?:any): any;
/**
* Compiles JavaScript templates into functions that can be evaluated for rendering. Useful
@@ -2079,6 +2143,12 @@ interface Underscore<T> {
**/
zip(...arrays: any[][]): any[][];
/**
* Wrapped type `any[][]`.
* @see _.unzip
**/
unzip(...arrays: any[][]): any[][];
/**
* Wrapped type `any[][]`.
* @see _.object
@@ -2107,6 +2177,16 @@ interface Underscore<T> {
**/
lastIndexOf(value: T, from?: number): number;
/**
* @see _.findIndex
**/
findIndex<T>(array: _.List<T>, predicate: _.ListIterator<T, boolean>, context?: any): number;
/**
* @see _.findLastIndex
**/
findLastIndex<T>(array: _.List<T>, predicate: _.ListIterator<T, boolean>, context?: any): number;
/**
* Wrapped type `any[]`.
* @see _.sortedIndex
@@ -2228,6 +2308,12 @@ interface Underscore<T> {
**/
keys(): string[];
/**
* Wrapped type `object`.
* @see _.allKeys
**/
allKeys(): string[];
/**
* Wrapped type `object`.
* @see _.values
@@ -2314,6 +2400,12 @@ interface Underscore<T> {
* @see _.property
**/
property(): (object: Object) => any;
/**
* Wrapped type `object`.
* @see _.propertyOf
**/
propertyOf(): (key: string) => any;
/**
* Wrapped type `object`.
@@ -2326,6 +2418,12 @@ interface Underscore<T> {
* @see _.isEmpty
**/
isEmpty(): boolean;
/**
* Wrapped type `object`.
* @see _.isMatch
**/
isMatch(): boolean;
/**
* Wrapped type `object`.
@@ -2356,6 +2454,12 @@ interface Underscore<T> {
* @see _.isFunction
**/
isFunction(): boolean;
/**
* Wrapped type `object`.
* @see _.isError
**/
isError(): boolean;
/**
* Wrapped type `object`.
@@ -2484,7 +2588,7 @@ interface Underscore<T> {
* Wrapped type `object`.
* @see _.result
**/
result(property: string): any;
result(property: string, defaultValue?:any): any;
/**
* Wrapped type `string`.
@@ -2957,6 +3061,12 @@ interface _Chain<T> {
**/
zip(...arrays: any[][]): _Chain<T>;
/**
* Wrapped type `any[][]`.
* @see _.unzip
**/
unzip(...arrays: any[][]): _Chain<T>;
/**
* Wrapped type `any[][]`.
* @see _.object
@@ -2985,6 +3095,16 @@ interface _Chain<T> {
**/
lastIndexOf(value: T, from?: number): _ChainSingle<T>;
/**
* @see _.findIndex
**/
findIndex<T>(predicate: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
/**
* @see _.findLastIndex
**/
findLastIndex<T>(predicate: _.ListIterator<T, boolean>, context?: any): _Chain<T>;
/**
* Wrapped type `any[]`.
* @see _.sortedIndex
@@ -3106,6 +3226,12 @@ interface _Chain<T> {
**/
keys(): _Chain<string>;
/**
* Wrapped type `object`.
* @see _.allKeys
**/
allKeys(): _Chain<string>;
/**
* Wrapped type `object`.
* @see _.values
@@ -3192,6 +3318,12 @@ interface _Chain<T> {
* @see _.property
**/
property(): _Chain<T>;
/**
* Wrapped type `object`.
* @see _.propertyOf
**/
propertyOf(): _Chain<T>;
/**
* Wrapped type `object`.
@@ -3204,6 +3336,12 @@ interface _Chain<T> {
* @see _.isEmpty
**/
isEmpty(): _Chain<T>;
/**
* Wrapped type `object`.
* @see _.isMatch
**/
isMatch(): _Chain<T>;
/**
* Wrapped type `object`.
@@ -3235,6 +3373,12 @@ interface _Chain<T> {
**/
isFunction(): _Chain<T>;
/**
* Wrapped type `object`.
* @see _.isError
**/
isError(): _Chain<T>;
/**
* Wrapped type `object`.
* @see _.isString
@@ -3362,7 +3506,7 @@ interface _Chain<T> {
* Wrapped type `object`.
* @see _.result
**/
result(property: string): _Chain<T>;
result(property: string, defaultValue?:any): _Chain<T>;
/**
* Wrapped type `string`.