From 5968a6823b92a16a778e62946bee3a4d9d73e503 Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Mon, 2 Jun 2014 22:40:45 -0400 Subject: [PATCH] Added chainable definitions for _(...).first and aliases --- lodash/lodash-tests.ts | 24 +++++++++++ lodash/lodash.d.ts | 98 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 6ee7ad464..1836d459e 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 diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 053787bd8..2a599cdf3 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 { /**