diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index 8cf98071b..c0812265e 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -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, 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( + array: _.List, + predicate: _.ListIterator, + 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( + array: _.List, + predicate: _.ListIterator, + 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 { **/ zip(...arrays: any[][]): any[][]; + /** + * Wrapped type `any[][]`. + * @see _.unzip + **/ + unzip(...arrays: any[][]): any[][]; + /** * Wrapped type `any[][]`. * @see _.object @@ -2107,6 +2177,16 @@ interface Underscore { **/ lastIndexOf(value: T, from?: number): number; + /** + * @see _.findIndex + **/ + findIndex(array: _.List, predicate: _.ListIterator, context?: any): number; + + /** + * @see _.findLastIndex + **/ + findLastIndex(array: _.List, predicate: _.ListIterator, context?: any): number; + /** * Wrapped type `any[]`. * @see _.sortedIndex @@ -2228,6 +2308,12 @@ interface Underscore { **/ keys(): string[]; + /** + * Wrapped type `object`. + * @see _.allKeys + **/ + allKeys(): string[]; + /** * Wrapped type `object`. * @see _.values @@ -2314,6 +2400,12 @@ interface Underscore { * @see _.property **/ property(): (object: Object) => any; + + /** + * Wrapped type `object`. + * @see _.propertyOf + **/ + propertyOf(): (key: string) => any; /** * Wrapped type `object`. @@ -2326,6 +2418,12 @@ interface Underscore { * @see _.isEmpty **/ isEmpty(): boolean; + + /** + * Wrapped type `object`. + * @see _.isMatch + **/ + isMatch(): boolean; /** * Wrapped type `object`. @@ -2356,6 +2454,12 @@ interface Underscore { * @see _.isFunction **/ isFunction(): boolean; + + /** + * Wrapped type `object`. + * @see _.isError + **/ + isError(): boolean; /** * Wrapped type `object`. @@ -2484,7 +2588,7 @@ interface Underscore { * Wrapped type `object`. * @see _.result **/ - result(property: string): any; + result(property: string, defaultValue?:any): any; /** * Wrapped type `string`. @@ -2957,6 +3061,12 @@ interface _Chain { **/ zip(...arrays: any[][]): _Chain; + /** + * Wrapped type `any[][]`. + * @see _.unzip + **/ + unzip(...arrays: any[][]): _Chain; + /** * Wrapped type `any[][]`. * @see _.object @@ -2985,6 +3095,16 @@ interface _Chain { **/ lastIndexOf(value: T, from?: number): _ChainSingle; + /** + * @see _.findIndex + **/ + findIndex(predicate: _.ListIterator, context?: any): _Chain; + + /** + * @see _.findLastIndex + **/ + findLastIndex(predicate: _.ListIterator, context?: any): _Chain; + /** * Wrapped type `any[]`. * @see _.sortedIndex @@ -3106,6 +3226,12 @@ interface _Chain { **/ keys(): _Chain; + /** + * Wrapped type `object`. + * @see _.allKeys + **/ + allKeys(): _Chain; + /** * Wrapped type `object`. * @see _.values @@ -3192,6 +3318,12 @@ interface _Chain { * @see _.property **/ property(): _Chain; + + /** + * Wrapped type `object`. + * @see _.propertyOf + **/ + propertyOf(): _Chain; /** * Wrapped type `object`. @@ -3204,6 +3336,12 @@ interface _Chain { * @see _.isEmpty **/ isEmpty(): _Chain; + + /** + * Wrapped type `object`. + * @see _.isMatch + **/ + isMatch(): _Chain; /** * Wrapped type `object`. @@ -3235,6 +3373,12 @@ interface _Chain { **/ isFunction(): _Chain; + /** + * Wrapped type `object`. + * @see _.isError + **/ + isError(): _Chain; + /** * Wrapped type `object`. * @see _.isString @@ -3362,7 +3506,7 @@ interface _Chain { * Wrapped type `object`. * @see _.result **/ - result(property: string): _Chain; + result(property: string, defaultValue?:any): _Chain; /** * Wrapped type `string`.