diff --git a/underscore/underscore-tests.ts b/underscore/underscore-tests.ts index 8e0162b58c..0fb7ac004e 100644 --- a/underscore/underscore-tests.ts +++ b/underscore/underscore-tests.ts @@ -33,6 +33,10 @@ _.every([true, 1, null, 'yes'], _.identity); _.any([null, 0, 'yes', false]); +_.some([1, 2, 3, 4], l => l % 3 === 0); + +_.some({ a: 'a', b: 'B', c: 'C', d: 'd' }, l => l === l.toUpperCase()); + _.contains([1, 2, 3], 3); _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); @@ -40,11 +44,11 @@ _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); var stooges = [{ name: 'moe', age: 40 }, { name: 'larry', age: 50 }, { name: 'curly', age: 60 }]; _.pluck(stooges, 'name'); -_.max<{ name: string; age: number }>(stooges, (stooge) => stooge.age); - -_.max([1, 2, 3, 4, 5]); +_.max(stooges, (stooge) => stooge.age); +_.min(stooges, (stooge) => stooge.age); var numbers = [10, 5, 100, 2, 1000]; +_.max(numbers); _.min(numbers); _.sortBy([1, 2, 3, 4, 5, 6], (num) => Math.sin(num)); diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index cc9a3e6e9d..9c95e4bcb7 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -96,8 +96,8 @@ interface UnderscoreStatic { /** * @see _.each - * @param object Iterators over this object's properties. - * @param iterator Iterator function for each property on `obj`. + * @param object Iterates over properties of this object. + * @param iterator Iterator function for each property on `object`. * @param context 'this' object in `iterator`, optional. **/ each( @@ -138,7 +138,7 @@ interface UnderscoreStatic { /** * @see _.map * @param object Maps the properties of this object. - * @param iterator Map iterator function for each property on `obj`. + * @param iterator Map iterator function for each property on `object`. * @param context `this` object in `iterator`, optional. * @return The mapped object result. **/ @@ -151,8 +151,8 @@ interface UnderscoreStatic { * @see _.map **/ collect( - list: _.List, iterator: - _.ListIterator, + list: _.List, + iterator: _.ListIterator, context?: any): TResult[]; /** @@ -241,7 +241,15 @@ interface UnderscoreStatic { * @see _.find **/ find( - list: _.Dictionary, + object: _.Dictionary, + iterator: _.ObjectIterator, + context?: any): T; + + /** + * @see _.find + **/ + detect( + list: _.List, iterator: _.ListIterator, context?: any): T; @@ -249,8 +257,8 @@ interface UnderscoreStatic { * @see _.find **/ detect( - list: _.Collection, - iterator: _.ListIterator, + object: _.Dictionary, + iterator: _.ObjectIterator, context?: any): T; /** @@ -270,7 +278,15 @@ interface UnderscoreStatic { * @see _.filter **/ filter( - list: _.Dictionary, + object: _.Dictionary, + iterator: _.ObjectIterator, + context?: any): T[]; + + /** + * @see _.filter + **/ + select( + list: _.List, iterator: _.ListIterator, context?: any): T[]; @@ -278,8 +294,8 @@ interface UnderscoreStatic { * @see _.filter **/ select( - list: _.Collection, - iterator: _.ListIterator, + object: _.Dictionary, + iterator: _.ObjectIterator, context?: any): T[]; /** @@ -290,7 +306,7 @@ interface UnderscoreStatic { * @return The elements within `list` that contain the required `properties`. **/ where( - list: _.Collection, + list: _.List, properties: U): T[]; /** @@ -321,8 +337,8 @@ interface UnderscoreStatic { * @see _.reject **/ reject( - list: _.Dictionary, - iterator: _.ListIterator, + object: _.Dictionary, + iterator: _.ObjectIterator, context?: any): T[]; /** @@ -334,18 +350,34 @@ interface UnderscoreStatic { * @return True if all elements passed the truth test, otherwise false. **/ every( - list: _.Collection, + list: _.List, iterator?: _.ListIterator, context?: any): boolean; /** - * @see _.all + * @see _.every + **/ + every( + list: _.Dictionary, + iterator?: _.ObjectIterator, + context?: any): boolean; + + /** + * @see _.every **/ all( - list: _.Collection, + list: _.List, iterator?: _.ListIterator, context?: any): boolean; + /** + * @see _.every + **/ + all( + list: _.Dictionary, + iterator?: _.ObjectIterator, + context?: any): boolean; + /** * Returns true if any of the values in the list pass the iterator truth test. Short-circuits and * stops traversing the list if a true element is found. Delegates to the native method some, if present. @@ -354,19 +386,35 @@ interface UnderscoreStatic { * @param context `this` object in `iterator`, optional. * @return True if any elements passed the truth test, otherwise false. **/ - any( - list: _.Collection, + some( + list: _.List, iterator?: _.ListIterator, context?: any): boolean; /** - * @see _.any + * @see _.some **/ some( - list: _.Collection, + object: _.Dictionary, + iterator?: _.ObjectIterator, + context?: any): boolean; + + /** + * @see _.some + **/ + any( + list: _.List, iterator?: _.ListIterator, context?: any): boolean; + /** + * @see _.some + **/ + any( + object: _.Dictionary, + iterator?: _.ObjectIterator, + context?: any): boolean; + /** * Returns true if the value is present in the list. Uses indexOf internally, * if list is an Array. @@ -375,7 +423,14 @@ interface UnderscoreStatic { * @return True if `value` is present in `list`, otherwise false. **/ contains( - list: _.Collection, + list: _.List, + value: T): boolean; + + /** + * @see _.contains + **/ + contains( + object: _.Dictionary, value: T): boolean; /** @@ -385,6 +440,13 @@ interface UnderscoreStatic { list: _.Collection, value: T): boolean; + /** + * @see _.contains + **/ + include( + object: _.Dictionary, + value: T): boolean; + /** * Calls the method named by methodName on each value in the list. Any extra arguments passed to * invoke will be forwarded on to the method invocation. @@ -393,7 +455,7 @@ interface UnderscoreStatic { * @param arguments Additional arguments to pass to the method `methodName`. **/ invoke( - list: _.Collection, + list: _.List, methodName: string, ...arguments: any[]): any; @@ -405,7 +467,7 @@ interface UnderscoreStatic { * @return The list of elements within `list` that have the property `propertyName`. **/ pluck( - list: _.Collection, + list: _.List, propertyName: string): any[]; /** @@ -424,7 +486,7 @@ interface UnderscoreStatic { * @return The maximum element within `list`. **/ max( - list: _.Collection, + list: _.List, iterator?: _.ListIterator, context?: any): T; @@ -444,7 +506,7 @@ interface UnderscoreStatic { * @return The minimum element within `list`. **/ min( - list: _.Collection, + list: _.List, iterator?: _.ListIterator, context?: any): T; @@ -530,7 +592,7 @@ interface UnderscoreStatic { * @param iterator Function name **/ countBy( - list: _.Dictionary, + list: _.List, iterator: string, context?: any): _.Dictionary;