From af6a6531122b53795021b0a2e190d90ef7df4fd6 Mon Sep 17 00:00:00 2001 From: Daniel Furtado Date: Sun, 27 Dec 2015 16:58:55 +0100 Subject: [PATCH 1/8] Added _.isMatch function --- underscore/underscore.d.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index 8cf98071b..23646f044 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -1387,6 +1387,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. @@ -2326,6 +2334,12 @@ interface Underscore { * @see _.isEmpty **/ isEmpty(): boolean; + + /** + * Wrapped type `object`. + * @see _.isMatch + **/ + isMatch(): boolean; /** * Wrapped type `object`. @@ -3204,6 +3218,12 @@ interface _Chain { * @see _.isEmpty **/ isEmpty(): _Chain; + + /** + * Wrapped type `object`. + * @see _.isMatch + **/ + isMatch(): _Chain; /** * Wrapped type `object`. From 05774649a6121ee69c66912c352e20405392c755 Mon Sep 17 00:00:00 2001 From: Daniel Furtado Date: Sun, 27 Dec 2015 20:08:30 +0100 Subject: [PATCH 2/8] Added _.findIndex and _.findLastIndex functions --- underscore/underscore.d.ts | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index 23646f044..feca73688 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -961,6 +961,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 @@ -2115,6 +2139,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 @@ -2999,6 +3033,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 From b8a88f3bbaecf9f0155c8898e1420af212bef0ea Mon Sep 17 00:00:00 2001 From: Daniel Furtado Date: Mon, 28 Dec 2015 18:03:24 +0100 Subject: [PATCH 3/8] Added _.isError function --- underscore/underscore.d.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index feca73688..bdb2bdedd 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -1454,6 +1454,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. @@ -2404,6 +2411,12 @@ interface Underscore { * @see _.isFunction **/ isFunction(): boolean; + + /** + * Wrapped type `object`. + * @see _.isError + **/ + isError(): boolean; /** * Wrapped type `object`. @@ -3299,6 +3312,12 @@ interface _Chain { **/ isFunction(): _Chain; + /** + * Wrapped type `object`. + * @see _.isError + **/ + isError(): _Chain; + /** * Wrapped type `object`. * @see _.isString From 11bd75b0d8a331010e67afc8c505cf362699c99e Mon Sep 17 00:00:00 2001 From: Daniel Furtado Date: Mon, 28 Dec 2015 18:27:24 +0100 Subject: [PATCH 4/8] Added _.unzip function --- underscore/underscore.d.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index bdb2bdedd..d4743c63a 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. @@ -2118,6 +2128,12 @@ interface Underscore { **/ zip(...arrays: any[][]): any[][]; + /** + * Wrapped type `any[][]`. + * @see _.unzip + **/ + unzip(...arrays: any[][]): any[][]; + /** * Wrapped type `any[][]`. * @see _.object @@ -3018,6 +3034,12 @@ interface _Chain { **/ zip(...arrays: any[][]): _Chain; + /** + * Wrapped type `any[][]`. + * @see _.unzip + **/ + unzip(...arrays: any[][]): _Chain; + /** * Wrapped type `any[][]`. * @see _.object From 7f99c0aed229f65ed237d79c09aa25498becff05 Mon Sep 17 00:00:00 2001 From: Daniel Furtado Date: Mon, 28 Dec 2015 18:40:21 +0100 Subject: [PATCH 5/8] Added optional default value property for the _.result function --- underscore/underscore.d.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index d4743c63a..87d5b0919 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -1647,9 +1647,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 @@ -2561,7 +2562,7 @@ interface Underscore { * Wrapped type `object`. * @see _.result **/ - result(property: string): any; + result(property: string, defaultValue?:any): any; /** * Wrapped type `string`. @@ -3467,7 +3468,7 @@ interface _Chain { * Wrapped type `object`. * @see _.result **/ - result(property: string): _Chain; + result(property: string, defaultValue?:any): _Chain; /** * Wrapped type `string`. From 5566b0981806d02273a95665600c48e03c2e7c6f Mon Sep 17 00:00:00 2001 From: Daniel Furtado Date: Mon, 28 Dec 2015 19:03:37 +0100 Subject: [PATCH 6/8] Added _.propertyOf function --- underscore/underscore.d.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index 87d5b0919..95dbd3bcf 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -1405,6 +1405,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. @@ -2380,6 +2387,12 @@ interface Underscore { * @see _.property **/ property(): (object: Object) => any; + + /** + * Wrapped type `object`. + * @see _.propertyOf + **/ + propertyOf(): (key: string) => any; /** * Wrapped type `object`. @@ -3286,6 +3299,12 @@ interface _Chain { * @see _.property **/ property(): _Chain; + + /** + * Wrapped type `object`. + * @see _.propertyOf + **/ + propertyOf(): _Chain; /** * Wrapped type `object`. From 28dfdd9964e4c62bafaf7d4417f2e3b38f9d8e2b Mon Sep 17 00:00:00 2001 From: Daniel Furtado Date: Mon, 28 Dec 2015 19:13:22 +0100 Subject: [PATCH 7/8] Added _.allKeys function --- underscore/underscore.d.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index 95dbd3bcf..bec1dca8c 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -1226,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. @@ -2301,6 +2308,12 @@ interface Underscore { **/ keys(): string[]; + /** + * Wrapped type `object`. + * @see _.allKeys + **/ + allKeys(): string[]; + /** * Wrapped type `object`. * @see _.values @@ -3213,6 +3226,12 @@ interface _Chain { **/ keys(): _Chain; + /** + * Wrapped type `object`. + * @see _.allKeys + **/ + allKeys(): _Chain; + /** * Wrapped type `object`. * @see _.values From 0a5ebc36fe759d618728a08811e29cc619e83ecb Mon Sep 17 00:00:00 2001 From: Daniel Furtado Date: Mon, 28 Dec 2015 19:27:45 +0100 Subject: [PATCH 8/8] Fixed comments for the functions _.findIndex and _.findLastIndex --- underscore/underscore.d.ts | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index bec1dca8c..c0812265e 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -973,24 +973,24 @@ interface UnderscoreStatic { 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.` - **/ + * 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.` - **/ + * 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, @@ -2178,13 +2178,13 @@ interface Underscore { lastIndexOf(value: T, from?: number): number; /** - * @see _.findIndex - **/ + * @see _.findIndex + **/ findIndex(array: _.List, predicate: _.ListIterator, context?: any): number; /** - * @see _.findLastIndex - **/ + * @see _.findLastIndex + **/ findLastIndex(array: _.List, predicate: _.ListIterator, context?: any): number; /** @@ -3096,13 +3096,13 @@ interface _Chain { lastIndexOf(value: T, from?: number): _ChainSingle; /** - * @see _.findIndex - **/ + * @see _.findIndex + **/ findIndex(predicate: _.ListIterator, context?: any): _Chain; /** - * @see _.findLastIndex - **/ + * @see _.findLastIndex + **/ findLastIndex(predicate: _.ListIterator, context?: any): _Chain; /**