From b0b86846bd466b9ff2cbd60f131be06980e03b0b Mon Sep 17 00:00:00 2001 From: Matt DeKrey Date: Mon, 27 Jul 2015 15:40:53 -0400 Subject: [PATCH] Partial updates for lodash to 3.10.0 --- lodash/lodash-tests.ts | 20 +++--- lodash/lodash.d.ts | 134 +++++++++++++++++++++++++---------------- 2 files changed, 93 insertions(+), 61 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 627dda565..ca5ad80d1 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -221,19 +221,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]); @@ -310,6 +310,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) { @@ -392,6 +394,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' }); @@ -654,6 +657,7 @@ result = _.sortBy(['banana', 'strawberry', 'apple'], 'length'); 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 7bc1df648..d49e4104f 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -615,12 +615,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 @@ -637,48 +637,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 { @@ -749,7 +737,7 @@ declare module _ { /** * @see _.first **/ - take(): T; + take(): LoDashArrayWrapper; /** * @see _.first @@ -758,25 +746,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> { } @@ -1519,6 +1510,13 @@ declare module _ { **/ union(...arrays: List[]): T[]; } + + interface LoDashArrayWrapper { + /** + * @see _.union + **/ + union(...arrays: (Array|List)[]): LoDashArrayWrapper; + } //_.uniq interface LoDashStatic { @@ -2427,6 +2425,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 @@ -2585,6 +2593,11 @@ declare module _ { } interface LoDashArrayWrapper { + /** + * @see _.filter + **/ + filter(): LoDashArrayWrapper; + /** * @see _.filter **/ @@ -4805,6 +4818,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 { @@ -4826,6 +4848,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; } //_.toArray