diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index abe109c6e..63f36e263 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -2964,9 +2964,81 @@ module TestSome { } } -result = _.sortBy([1, 2, 3], function (num) { return Math.sin(num); }); -result = _.sortBy([1, 2, 3], function (num) { return this.sin(num); }, Math); -result = _.sortBy(['banana', 'strawberry', 'apple'], 'length'); +// _.sortBy +module TestSortBy { + let array: TResult[]; + let list: _.List; + let dictionary: _.Dictionary; + + let listIterator: (value: TResult, index: number, collection: _.List) => number; + let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary) => number; + + { + let result: TResult[]; + + result = _.sortBy(array); + result = _.sortBy(array, listIterator); + result = _.sortBy(array, listIterator, any); + result = _.sortBy(array, ''); + result = _.sortBy<{a: number}, TResult>(array, {a: 42}); + + result = _.sortBy(list); + result = _.sortBy(list, listIterator); + result = _.sortBy(list, listIterator, any); + result = _.sortBy(list, ''); + result = _.sortBy<{a: number}, TResult>(list, {a: 42}); + + result = _.sortBy(dictionary); + result = _.sortBy(dictionary, dictionaryIterator); + result = _.sortBy(dictionary, dictionaryIterator, any); + result = _.sortBy(dictionary, ''); + result = _.sortBy<{a: number}, TResult>(dictionary, {a: 42}); + } + + { + let result: _.LoDashImplicitArrayWrapper; + + result = _(array).sortBy(); + result = _(array).sortBy(listIterator); + result = _(array).sortBy(listIterator, any); + result = _(array).sortBy(''); + result = _(array).sortBy<{a: number}>({a: 42}); + + result = _(list).sortBy(); + result = _(list).sortBy(listIterator); + result = _(list).sortBy(listIterator, any); + result = _(list).sortBy(''); + result = _(list).sortBy<{a: number}, TResult>({a: 42}); + + result = _(dictionary).sortBy(); + result = _(dictionary).sortBy(dictionaryIterator); + result = _(dictionary).sortBy(dictionaryIterator, any); + result = _(dictionary).sortBy(''); + result = _(dictionary).sortBy<{a: number}, TResult>({a: 42}); + } + + { + let result: _.LoDashExplicitArrayWrapper; + + result = _(array).chain().sortBy(); + result = _(array).chain().sortBy(listIterator); + result = _(array).chain().sortBy(listIterator, any); + result = _(array).chain().sortBy(''); + result = _(array).chain().sortBy<{a: number}>({a: 42}); + + result = _(list).chain().sortBy(); + result = _(list).chain().sortBy(listIterator); + result = _(list).chain().sortBy(listIterator, any); + result = _(list).chain().sortBy(''); + result = _(list).chain().sortBy<{a: number}, TResult>({a: 42}); + + result = _(dictionary).chain().sortBy(); + result = _(dictionary).chain().sortBy(dictionaryIterator); + result = _(dictionary).chain().sortBy(dictionaryIterator, any); + result = _(dictionary).chain().sortBy(''); + result = _(dictionary).chain().sortBy<{a: number}, TResult>({a: 42}); + } +} result = _.sortByAll(stoogesAges, function(stooge) { return Math.sin(stooge.age); }, function(stooge) { return stooge.name.slice(1); }); result = _.sortByAll(stoogesAges, ['name', 'age']); @@ -2982,9 +3054,6 @@ result = _.sortByOrder(stoogesAges, [function(stooge) { return Ma result = _.sortByOrder(stoogesAges, ['name', 'age'], [true, false]); result = _.sortByOrder(stoogesAges, ['name', function(stooge) { return Math.sin(stooge.age); }], [true, false]); -result = _([1, 2, 3]).sortBy(function (num) { return Math.sin(num); }).value(); -result = _([1, 2, 3]).sortBy(function (num) { return this.sin(num); }, Math).value(); -result = _(['banana', 'strawberry', 'apple']).sortBy('length').value(); result = _(foodsOrganic).sortByAll('organic', (food) => food.name, { organic: true }).value(); result = _.where(stoogesCombined, { 'age': 40 }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 7f20d7aa8..6fe30eb1f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -6247,104 +6247,162 @@ declare module _ { //_.sortBy interface LoDashStatic { /** - * Creates an array of elements, sorted in ascending order by the results of running each - * element in a collection through the callback. This method performs a stable sort, that - * is, it will preserve the original sort order of equal elements. The callback is bound - * to thisArg and invoked with three arguments; (value, index|key, collection). - * - * If a property name is provided for callback the created "_.pluck" style callback will - * return 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 an 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 callback The function called per iteration. - * @param thisArg The this binding of callback. - * @return A new array of sorted elements. - **/ - sortBy( - collection: Array, - iteratee?: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.sortBy - **/ - sortBy( - collection: List, - iteratee?: ListIterator, - thisArg?: any): T[]; - - /** - * @see _.sortBy - * @param pluckValue _.pluck style callback - **/ - sortBy( - collection: Array, - pluckValue: string): T[]; - - /** - * @see _.sortBy - * @param pluckValue _.pluck style callback - **/ - sortBy( - collection: List, - pluckValue: string): T[]; - - /** - * @see _.sortBy - * @param whereValue _.where style callback - **/ - sortBy( - collection: Array, - whereValue: W): T[]; - - /** - * @see _.sortBy - * @param whereValue _.where style callback - **/ - sortBy( - collection: List, - whereValue: W): T[]; - - /** - * Sorts by all the given arguments, using either ListIterator, pluckValue, or whereValue foramts - * @param args The rules by which to sort + * Creates an array of elements, sorted in ascending order by the results of running each element in a + * collection through iteratee. This method performs a stable sort, that is, it preserves the original sort + * order of equal elements. The iteratee is bound to thisArg and invoked with three arguments: + * (value, index|key, collection). + * + * If a property name is provided for iteratee the created _.property style callback returns the property + * valueof 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 new sorted array. */ - sortByAll( - collection: (Array|List), - ...args: (ListIterator|Object|string)[] + sortBy( + collection: List, + iteratee?: ListIterator, + thisArg?: any + ): T[]; + + /** + * @see _.sortBy + */ + sortBy( + collection: Dictionary, + iteratee?: DictionaryIterator, + thisArg?: any + ): T[]; + + /** + * @see _.sortBy + */ + sortBy( + collection: List|Dictionary, + iteratee: string + ): T[]; + + /** + * @see _.sortBy + */ + sortBy( + collection: List|Dictionary, + whereValue: W + ): T[]; + + /** + * @see _.sortBy + */ + sortBy( + collection: List|Dictionary ): T[]; } interface LoDashImplicitArrayWrapper { /** - * @see _.sortBy - **/ + * @see _.sortBy + */ sortBy( iteratee?: ListIterator, - thisArg?: any): LoDashImplicitArrayWrapper; + thisArg?: any + ): LoDashImplicitArrayWrapper; /** - * @see _.sortBy - * @param pluckValue _.pluck style callback - **/ - sortBy(pluckValue: string): LoDashImplicitArrayWrapper; - - /** - * @see _.sortBy - * @param whereValue _.where style callback - **/ - sortBy(whereValue: W): LoDashImplicitArrayWrapper; - - /** - * Sorts by all the given arguments, using either ListIterator, pluckValue, or whereValue foramts - * @param args The rules by which to sort + * @see _.sortBy */ - sortByAll(...args: (ListIterator|Object|string)[]): LoDashImplicitArrayWrapper; + sortBy(iteratee: string): LoDashImplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(whereValue: W): LoDashImplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(): LoDashImplicitArrayWrapper; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.sortBy + */ + sortBy( + iteratee?: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashImplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(iteratee: string): LoDashImplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(whereValue: W): LoDashImplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(): LoDashImplicitArrayWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.sortBy + */ + sortBy( + iteratee?: ListIterator, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(iteratee: string): LoDashExplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(whereValue: W): LoDashExplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.sortBy + */ + sortBy( + iteratee?: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(iteratee: string): LoDashExplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(whereValue: W): LoDashExplicitArrayWrapper; + + /** + * @see _.sortBy + */ + sortBy(): LoDashExplicitArrayWrapper; } //_.sortByAll @@ -6391,9 +6449,24 @@ declare module _ { sortByAll( collection: List, ...iteratees: (ListIterator|string|Object)[]): T[]; + + /** + * Sorts by all the given arguments, using either ListIterator, pluckValue, or whereValue foramts + * @param args The rules by which to sort + */ + sortByAll( + collection: (Array|List), + ...args: (ListIterator|Object|string)[] + ): T[]; } interface LoDashImplicitArrayWrapper { + /** + * Sorts by all the given arguments, using either ListIterator, pluckValue, or whereValue foramts + * @param args The rules by which to sort + */ + sortByAll(...args: (ListIterator|Object|string)[]): LoDashImplicitArrayWrapper; + /** * @see _.sortByAll **/