diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 70b288f09..0e90d8ee1 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -240,19 +240,19 @@ result = _([1, 2, 3]).head(function (num) { result = _(foodsOrganic).head('organic').value(); result = _(foodsType).head({ 'type': 'fruit' }).value(); -result = _.take([1, 2, 3]); +result = _.take([1, 2, 3]); result = _.take([1, 2, 3], 2); -result = _.take([1, 2, 3], (num) => num < 3); -result = _.take(foodsOrganic, 'organic'); -result = _.take(foodsType, { 'type': 'fruit' }); +result = _.takeWhile([1, 2, 3], (num) => num < 3); +result = _.takeWhile(foodsOrganic, 'organic'); +result = _.takeWhile(foodsType, { 'type': 'fruit' }); -result = _([1, 2, 3]).take(); +result = _([1, 2, 3]).take().value(); result = _([1, 2, 3]).take(2).value(); -result = _([1, 2, 3]).take(function (num) { +result = _([1, 2, 3]).takeWhile(function (num) { return num < 3; }).value(); -result = _(foodsOrganic).take('organic').value(); -result = _(foodsType).take({ 'type': 'fruit' }).value(); +result = _(foodsType).takeWhile('organic').value(); +result = _(foodsType).takeWhile({ 'type': 'fruit' }).value(); result = >_.flatten([[1, 2], [3, 4]]); result = >_.flatten([[1, 2], [3, 4], 5, 6]); @@ -329,6 +329,8 @@ result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function result = _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); +result = _([1, 2, 3]).union([101, 2, 1, 10], [2, 1]).value(); + result = _.uniq([1, 2, 1, 3, 1]); result = _.uniq([1, 1, 2, 2, 3], true); result = _.uniq(['A', 'b', 'C', 'a', 'B', 'c'], function (letter) { @@ -438,6 +440,7 @@ result = _.all([true, 1, null, 'yes'], Boolean); result = _.all(stoogesAges, 'age'); result = _.all(stoogesAges, { 'age': 50 }); +result = _.filter([1, 2, 3, 4, 5, 6]); result = _.filter([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); result = _.filter(foodsCombined, 'organic'); result = _.filter(foodsCombined, { 'type': 'fruit' }); @@ -742,6 +745,7 @@ result = _.sortByOrder(stoogesAges, ['name', function(stooge) { r 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(); (function (a: number, b: number, c: number, d: number): Array { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); result = _.toArray([1, 2, 3, 4]); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 10a00f41f..907a2fa46 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -664,12 +664,12 @@ declare module _ { /** * @see _.first **/ - take(array: Array): T; + take(array: Array): T[]; /** * @see _.first **/ - take(array: List): T; + take(array: List): T[]; /** * @see _.first @@ -686,48 +686,36 @@ declare module _ { n: number): T[]; /** - * @see _.first - **/ - take( - array: Array, - callback: ListIterator, - thisArg?: any): T[]; - + * Takes the first items from an array or list based on a predicate + * @param array The array or list of items on which the result set will be based + * @param predicate A predicate function to determine whether a value will be taken. Optional; defaults to identity. + * @param [thisArg] The this binding of predicate. + */ + takeWhile( + array: (Array|List), + predicate?: ListIterator, + thisArg?: any + ): T[]; + /** - * @see _.first - **/ - take( - array: List, - callback: ListIterator, - thisArg?: any): T[]; - + * Takes the first items from an array or list based on a predicate + * @param array The array or list of items on which the result set will be based + * @param pluckValue Uses a _.property style callback to return the property value of the given element + */ + takeWhile( + array: (Array|List), + pluckValue: string + ): any[]; + /** - * @see _.first - **/ - take( - array: Array, - pluckValue: string): T[]; - - /** - * @see _.first - **/ - take( - array: List, - pluckValue: string): T[]; - - /** - * @see _.first - **/ - take( - array: Array, - whereValue: W): T[]; - - /** - * @see _.first - **/ - take( - array: List, - whereValue: W): T[]; + * Takes the first items from an array or list based on a predicate + * @param array The array or list of items on which the result set will be based + * @param whereValue Uses a _.matches style callback to return the first elements that match the given value + */ + takeWhile( + array: (Array|List), + whereValue: W + ): T[]; } interface LoDashArrayWrapper { @@ -798,7 +786,7 @@ declare module _ { /** * @see _.first **/ - take(): T; + take(): LoDashArrayWrapper; /** * @see _.first @@ -807,25 +795,28 @@ declare module _ { take(n: number): LoDashArrayWrapper; /** - * @see _.first - * @param callback The function called per element. + * Takes the first items based on a predicate + * @param predicate The function called per element. * @param [thisArg] The this binding of callback. **/ - take( - callback: ListIterator, + takeWhile( + predicate: ListIterator, thisArg?: any): LoDashArrayWrapper; /** - * @see _.first - * @param pluckValue "_.pluck" style callback value + * Takes the first items based on a predicate + * @param pluckValue Uses a _.property style callback to return the property value of the given element **/ - take(pluckValue: string): LoDashArrayWrapper; + takeWhile( + pluckValue: string): LoDashArrayWrapper; /** - * @see _.first - * @param whereValue "_.where" style callback value + * Takes the first items based on a predicate + * @param whereValue Uses a _.matches style callback to return the first elements that match the given value **/ - take(whereValue: W): LoDashArrayWrapper; + takeWhile( + whereValue: W): LoDashArrayWrapper; + } interface MaybeNestedList extends List> { } @@ -1536,6 +1527,13 @@ declare module _ { **/ union(...arrays: List[]): T[]; } + + interface LoDashArrayWrapper { + /** + * @see _.union + **/ + union(...arrays: (Array|List)[]): LoDashArrayWrapper; + } //_.uniq interface LoDashStatic { @@ -2517,6 +2515,16 @@ declare module _ { //_.filter interface LoDashStatic { + /** + * Iterates over elements of a collection, returning an array of all elements the + * identity function returns truey for. + * + * @param collection The collection to iterate over. + * @return Returns a new array of elements that passed the callback check. + **/ + filter( + collection: (Array|List)): T[]; + /** * Iterates over elements of a collection, returning an array of all elements the * callback returns truey for. The callback is bound to thisArg and invoked with three @@ -2675,6 +2683,11 @@ declare module _ { } interface LoDashArrayWrapper { + /** + * @see _.filter + **/ + filter(): LoDashArrayWrapper; + /** * @see _.filter **/ @@ -4939,6 +4952,15 @@ declare module _ { 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 + */ + sortByAll( + collection: (Array|List), + ...args: (ListIterator|Object|string)[] + ): T[]; } interface LoDashArrayWrapper { @@ -4960,6 +4982,12 @@ declare module _ { * @param whereValue _.where style callback **/ sortBy(whereValue: W): LoDashArrayWrapper; + + /** + * 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)[]): LoDashArrayWrapper; } //_.sortByAll