diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 1bde585ab..d58368b79 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -183,6 +183,14 @@ result = _.first([1, 2, 3], function (num) { result = _.first(foodsOrganic, 'organic'); result = _.first(foodsType, { 'type': 'fruit' }); +result = _([1, 2, 3]).first(); +result = _([1, 2, 3]).first(2).value(); +result = _([1, 2, 3]).first(function (num) { + return num < 3; +}).value(); +result = _(foodsOrganic).first('organic').value(); +result = _(foodsType).first({ 'type': 'fruit' }).value(); + result = _.head([1, 2, 3]); result = _.head([1, 2, 3], 2); result = _.head([1, 2, 3], function (num) { @@ -191,12 +199,28 @@ result = _.head([1, 2, 3], function (num) { result = _.head(foodsOrganic, 'organic'); result = _.head(foodsType, { 'type': 'fruit' }); +result = _([1, 2, 3]).head(); +result = _([1, 2, 3]).head(2).value(); +result = _([1, 2, 3]).head(function (num) { + return num < 3; +}).value(); +result = _(foodsOrganic).head('organic').value(); +result = _(foodsType).head({ 'type': 'fruit' }).value(); + 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 = _([1, 2, 3]).take(); +result = _([1, 2, 3]).take(2).value(); +result = _([1, 2, 3]).take(function (num) { + return num < 3; +}).value(); +result = _(foodsOrganic).take('organic').value(); +result = _(foodsType).take({ 'type': 'fruit' }).value(); + result = _.flatten([1, [2], [3, [[4]]]]); result = _.flatten([1, [2], [3, [[4]]]], true); var result: any @@ -277,6 +301,22 @@ result = _.unique(['A', 'b', 'C', 'a', 'B', 'c'], function (letter) { result = _.unique([1, 2.5, 3, 1.5, 2, 3.5], function (num) { return this.floor(num); }, Math); result = <{ x: number; }[]>_.unique([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); +result = _([1, 2, 1, 3, 1]).uniq().value(); +result = _([1, 1, 2, 2, 3]).uniq(true).value(); +result = _(['A', 'b', 'C', 'a', 'B', 'c']).uniq(function (letter) { + return letter.toLowerCase(); +}).value(); +result = _([1, 2.5, 3, 1.5, 2, 3.5]).uniq(function (num) { return this.floor(num); }, Math).value(); +result = <{ x: number; }[]>_([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }]).uniq('x').value(); + +result = _([1, 2, 1, 3, 1]).unique().value(); +result = _([1, 1, 2, 2, 3]).unique(true).value(); +result = _(['A', 'b', 'C', 'a', 'B', 'c']).unique(function (letter) { + return letter.toLowerCase(); +}).value(); +result = _([1, 2.5, 3, 1.5, 2, 3.5]).unique(function (num) { return this.floor(num); }, Math).value(); +result = <{ x: number; }[]>_([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }]).unique('x').value(); + result = _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); result = _.zip(['moe', 'larry'], [30, 40], [true, false]); @@ -357,9 +397,11 @@ result = _.findLast(foodsCombined, 'organic'); result = _.forEach([1, 2, 3], function (num) { console.log(num); }); result = <_.Dictionary>_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); +result = _.forEach({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) }); result = _.each([1, 2, 3], function (num) { console.log(num); }); result = <_.Dictionary>_.each({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); +result = _.each({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) }); result = <_.LoDashArrayWrapper>_([1, 2, 3]).forEach(function (num) { console.log(num); }); result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).forEach(function (num) { console.log(num); }); @@ -419,16 +461,18 @@ result = _.min(stoogesAges, function (stooge) { return stooge.age; result = _.min(stoogesAges, 'age'); result = _.pluck(stoogesAges, 'name'); +result = _(stoogesAges).pluck('name').value(); -result = _.reduce([1, 2, 3], function (sum: number, num: number) { - return sum + num; -}); interface ABC { [index: string]: number; a: number; b: number; c: number; } + +result = _.reduce([1, 2, 3], function (sum: number, num: number) { + return sum + num; +}); result = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num: number, key: string) { r[key] = num * 3; return r; @@ -450,6 +494,30 @@ result = _.inject({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num: number return r; }, {}); +result = _([1, 2, 3]).reduce(function (sum: number, num: number) { + return sum + num; +}); +result = _({ 'a': 1, 'b': 2, 'c': 3 }).reduce(function (r: ABC, num: number, key: string) { + r[key] = num * 3; + return r; +}, {}); + +result = _([1, 2, 3]).foldl(function (sum: number, num: number) { + return sum + num; +}); +result = _({ 'a': 1, 'b': 2, 'c': 3 }).foldl(function (r: ABC, num: number, key: string) { + r[key] = num * 3; + return r; +}, {}); + +result = _([1, 2, 3]).inject(function (sum: number, num: number) { + return sum + num; +}); +result = _({ 'a': 1, 'b': 2, 'c': 3 }).inject(function (r: ABC, num: number, key: string) { + r[key] = num * 3; + return r; +}, {}); + result = _.reduceRight([[0, 1], [2, 3], [4, 5]], function (a: number[], b: number[]) { return a.concat(b); }, []); result = _.foldr([[0, 1], [2, 3], [4, 5]], function (a: number[], b: number[]) { return a.concat(b); }, []); @@ -457,6 +525,10 @@ result = _.reject([1, 2, 3, 4, 5, 6], function (num) { return num % 2 result = _.reject(foodsCombined, 'organic'); result = _.reject(foodsCombined, { 'type': 'fruit' }); +result = _([1, 2, 3, 4, 5, 6]).reject(function (num) { return num % 2 == 0; }).value(); +result = _(foodsCombined).reject('organic').value(); +result = _(foodsCombined).reject({ 'type': 'fruit' }).value(); + result = _.sample([1, 2, 3, 4]); result = _.sample([1, 2, 3, 4], 2); @@ -480,11 +552,18 @@ 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'); +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(); + (function (a: number, b: number, c: number, d: number) { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); result = _.where(stoogesCombined, { 'age': 40 }); result = _.where(stoogesCombined, { 'quotes': ['Poifect!'] }); +result = _(stoogesCombined).where({ 'age': 40 }).value(); +result = _(stoogesCombined).where({ 'quotes': ['Poifect!'] }).value(); + /************* * Functions * *************/ @@ -834,6 +913,7 @@ result = _.isString('moe'); result = _.isUndefined(void 0); result = _.keys({ 'one': 1, 'two': 2, 'three': 3 }); +result = _({ 'one': 1, 'two': 2, 'three': 3 }).keys().value(); var mergeNames = { 'stooges': [ @@ -879,8 +959,14 @@ result = _.omit({ 'name': 'moe', 'age': 40 }, ['age']); result = _.omit({ 'name': 'moe', 'age': 40 }, function (value) { return typeof value == 'number'; }); +result = _({ 'name': 'moe', 'age': 40 }).omit('age').value(); +result = _({ 'name': 'moe', 'age': 40 }).omit(['age']).value(); +result = _({ 'name': 'moe', 'age': 40 }).omit(function (value) { + return typeof value == 'number'; +}).value(); result = _.pairs({ 'moe': 30, 'larry': 40 }); +result = _({ 'moe': 30, 'larry': 40 }).pairs().value(); result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, 'name'); result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, ['name']); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 594f20973..e51a59825 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -644,6 +644,104 @@ declare module _ { whereValue: W): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.first + **/ + first(): T; + + /** + * @see _.first + * @param n The number of elements to return. + **/ + first(n: number): LoDashArrayWrapper; + + /** + * @see _.first + * @param callback The function called per element. + * @param [thisArg] The this binding of callback. + **/ + first( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.first + * @param pluckValue "_.pluck" style callback value + **/ + first(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.first + * @param whereValue "_.where" style callback value + **/ + first(whereValue: W): LoDashArrayWrapper; + + /** + * @see _.first + **/ + head(): T; + + /** + * @see _.first + * @param n The number of elements to return. + **/ + head(n: number): LoDashArrayWrapper; + + /** + * @see _.first + * @param callback The function called per element. + * @param [thisArg] The this binding of callback. + **/ + head( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.first + * @param pluckValue "_.pluck" style callback value + **/ + head(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.first + * @param whereValue "_.where" style callback value + **/ + head(whereValue: W): LoDashArrayWrapper; + + /** + * @see _.first + **/ + take(): T; + + /** + * @see _.first + * @param n The number of elements to return. + **/ + take(n: number): LoDashArrayWrapper; + + /** + * @see _.first + * @param callback The function called per element. + * @param [thisArg] The this binding of callback. + **/ + take( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.first + * @param pluckValue "_.pluck" style callback value + **/ + take(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.first + * @param whereValue "_.where" style callback value + **/ + take(whereValue: W): LoDashArrayWrapper; + } + //_.flatten interface LoDashStatic { /** @@ -1750,6 +1848,106 @@ declare module _ { whereValue?: W): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.uniq + **/ + uniq(isSorted?: boolean): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + uniq( + isSorted: boolean, + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + uniq( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + uniq( + isSorted: boolean, + pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + uniq(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + uniq( + isSorted: boolean, + whereValue: W): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + uniq( + whereValue: W): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + unique(isSorted?: boolean): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + unique( + isSorted: boolean, + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.uniq + **/ + unique( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + unique( + isSorted: boolean, + pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + unique(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + unique( + isSorted: boolean, + whereValue: W): LoDashArrayWrapper; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + unique( + whereValue: W): LoDashArrayWrapper; + } + //_.without interface LoDashStatic { /** @@ -2741,6 +2939,14 @@ declare module _ { callback: ObjectIterator, thisArg?: any): Dictionary; + /** + * @see _.each + **/ + forEach( + object: T, + callback: ObjectIterator, + thisArg?: any): T + /** * @see _.forEach **/ @@ -2767,6 +2973,14 @@ declare module _ { object: Dictionary, callback: ObjectIterator, thisArg?: any): Dictionary; + + /** + * @see _.each + **/ + each( + object: T, + callback: ObjectIterator, + thisArg?: any): T } interface LoDashArrayWrapper { @@ -3444,6 +3658,22 @@ declare module _ { property: string): any[]; } + interface LoDashArrayWrapper { + /** + * @see _.pluck + **/ + pluck( + property: string): LoDashArrayWrapper; + } + + interface LoDashObjectWrapper { + /** + * @see _.pluck + **/ + pluck( + property: string): LoDashArrayWrapper; + } + //_.reduce interface LoDashStatic { /** @@ -3609,6 +3839,100 @@ declare module _ { thisArg?: any): TResult; } + interface LoDashArrayWrapper { + /** + * @see _.reduce + **/ + reduce( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + reduce( + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + callback: MemoIterator, + thisArg?: any): TResult; + } + + interface LoDashObjectWrapper { + /** + * @see _.reduce + **/ + reduce( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + reduce( + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + callback: MemoIterator, + thisArg?: any): TResult; + } + //_.reduceRight interface LoDashStatic { /** @@ -3806,6 +4130,27 @@ declare module _ { whereValue: W): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.reject + **/ + reject( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.reject + * @param pluckValue _.pluck style callback + **/ + reject(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.reject + * @param whereValue _.where style callback + **/ + reject(whereValue: W): LoDashArrayWrapper; + } + //_.sample interface LoDashStatic { /** @@ -4134,6 +4479,27 @@ declare module _ { whereValue: W): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.sortBy + **/ + sortBy( + callback?: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.sortBy + * @param pluckValue _.pluck style callback + **/ + sortBy(pluckValue: string): LoDashArrayWrapper; + + /** + * @see _.sortBy + * @param whereValue _.where style callback + **/ + sortBy(whereValue: W): LoDashArrayWrapper; + } + //_.toArray interface LoDashStatic { /** @@ -4182,6 +4548,13 @@ declare module _ { properties: U): T[]; } + interface LoDashArrayWrapper { + /** + * @see _.where + **/ + where(properties: U): LoDashArrayWrapper; + } + /************* * Functions * *************/ @@ -5296,6 +5669,13 @@ declare module _ { keys(object: any): string[]; } + interface LoDashObjectWrapper { + /** + * @see _.keys + **/ + keys(): LoDashArrayWrapper + } + //_.mapValues interface LoDashStatic { /** @@ -5407,6 +5787,27 @@ declare module _ { thisArg?: any): Omitted; } + interface LoDashObjectWrapper { + /** + * @see _.omit + **/ + omit( + ...keys: string[]): LoDashObjectWrapper; + + /** + * @see _.omit + **/ + omit( + keys: string[]): LoDashObjectWrapper; + + /** + * @see _.omit + **/ + omit( + callback: ObjectIterator, + thisArg?: any): LoDashObjectWrapper; + } + //_.pairs interface LoDashStatic { /** @@ -5418,6 +5819,13 @@ declare module _ { pairs(object: any): any[][]; } + interface LoDashObjectWrapper { + /** + * @see _.pairs + **/ + pairs(): LoDashArrayWrapper; + } + //_.picks interface LoDashStatic { /**