diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index f8318107e7..41b80f49c1 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -7185,52 +7185,18 @@ module TestFloor { module TestMax { let array: number[]; let list: _.List; - let dictionary: _.Dictionary; - - let listIterator: (value: number, index: number, collection: _.List) => number; - let dictionaryIterator: (value: number, key: string, collection: _.Dictionary) => number; let result: number; result = _.max(array); - result = _.max(array, listIterator); - result = _.max(array, listIterator, any); - result = _.max(array, ''); - result = _.max<{a: number}, number>(array, {a: 42}); - result = _.max(list); - result = _.max(list, listIterator); - result = _.max(list, listIterator, any); - result = _.max(list, ''); - result = _.max<{a: number}, number>(list, {a: 42}); - - result = _.max(dictionary); - result = _.max(dictionary, dictionaryIterator); - result = _.max(dictionary, dictionaryIterator, any); - result = _.max(dictionary, ''); - result = _.max<{a: number}, number>(dictionary, {a: 42}); result = _(array).max(); - result = _(array).max(listIterator); - result = _(array).max(listIterator, any); - result = _(array).max(''); - result = _(array).max<{a: number}>({a: 42}); - result = _(list).max(); - result = _(list).max(listIterator); - result = _(list).max(listIterator, any); - result = _(list).max(''); - result = _(list).max<{a: number}, number>({a: 42}); - - result = _(dictionary).max(); - result = _(dictionary).max(dictionaryIterator); - result = _(dictionary).max(dictionaryIterator, any); - result = _(dictionary).max(''); - result = _(dictionary).max<{a: number}, number>({a: 42}); } -// _.min -module TestMin { +// _.maxBy +module TestMaxBy { let array: number[]; let list: _.List; let dictionary: _.Dictionary; @@ -7240,41 +7206,92 @@ module TestMin { let result: number; + result = _.maxBy(array); + result = _.maxBy(array, listIterator); + result = _.maxBy(array, ''); + result = _.maxBy<{a: number}, number>(array, {a: 42}); + + result = _.maxBy(list); + result = _.maxBy(list, listIterator); + result = _.maxBy(list, ''); + result = _.maxBy<{a: number}, number>(list, {a: 42}); + + result = _.maxBy(dictionary); + result = _.maxBy(dictionary, dictionaryIterator); + result = _.maxBy(dictionary, ''); + result = _.maxBy<{a: number}, number>(dictionary, {a: 42}); + + result = _(array).maxBy(); + result = _(array).maxBy(listIterator); + result = _(array).maxBy(''); + result = _(array).maxBy<{a: number}>({a: 42}); + + result = _(list).maxBy(); + result = _(list).maxBy(listIterator); + result = _(list).maxBy(''); + result = _(list).maxBy<{a: number}, number>({a: 42}); + + result = _(dictionary).maxBy(); + result = _(dictionary).maxBy(dictionaryIterator); + result = _(dictionary).maxBy(''); + result = _(dictionary).maxBy<{a: number}, number>({a: 42}); +} + +// _.min +module TestMin { + let array: number[]; + let list: _.List; + + let result: number; + result = _.min(array); - result = _.min(array, listIterator); - result = _.min(array, listIterator, any); - result = _.min(array, ''); - result = _.min<{a: number}, number>(array, {a: 42}); - result = _.min(list); - result = _.min(list, listIterator); - result = _.min(list, listIterator, any); - result = _.min(list, ''); - result = _.min<{a: number}, number>(list, {a: 42}); - - result = _.min(dictionary); - result = _.min(dictionary, dictionaryIterator); - result = _.min(dictionary, dictionaryIterator, any); - result = _.min(dictionary, ''); - result = _.min<{a: number}, number>(dictionary, {a: 42}); result = _(array).min(); - result = _(array).min(listIterator); - result = _(array).min(listIterator, any); - result = _(array).min(''); - result = _(array).min<{a: number}>({a: 42}); - result = _(list).min(); - result = _(list).min(listIterator); - result = _(list).min(listIterator, any); - result = _(list).min(''); - result = _(list).min<{a: number}, number>({a: 42}); - result = _(dictionary).min(); - result = _(dictionary).min(dictionaryIterator); - result = _(dictionary).min(dictionaryIterator, any); - result = _(dictionary).min(''); - result = _(dictionary).min<{a: number}, number>({a: 42}); +} + +// _.minBy +module TestMinBy { + let array: number[]; + let list: _.List; + let dictionary: _.Dictionary; + + let listIterator: (value: number, index: number, collection: _.List) => number; + let dictionaryIterator: (value: number, key: string, collection: _.Dictionary) => number; + + let result: number; + + result = _.minBy(array); + result = _.minBy(array, listIterator); + result = _.minBy(array, ''); + result = _.minBy<{a: number}, number>(array, {a: 42}); + + result = _.minBy(list); + result = _.minBy(list, listIterator); + result = _.minBy(list, ''); + result = _.minBy<{a: number}, number>(list, {a: 42}); + + result = _.minBy(dictionary); + result = _.minBy(dictionary, dictionaryIterator); + result = _.minBy(dictionary, ''); + result = _.minBy<{a: number}, number>(dictionary, {a: 42}); + + result = _(array).minBy(); + result = _(array).minBy(listIterator); + result = _(array).minBy(''); + result = _(array).minBy<{a: number}>({a: 42}); + + result = _(list).minBy(); + result = _(list).minBy(listIterator); + result = _(list).minBy(''); + result = _(list).minBy<{a: number}, number>({a: 42}); + + result = _(dictionary).minBy(); + result = _(dictionary).minBy(dictionaryIterator); + result = _(dictionary).minBy(''); + result = _(dictionary).minBy<{a: number}, number>({a: 42}); } // _.round diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f12d06adab..793aaca1fb 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -26,7 +26,7 @@ TODO: - [x] Renamed _.restParam to _.rest - [x] Renamed _.sortByOrder to _.orderBy - [x] Renamed _.trimLeft & _.trimRight to _.trimStart & _.trimEnd -- [ ] Renamed _.trunc to _.truncate +- [x] Renamed _.trunc to _.truncate - [ ] Split _.indexOf & _.lastIndexOf into _.sortedIndexOf & _.sortedLastIndexOf - [ ] Split _.max & _.min into _.maxBy & _.minBy @@ -37,10 +37,10 @@ TODO: - [ ] Split _.uniq into _.sortedUniq, _.sortedUniqBy, & _.uniqBy - [ ] Absorbed _.sortByAll into _.sortBy -- [ ] Changed the category of _.at to “Object” -- [ ] Changed the category of _.bindAll to “Utility” +- [x] Changed the category of _.at to “Object” +- [x] Changed the category of _.bindAll to “Utility” - [ ] Made “By” methods provide a single param to iteratees -- [ ] Made _.capitalize uppercase the first character & lowercase the rest +- [x] Made _.capitalize uppercase the first character & lowercase the rest - [ ] Made _.functions return only own method names - [ ] Made _.words chainable by default - [ ] Removed isDeep params from _.clone & _.flatten @@ -10137,6 +10137,7 @@ declare module _ { * Note: This method is loosely based on the structured clone algorithm. The enumerable properties of arguments * objects and objects created by constructors other than Object are cloned to plain Object objects. An empty * object is returned for uncloneable values such as functions, DOM nodes, Maps, Sets, and WeakMaps. + * * @param value The value to clone. * @param isDeep Specify a deep clone. * @param customizer The function to customize cloning values. @@ -11142,55 +11143,18 @@ declare module _ { //_.max interface LoDashStatic { - /** - * Gets the maximum value of collection. If collection is empty or falsey -Infinity is returned. If an iteratee - * function is provided it’s invoked for each value in collection to generate the criterion by which the value - * is ranked. The iteratee is bound to thisArg and invoked with three arguments: (value, index, collection). - * - * If a property name is provided for iteratee the created _.property style callback returns the property value - * of the given element. - * - * If a value is also provided for thisArg the created _.matchesProperty style callback returns true for - * elements that have a matching property value, else false. - * - * If an object is provided for iteratee the created _.matches style callback returns true for elements that - * have the properties of the given object, else false. - * - * @param collection The collection to iterate over. - * @param iteratee The function invoked per iteration. - * @param thisArg The this binding of iteratee. - * @return Returns the maximum value. - */ + /** + * Computes the maximum value of `array`. If `array` is empty or falsey + * `undefined` is returned. + * + * @static + * @memberOf _ + * @category Math + * @param {Array} array The array to iterate over. + * @returns {*} Returns the maximum value. + */ max( - collection: List, - iteratee?: ListIterator, - thisArg?: any - ): T; - - /** - * @see _.max - */ - max( - collection: Dictionary, - iteratee?: DictionaryIterator, - thisArg?: any - ): T; - - /** - * @see _.max - */ - max( - collection: List|Dictionary, - iteratee?: string, - thisArg?: any - ): T; - - /** - * @see _.max - */ - max( - collection: List|Dictionary, - whereValue?: TObject + collection: List ): T; } @@ -11198,48 +11162,114 @@ declare module _ { /** * @see _.max */ - max( - iteratee?: ListIterator, - thisArg?: any - ): T; - - /** - * @see _.max - */ - max( - iteratee?: string, - thisArg?: any - ): T; - - /** - * @see _.max - */ - max( - whereValue?: TObject - ): T; + max(): T; } interface LoDashImplicitObjectWrapper { /** * @see _.max */ - max( + max(): T; + } + + //_.maxBy + interface LoDashStatic { + /** + * This method is like `_.max` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the criterion by which + * the value is ranked. The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @category Math + * @param {Array} array The array to iterate over. + * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @returns {*} Returns the maximum value. + * @example + * + * var objects = [{ 'n': 1 }, { 'n': 2 }]; + * + * _.maxBy(objects, function(o) { return o.a; }); + * // => { 'n': 2 } + * + * // using the `_.property` iteratee shorthand + * _.maxBy(objects, 'n'); + * // => { 'n': 2 } + */ + maxBy( + collection: List, + iteratee?: ListIterator + ): T; + + /** + * @see _.maxBy + */ + maxBy( + collection: Dictionary, + iteratee?: DictionaryIterator + ): T; + + /** + * @see _.maxBy + */ + maxBy( + collection: List|Dictionary, + iteratee?: string + ): T; + + /** + * @see _.maxBy + */ + maxBy( + collection: List|Dictionary, + whereValue?: TObject + ): T; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.maxBy + */ + maxBy( + iteratee?: ListIterator + ): T; + + /** + * @see _.maxBy + */ + maxBy( + iteratee?: string + ): T; + + /** + * @see _.maxBy + */ + maxBy( + whereValue?: TObject + ): T; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.maxBy + */ + maxBy( iteratee?: ListIterator|DictionaryIterator, thisArg?: any ): T; /** - * @see _.max + * @see _.maxBy */ - max( + maxBy( iteratee?: string, thisArg?: any ): T; /** - * @see _.max + * @see _.maxBy */ - max( + maxBy( whereValue?: TObject ): T; } @@ -11247,54 +11277,17 @@ declare module _ { //_.min interface LoDashStatic { /** - * Gets the minimum value of collection. If collection is empty or falsey Infinity is returned. If an iteratee - * function is provided it’s invoked for each value in collection to generate the criterion by which the value - * is ranked. The iteratee is bound to thisArg and invoked with three arguments: (value, index, collection). + * Computes the minimum value of `array`. If `array` is empty or falsey + * `undefined` is returned. * - * If a property name is provided for iteratee the created _.property style callback returns the property value - * of the given element. - * - * If a value is also provided for thisArg the created _.matchesProperty style callback returns true for - * elements that have a matching property value, else false. - * - * If an object is provided for iteratee the created _.matches style callback returns true for elements that - * have the properties of the given object, else false. - * - * @param collection The collection to iterate over. - * @param iteratee The function invoked per iteration. - * @param thisArg The this binding of iteratee. - * @return Returns the minimum value. + * @static + * @memberOf _ + * @category Math + * @param {Array} array The array to iterate over. + * @returns {*} Returns the minimum value. */ min( - collection: List, - iteratee?: ListIterator, - thisArg?: any - ): T; - - /** - * @see _.min - */ - min( - collection: Dictionary, - iteratee?: DictionaryIterator, - thisArg?: any - ): T; - - /** - * @see _.min - */ - min( - collection: List|Dictionary, - iteratee?: string, - thisArg?: any - ): T; - - /** - * @see _.min - */ - min( - collection: List|Dictionary, - whereValue?: TObject + collection: List ): T; } @@ -11302,48 +11295,114 @@ declare module _ { /** * @see _.min */ - min( - iteratee?: ListIterator, - thisArg?: any - ): T; - - /** - * @see _.min - */ - min( - iteratee?: string, - thisArg?: any - ): T; - - /** - * @see _.min - */ - min( - whereValue?: TObject - ): T; + min(): T; } interface LoDashImplicitObjectWrapper { /** * @see _.min */ - min( + min(): T; + } + + //_.minBy + interface LoDashStatic { + /** + * This method is like `_.min` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the criterion by which + * the value is ranked. The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @category Math + * @param {Array} array The array to iterate over. + * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element. + * @returns {*} Returns the minimum value. + * @example + * + * var objects = [{ 'n': 1 }, { 'n': 2 }]; + * + * _.minBy(objects, function(o) { return o.a; }); + * // => { 'n': 1 } + * + * // using the `_.property` iteratee shorthand + * _.minBy(objects, 'n'); + * // => { 'n': 1 } + */ + minBy( + collection: List, + iteratee?: ListIterator + ): T; + + /** + * @see _.minBy + */ + minBy( + collection: Dictionary, + iteratee?: DictionaryIterator + ): T; + + /** + * @see _.minBy + */ + minBy( + collection: List|Dictionary, + iteratee?: string + ): T; + + /** + * @see _.minBy + */ + minBy( + collection: List|Dictionary, + whereValue?: TObject + ): T; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.minBy + */ + minBy( + iteratee?: ListIterator + ): T; + + /** + * @see _.minBy + */ + minBy( + iteratee?: string + ): T; + + /** + * @see _.minBy + */ + minBy( + whereValue?: TObject + ): T; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.minBy + */ + minBy( iteratee?: ListIterator|DictionaryIterator, thisArg?: any ): T; /** - * @see _.min + * @see _.minBy */ - min( + minBy( iteratee?: string, thisArg?: any ): T; /** - * @see _.min + * @see _.minBy */ - min( + minBy( whereValue?: TObject ): T; }