From b5fb5ecf07dbe61d81bda07d4ecaaca537f813b1 Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Tue, 1 Apr 2014 21:40:57 -0400 Subject: [PATCH 01/49] Fixed up lodash with support for Array, List, Dictionary. Some test cases are still failing, this seems to due to inference of result types, like for use in the accumulator methods (foldl for example). Most of these could be resolved by using the correct generic type. I was trying to avoid this type of fix for the tests. --- lodash/lodash-tests.disabled.ts | 633 +++--- lodash/lodash.d.ts | 3305 ++++++++++++++++++++++++------- 2 files changed, 2899 insertions(+), 1039 deletions(-) diff --git a/lodash/lodash-tests.disabled.ts b/lodash/lodash-tests.disabled.ts index aca0bbdf0b..97c2709405 100644 --- a/lodash/lodash-tests.disabled.ts +++ b/lodash/lodash-tests.disabled.ts @@ -41,16 +41,16 @@ interface IKey { var foodsOrganic: IFoodOrganic[] = [ { name: 'banana', organic: true }, - { name: 'beet', organic: false }, + { name: 'beet', organic: false }, ]; var foodsType: IFoodType[] = [ - { name: 'apple', type: 'fruit' }, + { name: 'apple', type: 'fruit' }, { name: 'banana', type: 'fruit' }, - { name: 'beet', type: 'vegetable' } + { name: 'beet', type: 'vegetable' } ]; var foodsCombined: IFoodCombined[] = [ - { 'name': 'apple', 'organic': false, 'type': 'fruit' }, - { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } ]; var stoogesQuotes: IStoogesQuote[] = [ @@ -63,24 +63,24 @@ var stoogesAges: IStoogesAge[] = [ ]; var stoogesCombined: IStoogesCombined[] = [ - { 'name': 'curly', 'age': 30, 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, - { 'name': 'moe', 'age': 40, 'quotes': ['Spread out!', 'You knucklehead!'] } + { 'name': 'curly', 'age': 30, 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, + { 'name': 'moe', 'age': 40, 'quotes': ['Spread out!', 'You knucklehead!'] } ]; var keys: IKey[] = [ - { 'dir': 'left', 'code': 97 }, - { 'dir': 'right', 'code': 100 } + { 'dir': 'left', 'code': 97 }, + { 'dir': 'right', 'code': 100 } ]; class Dog { - constructor(public name: string) {} + constructor(public name: string) { } public bark() { - console.log('Woof, woof!'); + console.log('Woof, woof!'); } } -var result : any; +var result: any; /************* * Chaining * @@ -89,7 +89,10 @@ result = <_.LoDashWrapper>_('test'); result = <_.LoDashWrapper>_(1); result = <_.LoDashWrapper>_(true); result = <_.LoDashArrayWrapper>_(['test1', 'test2']); -result = <_.LoDashObjectWrapper<_.Dictionary>>_({'key1': 'test1', 'key2': 'test2'}); +// Appears to be a change in the compiler, if the type explicity implements the object indexer. +// Looking at: https://typescript.codeplex.com/wikipage?title=Known%20breaking%20changes%20between%200.8%20and%200.9&referringTitle=Documentation +// "The ‘noimplicitany’ option now warns on the use of the hidden default indexer" +result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }); result = <_.LoDashWrapper>_.chain('test'); result = <_.LoDashWrapper>_('test').chain(); @@ -99,8 +102,8 @@ result = <_.LoDashWrapper>_.chain(true); result = <_.LoDashWrapper>_(true).chain(); result = <_.LoDashArrayWrapper>_.chain(['test1', 'test2']); result = <_.LoDashArrayWrapper>_(['test1', 'test2']).chain(); -result = <_.LoDashObjectWrapper<_.Dictionary>>_.chain({'key1': 'test1', 'key2': 'test2'}); -result = <_.LoDashObjectWrapper<_.Dictionary>>_({'key1': 'test1', 'key2': 'test2'}).chain(); +result = <_.LoDashObjectWrapper<_.Dictionary>>_.chain(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }); +result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).chain(); //Wrapped array shortcut methods result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).concat(5, 6); @@ -116,31 +119,31 @@ result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).splice(1); result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).splice(1, 2, 5, 6); result = <_.LoDashWrapper>_([1, 2, 3, 4]).unshift(5, 6); -result = _.tap([1, 2, 3, 4], function(array) { console.log(array); }); -result = <_.LoDashWrapper>_('test').tap(function(value) { console.log(value); }); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).tap(function(array) { console.log(array); }); -result = <_.LoDashObjectWrapper<_.Dictionary>>_({'key1': 'test1', 'key2': 'test2'}).tap(function(array) { console.log(array); }); +result = _.tap([1, 2, 3, 4], function (array) { console.log(array); }); +result = <_.LoDashWrapper>_('test').tap(function (value) { console.log(value); }); +result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).tap(function (array) { console.log(array); }); +result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).tap(function (array) { console.log(array); }); result = _('test').toString(); result = _([1, 2, 3]).toString(); -result = _({'key1': 'test1', 'key2': 'test2'}).toString(); +result = _({ 'key1': 'test1', 'key2': 'test2' }).toString(); result = _('test').valueOf(); result = _([1, 2, 3]).valueOf(); -result = <_.Dictionary>_({'key1': 'test1', 'key2': 'test2'}).valueOf(); +result = <_.Dictionary>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).valueOf(); result = _('test').value(); result = _([1, 2, 3]).value(); -result = <_.Dictionary>_({'key1': 'test1', 'key2': 'test2'}).value(); +result = <_.Dictionary>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).value(); // /************* // * Arrays * // *************/ result = _.compact([0, 1, false, 2, '', 3]); - result = <_.LoDashArrayWrapper>_([0, 1, false, 2, '', 3]).compact(); +result = <_.LoDashArrayWrapper>_([0, 1, false, 2, '', 3]).compact(); result = _.difference([1, 2, 3, 4, 5], [5, 2, 10]); - result = <_.LoDashArrayWrapper>_([1, 2, 3, 4, 5]).difference([5, 2, 10]); +result = <_.LoDashArrayWrapper>_([1, 2, 3, 4, 5]).difference([5, 2, 10]); result = _.rest([1, 2, 3]); result = _.rest([1, 2, 3], 2); @@ -160,48 +163,48 @@ result = _.tail([1, 2, 3], (num) => num < 3) result = _.tail(foodsOrganic, 'test') result = _.tail(foodsType, { 'type': 'value' }) -result = _.findIndex(['apple', 'banana', 'beet'], function(f) { - return /^b/.test(f); +result = _.findIndex(['apple', 'banana', 'beet'], function (f) { + return /^b/.test(f); }); result = _.findIndex(['apple', 'banana', 'beet'], 'apple'); -result = _.findIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple'}); +result = _.findIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple' }); -result = _.findLastIndex(['apple', 'banana', 'beet'], function(f: string) { - return /^b/.test(f); +result = _.findLastIndex(['apple', 'banana', 'beet'], function (f: string) { + return /^b/.test(f); }); result = _.findLastIndex(['apple', 'banana', 'beet'], 'apple'); -result = _.findLastIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple'}); +result = _.findLastIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple' }); result = _.first([1, 2, 3]); result = _.first([1, 2, 3], 2); -result = _.first([1, 2, 3], function(num) { - return num < 3; +result = _.first([1, 2, 3], function (num) { + return num < 3; }); result = _.first(foodsOrganic, 'organic'); result = _.first(foodsType, { 'type': 'fruit' }); - result = _.head([1, 2, 3]); - result = _.head([1, 2, 3], 2); - result = _.head([1, 2, 3], function(num) { - return num < 3; - }); - result = _.head(foodsOrganic, 'organic'); - result = _.head(foodsType, { 'type': 'fruit' }); +result = _.head([1, 2, 3]); +result = _.head([1, 2, 3], 2); +result = _.head([1, 2, 3], function (num) { + return num < 3; +}); +result = _.head(foodsOrganic, 'organic'); +result = _.head(foodsType, { 'type': 'fruit' }); - 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 = _.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 = _.flatten([1, [2], [3, [[4]]]]); result = _.flatten([1, [2], [3, [[4]]]], true); var result: any result = _.flatten(stoogesQuotes, 'quotes'); - result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(); - result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(true); - result = <_.LoDashArrayWrapper>_(stoogesQuotes).flatten('quotes'); +result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(); +result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(true); +result = <_.LoDashArrayWrapper>_(stoogesQuotes).flatten('quotes'); result = _.indexOf([1, 2, 3, 1, 2, 3], 2); result = _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); @@ -209,8 +212,8 @@ result = _.indexOf([1, 1, 2, 2, 3, 3], 2, true); result = _.initial([1, 2, 3]); result = _.initial([1, 2, 3], 2); -result = _.initial([1, 2, 3], function(num) { - return num > 1; +result = _.initial([1, 2, 3], function (num) { + return num > 1; }); result = _.initial(foodsOrganic, 'organic'); result = _.initial(foodsType, { 'type': 'vegetable' }); @@ -219,8 +222,8 @@ result = _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); result = _.last([1, 2, 3]); result = _.last([1, 2, 3], 2); -result = _.last([1, 2, 3], function(num) { - return num > 1; +result = _.last([1, 2, 3], function (num) { + return num > 1; }); result = _.last(foodsOrganic, 'organic'); result = _.last(foodsType, { 'type': 'vegetable' }); @@ -228,8 +231,8 @@ result = _.last(foodsType, { 'type': 'vegetable' }); result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); -result = <{[key: string]: any}>_.zipObject(['moe', 'larry'], [30, 40]); -result = <{[key: string]: any}>_.object(['moe', 'larry'], [30, 40]); +result = <{ [key: string]: any }>_.zipObject(['moe', 'larry'], [30, 40]); +result = <{ [key: string]: any }>_.object(['moe', 'larry'], [30, 40]); result = _.pull([1, 2, 3, 1, 2, 3], 2, 3); @@ -240,39 +243,39 @@ result = _.range(0, -10, -1); result = _.range(1, 4, 0); result = _.range(0); -result = _.remove([1, 2, 3, 4, 5, 6], function(num: number) { return num % 2 == 0; }); +result = _.remove([1, 2, 3, 4, 5, 6], function (num: number) { return num % 2 == 0; }); result = _.remove(foodsOrganic, 'organic'); -result = _.remove(foodsType, { 'type': 'vegetable'}); +result = _.remove(foodsType, { 'type': 'vegetable' }); result = _.sortedIndex([20, 30, 50], 40); result = _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); var sortedIndexDict = { - 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } + 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } }; -result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { - return sortedIndexDict.wordToNumber[word]; +result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word) { + return sortedIndexDict.wordToNumber[word]; }); -result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { - return this.wordToNumber[word]; +result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word) { + return this.wordToNumber[word]; }, sortedIndexDict); result = _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); 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) { - return letter.toLowerCase(); +result = _.uniq(['A', 'b', 'C', 'a', 'B', 'c'], function (letter) { + return letter.toLowerCase(); }); -result = _.uniq([1, 2.5, 3, 1.5, 2, 3.5], function(num) { return this.floor(num); }, Math); -result = <{x: number;}[]>_.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); +result = _.uniq([1, 2.5, 3, 1.5, 2, 3.5], function (num) { return this.floor(num); }, Math); +result = <{ x: number; }[]>_.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); - result = _.unique([1, 2, 1, 3, 1]); - result = _.unique([1, 1, 2, 2, 3], true); - result = _.unique(['A', 'b', 'C', 'a', 'B', 'c'], function(letter) { - return letter.toLowerCase(); - }); - 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 = _.unique([1, 2, 1, 3, 1]); +result = _.unique([1, 1, 2, 2, 3], true); +result = _.unique(['A', 'b', 'C', 'a', 'B', 'c'], function (letter) { + return letter.toLowerCase(); +}); +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 = _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); @@ -291,165 +294,165 @@ result = _.contains([1, 2, 3], 1, 2); result = _.contains({ 'name': 'moe', 'age': 40 }, 'moe'); result = _.contains('curly', 'ur'); - result = _.include([1, 2, 3], 1); - result = _.include([1, 2, 3], 1, 2); - result = _.include({ 'name': 'moe', 'age': 40 }, 'moe'); - result = _.include('curly', 'ur'); +result = _.include([1, 2, 3], 1); +result = _.include([1, 2, 3], 1, 2); +result = _.include({ 'name': 'moe', 'age': 40 }, 'moe'); +result = _.include('curly', 'ur'); -result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); -result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); +result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return Math.floor(num); }); +result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return this.floor(num); }, Math); result = <_.Dictionary>_.countBy(['one', 'two', 'three'], 'length'); - result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function(num) { return Math.floor(num); }); - result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function(num) { return this.floor(num); }, Math); - result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).countBy('length'); +result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function (num) { return Math.floor(num); }); +result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function (num) { return this.floor(num); }, Math); +result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).countBy('length'); result = _.every([true, 1, null, 'yes'], Boolean); result = _.every(stoogesAges, 'age'); result = _.every(stoogesAges, { 'age': 50 }); - result = _.all([true, 1, null, 'yes'], Boolean); - result = _.all(stoogesAges, 'age'); - result = _.all(stoogesAges, { 'age': 50 }); +result = _.all([true, 1, null, 'yes'], Boolean); +result = _.all(stoogesAges, 'age'); +result = _.all(stoogesAges, { 'age': 50 }); -result = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +result = _.filter([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); result = _.filter(foodsCombined, 'organic'); result = _.filter(foodsCombined, { 'type': 'fruit' }); - result = _([1, 2, 3, 4, 5, 6]).filter(function(num) { return num % 2 == 0; }).value(); - result = _(foodsCombined).filter('organic').value(); - result = _(foodsCombined).filter({ 'type': 'fruit' }).value(); +result = _([1, 2, 3, 4, 5, 6]).filter(function (num) { return num % 2 == 0; }).value(); +result = _(foodsCombined).filter('organic').value(); +result = _(foodsCombined).filter({ 'type': 'fruit' }).value(); - result = _.select([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); - result = _.select(foodsCombined, 'organic'); - result = _.select(foodsCombined, { 'type': 'fruit' }); +result = _.select([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); +result = _.select(foodsCombined, 'organic'); +result = _.select(foodsCombined, { 'type': 'fruit' }); - result = _([1, 2, 3, 4, 5, 6]).select(function(num) { return num % 2 == 0; }).value(); - result = _(foodsCombined).select('organic').value(); - result = _(foodsCombined).select({ 'type': 'fruit' }).value(); +result = _([1, 2, 3, 4, 5, 6]).select(function (num) { return num % 2 == 0; }).value(); +result = _(foodsCombined).select('organic').value(); +result = _(foodsCombined).select({ 'type': 'fruit' }).value(); -result = _.find([1, 2, 3, 4], function(num) { - return num % 2 == 0; +result = _.find([1, 2, 3, 4], function (num) { + return num % 2 == 0; }); result = _.find(foodsCombined, { 'type': 'vegetable' }); result = _.find(foodsCombined, 'organic'); - result = _.detect([1, 2, 3, 4], function(num) { - return num % 2 == 0; - }); - result = _.detect(foodsCombined, { 'type': 'vegetable' }); - result = _.detect(foodsCombined, 'organic'); +result = _.detect([1, 2, 3, 4], function (num) { + return num % 2 == 0; +}); +result = _.detect(foodsCombined, { 'type': 'vegetable' }); +result = _.detect(foodsCombined, 'organic'); - result = _.findWhere([1, 2, 3, 4], function(num) { - return num % 2 == 0; - }); - result = _.findWhere(foodsCombined, { 'type': 'vegetable' }); - result = _.findWhere(foodsCombined, 'organic'); +result = _.findWhere([1, 2, 3, 4], function (num) { + return num % 2 == 0; +}); +result = _.findWhere(foodsCombined, { 'type': 'vegetable' }); +result = _.findWhere(foodsCombined, 'organic'); -result = _.findLast([1, 2, 3, 4], function(num) { - return num % 2 == 0; +result = _.findLast([1, 2, 3, 4], function (num) { + return num % 2 == 0; }); result = _.findLast(foodsCombined, { 'type': 'vegetable' }); 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([1, 2, 3], function (num) { console.log(num); }); +result = <_.Dictionary>_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); - 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([1, 2, 3], function (num) { console.log(num); }); +result = <_.Dictionary>_.each({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); - result = <_.LoDashArrayWrapper>_([1, 2, 3]).forEach(function(num) { console.log(num); }); - result = <_.LoDashObjectWrapper<_.Dictionary>>_({ 'one': 1, 'two': 2, 'three': 3 }).forEach(function(num) { console.log(num); }); +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); }); - result = <_.LoDashArrayWrapper>_([1, 2, 3]).each(function(num) { console.log(num); }); - result = <_.LoDashObjectWrapper<_.Dictionary>>_({ 'one': 1, 'two': 2, 'three': 3 }).each(function(num) { console.log(num); }); +result = <_.LoDashArrayWrapper>_([1, 2, 3]).each(function (num) { console.log(num); }); +result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).each(function (num) { console.log(num); }); -result = _.forEachRight([1, 2, 3], function(num) { console.log(num); }); -result = <_.Dictionary>_.forEachRight({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); }); +result = _.forEachRight([1, 2, 3], function (num) { console.log(num); }); +result = <_.Dictionary>_.forEachRight({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); - result = _.eachRight([1, 2, 3], function(num) { console.log(num); }); - result = <_.Dictionary>_.eachRight({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); }); +result = _.eachRight([1, 2, 3], function (num) { console.log(num); }); +result = <_.Dictionary>_.eachRight({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); - result = <_.LoDashArrayWrapper>_([1, 2, 3]).forEachRight(function(num) { console.log(num); }); - result = <_.LoDashObjectWrapper<_.Dictionary>>_({ 'one': 1, 'two': 2, 'three': 3 }).forEachRight(function(num) { console.log(num); }); +result = <_.LoDashArrayWrapper>_([1, 2, 3]).forEachRight(function (num) { console.log(num); }); +result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).forEachRight(function (num) { console.log(num); }); - result = <_.LoDashArrayWrapper>_([1, 2, 3]).eachRight(function(num) { console.log(num); }); - result = <_.LoDashObjectWrapper<_.Dictionary>>_({ 'one': 1, 'two': 2, 'three': 3 }).eachRight(function(num) { console.log(num); }); +result = <_.LoDashArrayWrapper>_([1, 2, 3]).eachRight(function (num) { console.log(num); }); +result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).eachRight(function (num) { console.log(num); }); -result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); -result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); +result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function (num) { return Math.floor(num); }); +result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function (num) { return this.floor(num); }, Math); result = <_.Dictionary>_.groupBy(['one', 'two', 'three'], 'length'); - result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function(num) { return Math.floor(num); }); - result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function(num) { return this.floor(num); }, Math); - result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).groupBy('length'); +result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function (num) { return Math.floor(num); }); +result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function (num) { return this.floor(num); }, Math); +result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).groupBy('length'); result = <_.Dictionary>_.indexBy(keys, 'dir'); -result = <_.Dictionary>_.indexBy(keys, function(key) { return String.fromCharCode(key.code); }); -result = <_.Dictionary>_.indexBy(keys, function(key) { this.fromCharCode(key.code); }, String); +result = <_.Dictionary>_.indexBy(keys, function (key) { return String.fromCharCode(key.code); }); +result = <_.Dictionary>_.indexBy(keys, function (key) { this.fromCharCode(key.code); }, String); result = _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); result = _.invoke([123, 456], String.prototype.split, ''); -result = _.map([1, 2, 3], function(num) { return num * 3; }); -result = _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); +result = _.map([1, 2, 3], function (num) { return num * 3; }); +result = _.map({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { return num * 3; }); result = _.map(stoogesAges, 'name'); - result = _([1, 2, 3]).map(function(num) { return num * 3; }).value(); - result = _({ 'one': 1, 'two': 2, 'three': 3 }).map(function(num) { return num * 3; }).value(); - result = _(stoogesAges).map('name').value(); +result = _([1, 2, 3]).map(function (num) { return num * 3; }).value(); +result = _({ 'one': 1, 'two': 2, 'three': 3 }).map(function (num) { return num * 3; }).value(); +result = _(stoogesAges).map('name').value(); -result = _.collect([1, 2, 3], function(num) { return num * 3; }); -result = _.collect({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); +result = _.collect([1, 2, 3], function (num) { return num * 3; }); +result = _.collect({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { return num * 3; }); result = _.collect(stoogesAges, 'name'); - result = _([1, 2, 3]).collect(function(num) { return num * 3; }).value(); - result = _({ 'one': 1, 'two': 2, 'three': 3 }).collect(function(num) { return num * 3; }).value(); - result = _(stoogesAges).collect('name').value(); +result = _([1, 2, 3]).collect(function (num) { return num * 3; }).value(); +result = _({ 'one': 1, 'two': 2, 'three': 3 }).collect(function (num) { return num * 3; }).value(); +result = _(stoogesAges).collect('name').value(); result = _.max([4, 2, 8, 6]); -result = _.max(stoogesAges, function(stooge) { return stooge.age; }); +result = _.max(stoogesAges, function (stooge) { return stooge.age; }); result = _.max(stoogesAges, 'age'); result = _.min([4, 2, 8, 6]); -result = _.min(stoogesAges, function(stooge) { return stooge.age; }); +result = _.min(stoogesAges, function (stooge) { return stooge.age; }); result = _.min(stoogesAges, 'age'); result = _.pluck(stoogesAges, 'name'); -result = _.reduce([1, 2, 3], function(sum: number, num: number) { - return sum + num; +result = _.reduce([1, 2, 3], function (sum: number, num: number) { + return sum + num; }); interface ABC { - a: number; - b: number; - c: number; + a: number; + b: number; + c: number; } -result = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(r: ABC, num, key) { - r[key] = num * 3; - return r; +result = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num, key) { + r[key] = num * 3; + return r; }, {}); -result = _.foldl([1, 2, 3], function(sum, num) { - return sum + num; +result = _.foldl([1, 2, 3], function (sum, num) { + return sum + num; }); -result = _.foldl({ 'a': 1, 'b': 2, 'c': 3 }, function(r: ABC, num, key) { - r[key] = num * 3; - return r; +result = _.foldl({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num, key) { + r[key] = num * 3; + return r; }, {}); -result = _.inject([1, 2, 3], function(sum, num) { - return sum + num; +result = _.inject([1, 2, 3], function (sum, num) { + return sum + num; }); -result = _.inject({ 'a': 1, 'b': 2, 'c': 3 }, function(r: ABC, num, key) { - r[key] = num * 3; - return r; +result = _.inject({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num, key) { + 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); }, []); +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); }, []); -result = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); +result = _.reject([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); result = _.reject(foodsCombined, 'organic'); result = _.reject(foodsCombined, { 'type': 'fruit' }); @@ -465,20 +468,20 @@ result = _.size('curly'); result = _.some([null, 0, 'yes', false], Boolean); result = _.some(foodsCombined, 'organic'); result = _.some(foodsCombined, { 'type': 'meat' }); - + result = _.any([null, 0, 'yes', false], Boolean); result = _.any(foodsCombined, 'organic'); result = _.any(foodsCombined, { 'type': 'meat' }); - -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([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'); -(function(a: number, b: number, c: number, d: number){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4); +(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!'] }); - + /************* * Functions * *************/ @@ -486,20 +489,20 @@ var saves = ['profile', 'settings']; var asyncSave = (obj: any) => obj.done(); var done: Function; -done = _.after(saves.length, function() { - console.log('Done saving!'); +done = _.after(saves.length, function () { + console.log('Done saving!'); }); -_.forEach(saves, function(type) { - asyncSave({ 'type': type, 'complete': done }); +_.forEach(saves, function (type) { + asyncSave({ 'type': type, 'complete': done }); }); -done = _(saves.length).after(function() { - console.log('Done saving!'); +done = _(saves.length).after(function () { + console.log('Done saving!'); }).value(); -_.forEach(saves, function(type) { - asyncSave({ 'type': type, 'complete': done }); +_.forEach(saves, function (type) { + asyncSave({ 'type': type, 'complete': done }); }); var funcBind = function (greeting: string) { return greeting + ' ' + this.name }; @@ -510,8 +513,8 @@ var funcBind3: () => any = _(funcBind).bind({ 'name': 'moe' }, 'hi').value(); funcBind3(); var view = { - 'label': 'docs', - 'onClick': function() { console.log('clicked ' + this.label); } + 'label': 'docs', + 'onClick': function () { console.log('clicked ' + this.label); } }; view = _.bindAll(view); @@ -521,17 +524,17 @@ view = _(view).bindAll().value(); jQuery('#docs').on('click', view.onClick); var objectBindKey = { - 'name': 'moe', - 'greet': function(greeting: string) { - return greeting + ' ' + this.name; - } + 'name': 'moe', + 'greet': function (greeting: string) { + return greeting + ' ' + this.name; + } }; var funcBindKey: Function = _.bindKey(objectBindKey, 'greet', 'hi'); funcBindKey(); -objectBindKey.greet = function(greeting) { - return greeting + ', ' + this.name + '!'; +objectBindKey.greet = function (greeting) { + return greeting + ', ' + this.name + '!'; }; funcBindKey(); @@ -540,78 +543,78 @@ funcBindKey = _(objectBindKey).bindKey('greet', 'hi').value(); funcBindKey(); var realNameMap = { - 'curly': 'jerome' + 'curly': 'jerome' }; -var format = function(name: string) { - name = realNameMap[name.toLowerCase()] || name; - return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase(); +var format = function (name: string) { + name = realNameMap[name.toLowerCase()] || name; + return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase(); }; -var greet = function(formatted: string) { - return 'Hiya ' + formatted + '!'; +var greet = function (formatted: string) { + return 'Hiya ' + formatted + '!'; }; result = _.compose(greet, format); result = <_.LoDashObjectWrapper>_(greet).compose(format); -var createCallbackObj = { name: 'Joe' }; +var createCallbackObj: { [index: string]: string; } = { name: 'Joe' }; result = <() => any>_.createCallback('name'); result = <() => boolean>_.createCallback(createCallbackObj); result = <_.LoDashObjectWrapper<() => any>>_('name').createCallback(); result = <_.LoDashObjectWrapper<() => boolean>>_(createCallbackObj).createCallback(); -result = _.curry(function(a, b, c) { - console.log(a + b + c); +result = _.curry(function (a, b, c) { + console.log(a + b + c); }); -result = <_.LoDashObjectWrapper>_(function(a, b, c) { - console.log(a + b + c); +result = <_.LoDashObjectWrapper>_(function (a, b, c) { + console.log(a + b + c); }).curry(); declare var source: any; -result = _.debounce(function() {}, 150); +result = _.debounce(function () { }, 150); -jQuery('#postbox').on('click', _.debounce(function() {}, 300, { - 'leading': true, - 'trailing': false +jQuery('#postbox').on('click', _.debounce(function () { }, 300, { + 'leading': true, + 'trailing': false })); -source.addEventListener('message', _.debounce(function() {}, 250, { - 'maxWait': 1000 +source.addEventListener('message', _.debounce(function () { }, 250, { + 'maxWait': 1000 }), false); -result = <_.LoDashObjectWrapper>_(function() {}).debounce(150); +result = <_.LoDashObjectWrapper>_(function () { }).debounce(150); -jQuery('#postbox').on('click', <_.LoDashObjectWrapper>_(function() {}).debounce(300, { - 'leading': true, - 'trailing': false +jQuery('#postbox').on('click', <_.LoDashObjectWrapper>_(function () { }).debounce(300, { + 'leading': true, + 'trailing': false })); -source.addEventListener('message', <_.LoDashObjectWrapper>_(function() {}).debounce(250, { - 'maxWait': 1000 +source.addEventListener('message', <_.LoDashObjectWrapper>_(function () { }).debounce(250, { + 'maxWait': 1000 }), false); var returnedDebounce = _.throttle(function (a) { return a * 5; }, 5); returnedThrottled(4); -result = _.defer(function() { console.log('deferred'); }); -result = <_.LoDashWrapper>_(function() { console.log('deferred'); }).defer(); +result = _.defer(function () { console.log('deferred'); }); +result = <_.LoDashWrapper>_(function () { console.log('deferred'); }).defer(); var log = _.bind(console.log, console); result = _.delay(log, 1000, 'logged later'); result = <_.LoDashWrapper>_(log).delay(1000, 'logged later'); -var fibonacci = _.memoize(function(n) { - return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); +var fibonacci = _.memoize(function (n) { + return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); }); var data = { - 'moe': { 'name': 'moe', 'age': 40 }, - 'curly': { 'name': 'curly', 'age': 60 } + 'moe': { 'name': 'moe', 'age': 40 }, + 'curly': { 'name': 'curly', 'age': 60 } }; -var stooge = _.memoize(function(name: string) { return data[name]; }, _.identity); +var stooge = _.memoize(function (name: string) { return data[name]; }, _.identity); stooge('curly'); stooge['cache']['curly'].name = 'jerome'; @@ -620,21 +623,21 @@ stooge('curly'); var returnedMemoize = _.throttle(function (a) { return a * 5; }, 5); returnedMemoize(4); -var initialize = _.once(function(){ }); +var initialize = _.once(function () { }); initialize(); initialize();'' var returnedOnce = _.throttle(function (a) { return a * 5; }, 5); returnedOnce(4); -var greetPartial = function(greeting: string, name: string) { return greeting + ' ' + name; }; +var greetPartial = function (greeting: string, name: string) { return greeting + ' ' + name; }; var hi = _.partial(greetPartial, 'hi'); hi('moe'); var defaultsDeep = _.partialRight(_.merge, _.defaults); var optionsPartialRight = { - 'variable': 'data', - 'imports': { 'jq': $ } + 'variable': 'data', + 'imports': { 'jq': $ } }; defaultsDeep(optionsPartialRight, _.templateSettings); @@ -642,16 +645,16 @@ defaultsDeep(optionsPartialRight, _.templateSettings); var throttled = _.throttle(function () { }, 100); jQuery(window).on('scroll', throttled); -jQuery('.interactive').on('click', _.throttle(function() { }, 300000, { - 'trailing': false +jQuery('.interactive').on('click', _.throttle(function () { }, 300000, { + 'trailing': false })); -var returnedThrottled = _.throttle(function (a) { return a*5; }, 5); +var returnedThrottled = _.throttle(function (a) { return a * 5; }, 5); returnedThrottled(4); -var helloWrap = function(name: string) { return 'hello ' + name; }; -var helloWrap2 = _.wrap(helloWrap, function(func) { - return 'before, ' + func('moe') + ', after'; +var helloWrap = function (name: string) { return 'hello ' + name; }; +var helloWrap2 = _.wrap(helloWrap, function (func) { + return 'before, ' + func('moe') + ', after'; }); helloWrap2(); @@ -659,93 +662,93 @@ helloWrap2(); * Objects * ***********/ interface NameAge { - name: string; - age: number; + name: string; + age: number; } result = _.assign({ 'name': 'moe' }, { 'age': 40 }); -result = _.assign({ 'name': 'moe' }, { 'age': 40 }, function(a, b) { - return typeof a == 'undefined' ? b : a; +result = _.assign({ 'name': 'moe' }, { 'age': 40 }, function (a, b) { + return typeof a == 'undefined' ? b : a; }); result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).assign({ 'age': 40 }); -result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).assign({ 'age': 40 }, function(a, b) { - return typeof a == 'undefined' ? b : a; +result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).assign({ 'age': 40 }, function (a, b) { + return typeof a == 'undefined' ? b : a; }); result = _.extend({ 'name': 'moe' }, { 'age': 40 }); -result = _.extend({ 'name': 'moe' }, { 'age': 40 }, function(a, b) { - return typeof a == 'undefined' ? b : a; +result = _.extend({ 'name': 'moe' }, { 'age': 40 }, function (a, b) { + return typeof a == 'undefined' ? b : a; }); result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).extend({ 'age': 40 }); -result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).extend({ 'age': 40 }, function(a, b) { - return typeof a == 'undefined' ? b : a; +result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).extend({ 'age': 40 }, function (a, b) { + return typeof a == 'undefined' ? b : a; }); result = _.clone(stoogesAges); result = _.clone(stoogesAges, true); -result = _.clone(stoogesAges, true, function(value) { - return _.isElement(value) ? value.cloneNode(false) : undefined; +result = _.clone(stoogesAges, true, function (value) { + return _.isElement(value) ? value.cloneNode(false) : undefined; }); result = _.cloneDeep(stoogesAges); -result = _.cloneDeep(stoogesAges, function(value) { - return _.isElement(value) ? value.cloneNode(false) : undefined; +result = _.cloneDeep(stoogesAges, function (value) { + return _.isElement(value) ? value.cloneNode(false) : undefined; }); interface Food { - name: string; - type: string; + name: string; + type: string; } var foodDefaults = { 'name': 'apple' }; result = _.defaults(foodDefaults, { 'name': 'banana', 'type': 'fruit' }); - result = <_.LoDashObjectWrapper>_(foodDefaults).defaults({ 'name': 'banana', 'type': 'fruit' }); +result = <_.LoDashObjectWrapper>_(foodDefaults).defaults({ 'name': 'banana', 'type': 'fruit' }); -result = _.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { - return num % 2 == 0; +result = _.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) { + return num % 2 == 0; }); -result = _.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { - return num % 2 == 1; +result = _.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) { + return num % 2 == 1; }); -result = _.forIn(new Dog('Dagny'), function(value, key) { - console.log(key); +result = _.forIn(new Dog('Dagny'), function (value, key) { + console.log(key); }); -result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forIn(function(value, key) { - console.log(key); +result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forIn(function (value, key) { + console.log(key); }); -result = _.forInRight(new Dog('Dagny'), function(value, key) { - console.log(key); +result = _.forInRight(new Dog('Dagny'), function (value, key) { + console.log(key); }); -result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forInRight(function(value, key) { - console.log(key); +result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forInRight(function (value, key) { + console.log(key); }); interface ZeroOne { - 0: string; - 1: string; - one: string; + 0: string; + 1: string; + one: string; } -result = _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { - console.log(key); +result = _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function (num, key) { + console.log(key); }); - result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwn(function(num, key) { - console.log(key); - }); - -result = _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { - console.log(key); +result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwn(function (num, key) { + console.log(key); }); - result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwnRight(function(num, key) { - console.log(key); - }); +result = _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function (num, key) { + console.log(key); +}); + +result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwnRight(function (num, key) { + console.log(key); +}); result = _.functions(_); result = _.methods(_); @@ -756,12 +759,12 @@ result = <_.LoDashArrayWrapper>_(_).methods(); result = _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); interface FirstSecond { - first: string; - second: string; + first: string; + second: string; } result = _.invert({ 'first': 'moe', 'second': 'larry' }); -(function(...args: any[]) { return _.isArguments(arguments); })(1, 2, 3); +(function (...args: any[]) { return _.isArguments(arguments); })(1, 2, 3); (function () { return _.isArray(arguments); })(); result = _.isArray([1, 2, 3]); @@ -784,12 +787,12 @@ result = _.isEqual(moe, copy); var words = ['hello', 'goodbye']; var otherWords = ['hi', 'goodbye']; -result = _.isEqual(words, otherWords, function(a, b) { - var reGreet = /^(?:hello|hi)$/i, - aGreet = _.isString(a) && reGreet.test(a), - bGreet = _.isString(b) && reGreet.test(b); +result = _.isEqual(words, otherWords, function (a, b) { + var reGreet = /^(?:hello|hi)$/i, + aGreet = _.isString(a) && reGreet.test(a), + bGreet = _.isString(b) && reGreet.test(b); - return (aGreet || bGreet) ? (aGreet == bGreet) : undefined; + return (aGreet || bGreet) ? (aGreet == bGreet) : undefined; }); result = _.isFinite(-101); @@ -817,7 +820,7 @@ class Stooge { constructor( public name: string, public age: number - ) {} + ) { } } result = _.isPlainObject(new Stooge('moe', 40)); @@ -833,67 +836,67 @@ result = _.isUndefined(void 0); result = _.keys({ 'one': 1, 'two': 2, 'three': 3 }); var mergeNames = { - 'stooges': [ - { 'name': 'moe' }, - { 'name': 'larry' } - ] + 'stooges': [ + { 'name': 'moe' }, + { 'name': 'larry' } + ] }; var mergeAges = { - 'stooges': [ - { 'age': 40 }, - { 'age': 50 } - ] + 'stooges': [ + { 'age': 40 }, + { 'age': 50 } + ] }; result = _.merge(mergeNames, mergeAges); var mergeFood = { - 'fruits': ['apple'], - 'vegetables': ['beet'] + 'fruits': ['apple'], + 'vegetables': ['beet'] }; var mergeOtherFood = { - 'fruits': ['banana'], - 'vegetables': ['carrot'] + 'fruits': ['banana'], + 'vegetables': ['carrot'] }; interface FruitVeg { - fruits: string[]; - vegetables: string[] + fruits: string[]; + vegetables: string[] }; -result = _.merge(mergeFood, mergeOtherFood, function(a, b) { - return _.isArray(a) ? a.concat(b) : undefined; +result = _.merge(mergeFood, mergeOtherFood, function (a, b) { + return _.isArray(a) ? a.concat(b) : undefined; }); interface HasName { - name: string; + name: string; } result = _.omit({ 'name': 'moe', 'age': 40 }, 'age'); result = _.omit({ 'name': 'moe', 'age': 40 }, ['age']); -result = _.omit({ 'name': 'moe', 'age': 40 }, function(value) { - return typeof value == 'number'; +result = _.omit({ 'name': 'moe', 'age': 40 }, function (value) { + return typeof value == 'number'; }); result = _.pairs({ 'moe': 30, 'larry': 40 }); result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, 'name'); result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, ['name']); -result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key) { - return key.charAt(0) != '_'; +result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, function (value, key) { + return key.charAt(0) != '_'; }); -result = _.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function(r, num) { - num *= num; - if (num % 2) { - return r.push(num) < 3; - } +result = _.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (r, num) { + num *= num; + if (num % 2) { + return r.push(num) < 3; + } }); // → [1, 9, 25] -result = <{a:number;b:number;c:number;}>_.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(r, num, key) { - r[key] = num * 3; +result = <{ a: number; b: number; c: number; }>_.transform({ 'a': 1, 'b': 2, 'c': 3 }, function (r, num, key) { + r[key] = num * 3; }); result = _.values({ 'one': 1, 'two': 2, 'three': 3 }); @@ -907,9 +910,9 @@ result = _.escape('Moe, Larry & Curly'); result = <{ name: string }>_.identity({ 'name': 'moe' }); _.mixin({ - 'capitalize': function(string) { - return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); - } + 'capitalize': function (string) { + return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); + } }); var lodash = _.noConflict(); @@ -923,10 +926,10 @@ result = _.random(1.2, 5.2); result = _.random(0, 5, true); var object = { - 'cheese': 'crumpets', - 'stuff': function() { - return 'nonsense'; - } + 'cheese': 'crumpets', + 'stuff': function () { + return 'nonsense'; + } }; result = _.result(object, 'cheese'); @@ -960,10 +963,10 @@ class Mage { } } -var mage = new Mage(); +var mage = new Mage(); result = _.times(3, <() => number>_.partial(_.random, 1, 6)); -result = _.times(3, function(n: number) { mage.castSpell(n); }); -result = _.times(3, function(n: number) { this.cast(n); }, mage); +result = _.times(3, function (n: number) { mage.castSpell(n); }); +result = _.times(3, function (n: number) { this.cast(n); }, mage); result = _.unescape('Moe, Larry & Curly'); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index b48f7e6034..3c4b572c15 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -181,15 +181,15 @@ declare module _ { **/ valueOf(): T; - /** - * @see valueOf - **/ - value(): T; - } + /** + * @see valueOf + **/ + value(): T; + } - interface LoDashWrapper extends LoDashWrapperBase> {} + interface LoDashWrapper extends LoDashWrapperBase> { } - interface LoDashObjectWrapper extends LoDashWrapperBase> {} + interface LoDashObjectWrapper extends LoDashWrapperBase> { } interface LoDashArrayWrapper extends LoDashWrapperBase> { concat(...items: T[]): LoDashArrayWrapper; @@ -263,6 +263,11 @@ declare module _ { * @param array Array to compact. * @return (Array) Returns a new array of filtered values. **/ + compact(array: Array): T[]; + + /** + * @see _.compact + **/ compact(array: List): T[]; } @@ -270,8 +275,8 @@ declare module _ { /** * @see _.compact **/ - compact(): LoDashArrayWrapper; - } + compact(): LoDashArrayWrapper; + } //_.difference interface LoDashStatic { @@ -282,6 +287,12 @@ declare module _ { * @param others The arrays of values to exclude. * @return Returns a new array of filtered values. **/ + difference( + array: Array, + ...others: Array[]): T[]; + /** + * @see _.difference + **/ difference( array: List, ...others: List[]): T[]; @@ -291,6 +302,11 @@ declare module _ { /** * @see _.difference **/ + difference( + ...others: Array[]): LoDashArrayWrapper; + /** + * @see _.difference + **/ difference( ...others: List[]): LoDashArrayWrapper; } @@ -307,7 +323,7 @@ declare module _ { * @return Returns the index of the found element, else -1. **/ findIndex( - array: List, + array: Array, callback: ListIterator, thisArg?: any): number; @@ -316,8 +332,30 @@ declare module _ { **/ findIndex( array: List, + callback: ListIterator, + thisArg?: any): number; + + /** + * @see _.findIndex + **/ + findIndex( + array: Array, pluckValue: string): number; - + + /** + * @see _.findIndex + **/ + findIndex( + array: List, + pluckValue: string): number; + + /** + * @see _.findIndex + **/ + findIndex( + array: Array, + whereDictionary: W): number; + /** * @see _.findIndex **/ @@ -336,18 +374,40 @@ declare module _ { * @param thisArg The this binding of callback. * @return Returns the index of the found element, else -1. **/ + findLastIndex( + array: Array, + callback: ListIterator, + thisArg?: any): number; + + /** + * @see _.findLastIndex + **/ findLastIndex( array: List, callback: ListIterator, thisArg?: any): number; - + + /** + * @see _.findLastIndex + **/ + findLastIndex( + array: Array, + pluckValue: string): number; + /** * @see _.findLastIndex **/ findLastIndex( array: List, pluckValue: string): number; - + + /** + * @see _.findLastIndex + **/ + findLastIndex( + array: Array, + whereDictionary: Dictionary): number; + /** * @see _.findLastIndex **/ @@ -372,8 +432,21 @@ declare module _ { * @param array Retrieves the first element of this array. * @return Returns the first element of `array`. **/ + first(array: Array): T; + + /** + * @see _.first + **/ first(array: List): T; + /** + * @see _.first + * @param n The number of elements to return. + **/ + first( + array: Array, + n: number): T[]; + /** * @see _.first * @param n The number of elements to return. @@ -382,6 +455,16 @@ declare module _ { array: List, n: number): T[]; + /** + * @see _.first + * @param callback The function called per element. + * @param [thisArg] The this binding of callback. + **/ + first( + array: Array, + callback: ListIterator, + thisArg?: any): T[]; + /** * @see _.first * @param callback The function called per element. @@ -392,6 +475,14 @@ declare module _ { callback: ListIterator, thisArg?: any): T[]; + /** + * @see _.first + * @param pluckValue "_.pluck" style callback value + **/ + first( + array: Array, + pluckValue: string): T[]; + /** * @see _.first * @param pluckValue "_.pluck" style callback value @@ -400,6 +491,14 @@ declare module _ { array: List, pluckValue: string): T[]; + /** + * @see _.first + * @param whereValue "_.where" style callback value + **/ + first( + array: Array, + whereValue: W): T[]; + /** * @see _.first * @param whereValue "_.where" style callback value @@ -408,73 +507,141 @@ declare module _ { array: List, whereValue: W): T[]; - /** - * @see _.first - **/ - head(array: List): T; + /** + * @see _.first + **/ + head(array: Array): T; - /** - * @see _.first - **/ - head( - array: List, - n: number): T[]; + /** + * @see _.first + **/ + head(array: List): T; - /** - * @see _.first - **/ - head( - array: List, - callback: ListIterator, - thisArg?: any): T[]; + /** + * @see _.first + **/ + head( + array: Array, + n: number): T[]; - /** - * @see _.first - **/ - head( - array: List, - pluckValue: string): T[]; + /** + * @see _.first + **/ + head( + array: List, + n: number): T[]; - /** - * @see _.first - **/ - head( - array: List, - whereValue: W): T[]; + /** + * @see _.first + **/ + head( + array: Array, + callback: ListIterator, + thisArg?: any): T[]; - /** - * @see _.first - **/ - take(array: List): T; + /** + * @see _.first + **/ + head( + array: List, + callback: ListIterator, + thisArg?: any): T[]; - /** - * @see _.first - **/ - take( - array: List, - n: number): T[]; + /** + * @see _.first + **/ + head( + array: Array, + pluckValue: string): T[]; - /** - * @see _.first - **/ - take( - array: List, - callback: ListIterator, - thisArg?: any): T[]; + /** + * @see _.first + **/ + head( + array: List, + pluckValue: string): T[]; - /** - * @see _.first - **/ - take( - array: List, - pluckValue: string): T[]; + /** + * @see _.first + **/ + head( + array: Array, + whereValue: W): T[]; - /** - * @see _.first - **/ - take( - array: List, - whereValue: W): T[]; + /** + * @see _.first + **/ + head( + array: List, + whereValue: W): T[]; + + /** + * @see _.first + **/ + take(array: Array): T; + + /** + * @see _.first + **/ + take(array: List): T; + + /** + * @see _.first + **/ + take( + array: Array, + n: number): T[]; + + /** + * @see _.first + **/ + take( + array: List, + n: number): T[]; + + /** + * @see _.first + **/ + take( + array: Array, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.first + **/ + take( + array: List, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @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[]; } //_.flatten @@ -494,65 +661,153 @@ declare module _ { * @param shallow If true then only flatten one level, optional, default = false. * @return `array` flattened. **/ + flatten(array: Array, isShallow?: boolean): T[]; + + /** + * @see _.flatten + **/ flatten(array: List, isShallow?: boolean): T[]; + /** + * @see _.flatten + **/ + flatten( + array: Array, + isShallow: boolean, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.flatten + **/ flatten( array: List, isShallow: boolean, callback: ListIterator, - thisArg?: any): T[]; + thisArg?: any): T[]; + /** + * @see _.flatten + **/ + flatten( + array: Array, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.flatten + **/ flatten( array: List, callback: ListIterator, - thisArg?: any): T[]; + thisArg?: any): T[]; + /** + * @see _.flatten + **/ + flatten( + array: Array, + isShallow: boolean, + whereValue: W): T[]; + + /** + * @see _.flatten + **/ flatten( array: List, isShallow: boolean, - whereValue: W): T[]; + whereValue: W): T[]; + /** + * @see _.flatten + **/ + flatten( + array: Array, + whereValue: W): T[]; + + /** + * @see _.flatten + **/ flatten( array: List, - whereValue: W): T[]; + whereValue: W): T[]; + /** + * @see _.flatten + **/ + flatten( + array: Array, + isShallow: boolean, + pluckValue: string): T[]; + + /** + * @see _.flatten + **/ flatten( array: List, isShallow: boolean, - pluckValue: string): T[]; + pluckValue: string): T[]; + /** + * @see _.flatten + **/ + flatten( + array: Array, + pluckValue: string): T[]; + + /** + * @see _.flatten + **/ flatten( array: List, - pluckValue: string): T[]; + pluckValue: string): T[]; } interface LoDashArrayWrapper { /** * @see _.flatten **/ - flatten(isShallow?: boolean): LoDashArrayWrapper; + flatten(isShallow?: boolean): LoDashArrayWrapper; - flatten( + /** + * @see _.flatten + **/ + flatten( isShallow: boolean, callback: ListIterator, thisArg?: any): LoDashArrayWrapper; - flatten( + /** + * @see _.flatten + **/ + flatten( callback: ListIterator, thisArg?: any): LoDashArrayWrapper; - flatten( + /** + * @see _.flatten + **/ + flatten( isShallow: boolean, pluckValue: string): LoDashArrayWrapper; - flatten( + /** + * @see _.flatten + **/ + flatten( pluckValue: string): LoDashArrayWrapper; - flatten( + /** + * @see _.flatten + **/ + flatten( isShallow: boolean, whereValue: W): LoDashArrayWrapper; - flatten( + /** + * @see _.flatten + **/ + flatten( whereValue: W): LoDashArrayWrapper; } @@ -567,10 +822,26 @@ declare module _ { * @param fromIndex The index to search from. * @return The index of `value` within `array`. **/ + indexOf( + array: Array, + value: T): number; + + /** + * @see _.indexOf + **/ indexOf( array: List, value: T): number; + /** + * @see _.indexOf + * @param fromIndex The index to search from + **/ + indexOf( + array: Array, + value: T, + fromIndex: number): number; + /** * @see _.indexOf * @param fromIndex The index to search from @@ -580,6 +851,15 @@ declare module _ { value: T, fromIndex: number): number; + /** + * @see _.indexOf + * @param isSorted True to perform a binary search on a sorted array. + **/ + indexOf( + array: Array, + value: T, + isSorted: boolean): number; + /** * @see _.indexOf * @param isSorted True to perform a binary search on a sorted array. @@ -607,9 +887,23 @@ declare module _ { * @param n Leaves this many elements behind, optional. * @return Returns everything but the last `n` elements of `array`. **/ + initial( + array: Array): T[]; + + /** + * @see _.initial + **/ initial( array: List): T[]; + /** + * @see _.initial + * @param n The number of elements to exclude. + **/ + initial( + array: Array, + n: number): T[]; + /** * @see _.initial * @param n The number of elements to exclude. @@ -618,6 +912,14 @@ declare module _ { array: List, n: number): T[]; + /** + * @see _.initial + * @param callback The function called per element + **/ + initial( + array: Array, + callback: ListIterator): T[]; + /** * @see _.initial * @param callback The function called per element @@ -626,6 +928,14 @@ declare module _ { array: List, callback: ListIterator): T[]; + /** + * @see _.initial + * @param pluckValue _.pluck style callback + **/ + initial( + array: Array, + pluckValue: string): T[]; + /** * @see _.initial * @param pluckValue _.pluck style callback @@ -634,6 +944,14 @@ declare module _ { array: List, pluckValue: string): T[]; + /** + * @see _.initial + * @param whereValue _.where style callback + **/ + initial( + array: Array, + whereValue: W): T[]; + /** * @see _.initial * @param whereValue _.where style callback @@ -651,6 +969,11 @@ declare module _ { * @param arrays The arrays to inspect. * @return Returns an array of composite values. **/ + intersection(...arrays: Array[]): T[]; + + /** + * @see _.intersection + **/ intersection(...arrays: List[]): T[]; } @@ -669,8 +992,21 @@ declare module _ { * @param array The array to query. * @return Returns the last element(s) of array. **/ + last(array: Array): T; + + /** + * @see _.last + **/ last(array: List): T; + /** + * @see _.last + * @param n The number of elements to return + **/ + last( + array: Array, + n: number): T[]; + /** * @see _.last * @param n The number of elements to return @@ -679,6 +1015,15 @@ declare module _ { array: List, n: number): T[]; + /** + * @see _.last + * @param callback The function called per element + **/ + last( + array: Array, + callback: ListIterator, + thisArg?: any): T[]; + /** * @see _.last * @param callback The function called per element @@ -688,6 +1033,14 @@ declare module _ { callback: ListIterator, thisArg?: any): T[]; + /** + * @see _.last + * @param pluckValue _.pluck style callback + **/ + last( + array: Array, + pluckValue: string): T[]; + /** * @see _.last * @param pluckValue _.pluck style callback @@ -696,6 +1049,14 @@ declare module _ { array: List, pluckValue: string): T[]; + /** + * @see _.last + * @param whereValue _.where style callback + **/ + last( + array: Array, + whereValue: W): T[]; + /** * @see _.last * @param whereValue _.where style callback @@ -716,12 +1077,20 @@ declare module _ { * @param fromIndex The index to search from. * @return The index of the matched value or -1. **/ + lastIndexOf( + array: Array, + value: T, + fromIndex?: number): number; + + /** + * @see _.lastIndexOf + **/ lastIndexOf( array: List, value: T, fromIndex?: number): number; } - + //_.pull interface LoDashStatic { /** @@ -731,6 +1100,13 @@ declare module _ { * @param values The values to remove. * @return array. **/ + pull( + array: Array, + ...values: any[]): any[]; + + /** + * @see _.pull + **/ pull( array: List, ...values: any[]): any[]; @@ -747,12 +1123,11 @@ declare module _ { * @param step The value to increment or decrement by. * @return Returns a new range array. **/ - range( start: number, stop: number, step?: number): number[]; - + /** * @see _.range * @param end The end of the range. @@ -779,11 +1154,27 @@ declare module _ { * @param thisArg The this binding of callback. * @return A new array of removed elements. **/ + remove( + array: Array, + callback?: ListIterator, + thisArg?: any): any[]; + + /** + * @see _.remove + **/ remove( array: List, callback?: ListIterator, thisArg?: any): any[]; + /** + * @see _.remove + * @param pluckValue _.pluck style callback + **/ + remove( + array: Array, + pluckValue?: string): any[]; + /** * @see _.remove * @param pluckValue _.pluck style callback @@ -792,6 +1183,14 @@ declare module _ { array: List, pluckValue?: string): any[]; + /** + * @see _.remove + * @param whereValue _.where style callback + **/ + remove( + array: Array, + wherealue?: Dictionary): any[]; + /** * @see _.remove * @param whereValue _.where style callback @@ -821,14 +1220,19 @@ declare module _ { * @param {*} [thisArg] The this binding of callback. * @return Returns a slice of array. **/ + rest(array: Array): T[]; + + /** + * @see _.rest + **/ rest(array: List): T[]; /** * @see _.rest **/ rest( - array: List, - callback: ListIterator, + array: Array, + callback: ListIterator, thisArg?: any): T[]; /** @@ -836,89 +1240,186 @@ declare module _ { **/ rest( array: List, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.rest + **/ + rest( + array: Array, n: number): T[]; - + + /** + * @see _.rest + **/ + rest( + array: List, + n: number): T[]; + + /** + * @see _.rest + **/ + rest( + array: Array, + pluckValue: string): T[]; + /** * @see _.rest **/ rest( array: List, pluckValue: string): T[]; - + /** * @see _.rest **/ - rest( + rest( + array: Array, + whereValue: W): T[]; + + /** + * @see _.rest + **/ + rest( array: List, whereValue: W): T[]; - /** - * @see _.rest - **/ - drop(array: List): T[]; + /** + * @see _.rest + **/ + drop(array: Array): T[]; - /** - * @see _.rest - **/ - drop( - array: List, - callback: ListIterator, - thisArg?: any): T[]; + /** + * @see _.rest + **/ + drop(array: List): T[]; - /** - * @see _.rest - **/ - drop( - array: List, - n: number): T[]; - - /** - * @see _.rest - **/ - drop( - array: List, - pluckValue: string): T[]; - - /** - * @see _.rest - **/ - drop( - array: List, - whereValue: W): T[]; + /** + * @see _.rest + **/ + drop( + array: Array, + callback: ListIterator, + thisArg?: any): T[]; - /** - * @see _.rest - **/ - tail(array: List): T[]; + /** + * @see _.rest + **/ + drop( + array: List, + callback: ListIterator, + thisArg?: any): T[]; - /** - * @see _.rest - **/ - tail( - array: List, - callback: ListIterator, - thisArg?: any): T[]; + /** + * @see _.rest + **/ + drop( + array: Array, + n: number): T[]; - /** - * @see _.rest - **/ - tail( - array: List, - n: number): T[]; - - /** - * @see _.rest - **/ - tail( - array: List, - pluckValue: string): T[]; - - /** - * @see _.rest - **/ - tail( - array: List, - whereValue: W): T[]; + /** + * @see _.rest + **/ + drop( + array: List, + n: number): T[]; + + /** + * @see _.rest + **/ + drop( + array: Array, + pluckValue: string): T[]; + + /** + * @see _.rest + **/ + drop( + array: List, + pluckValue: string): T[]; + + /** + * @see _.rest + **/ + drop( + array: Array, + whereValue: W): T[]; + + /** + * @see _.rest + **/ + drop( + array: List, + whereValue: W): T[]; + + /** + * @see _.rest + **/ + tail(array: Array): T[]; + + /** + * @see _.rest + **/ + tail(array: List): T[]; + + /** + * @see _.rest + **/ + tail( + array: Array, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.rest + **/ + tail( + array: List, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.rest + **/ + tail( + array: Array, + n: number): T[]; + + /** + * @see _.rest + **/ + tail( + array: List, + n: number): T[]; + + /** + * @see _.rest + **/ + tail( + array: Array, + pluckValue: string): T[]; + + /** + * @see _.rest + **/ + tail( + array: List, + pluckValue: string): T[]; + + /** + * @see _.rest + **/ + tail( + array: Array, + whereValue: W): T[]; + + /** + * @see _.rest + **/ + tail( + array: List, + whereValue: W): T[]; } //_.sortedIndex @@ -939,12 +1440,30 @@ declare module _ { * @param callback Iterator to compute the sort ranking of each value, optional. * @return The index at which value should be inserted into array. **/ + sortedIndex( + array: Array, + value: T, + callback?: (x: T) => TSort, + thisArg?: any): number; + + /** + * @see _.sortedIndex + **/ sortedIndex( array: List, value: T, - callback?: (x: T) => TSort, + callback?: (x: T) => TSort, thisArg?: any): number; + /** + * @see _.sortedIndex + * @param pluckValue the _.pluck style callback + **/ + sortedIndex( + array: Array, + value: T, + pluckValue: string): number; + /** * @see _.sortedIndex * @param pluckValue the _.pluck style callback @@ -954,6 +1473,15 @@ declare module _ { value: T, pluckValue: string): number; + /** + * @see _.sortedIndex + * @param pluckValue the _.where style callback + **/ + sortedIndex( + array: Array, + value: T, + whereValue: W): number; + /** * @see _.sortedIndex * @param pluckValue the _.where style callback @@ -972,6 +1500,11 @@ declare module _ { * @param arrays The arrays to inspect. * @return Returns an array of composite values. **/ + union(...arrays: Array[]): T[]; + + /** + * @see _.union + **/ union(...arrays: List[]): T[]; } @@ -995,14 +1528,39 @@ declare module _ { * @param context 'this' object in `iterator`, optional. * @return Copy of `array` where all elements are unique. **/ + uniq(array: Array, isSorted?: boolean): T[]; + + /** + * @see _.uniq + **/ uniq(array: List, isSorted?: boolean): T[]; + /** + * @see _.uniq + **/ + uniq( + array: Array, + isSorted: boolean, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.uniq + **/ uniq( array: List, isSorted: boolean, callback: ListIterator, thisArg?: any): T[]; + /** + * @see _.uniq + **/ + uniq( + array: Array, + callback: ListIterator, + thisArg?: any): T[]; + /** * @see _.uniq **/ @@ -1011,6 +1569,15 @@ declare module _ { callback: ListIterator, thisArg?: any): T[]; + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + uniq( + array: Array, + isSorted: boolean, + pluckValue: string): T[]; + /** * @see _.uniq * @param pluckValue _.pluck style callback @@ -1020,10 +1587,31 @@ declare module _ { isSorted: boolean, pluckValue: string): T[]; + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + uniq( + array: Array, + pluckValue: string): T[]; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ uniq( array: List, pluckValue: string): T[]; + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + uniq( + array: Array, + isSorted: boolean, + whereValue: W): T[]; + /** * @see _.uniq * @param whereValue _.where style callback @@ -1033,54 +1621,133 @@ declare module _ { isSorted: boolean, whereValue: W): T[]; + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + uniq( + array: Array, + whereValue: W): T[]; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ uniq( array: List, whereValue: W): T[]; - /** - * @see _.uniq - **/ - unique(array: List, isSorted?: boolean): T[]; + /** + * @see _.uniq + **/ + unique(array: Array, isSorted?: boolean): T[]; - unique( - array: List, - callback: ListIterator, - thisArg?: any): T[]; + /** + * @see _.uniq + **/ + unique(array: List, isSorted?: boolean): T[]; - /** - * @see _.uniq - **/ - unique( - array: List, - isSorted: boolean, - callback: ListIterator, - thisArg?: any): T[]; + /** + * @see _.uniq + **/ + unique( + array: Array, + callback: ListIterator, + thisArg?: any): T[]; - /** - * @see _.uniq - * @param pluckValue _.pluck style callback - **/ - unique( - array: List, - isSorted: boolean, - pluckValue: string): T[]; + /** + * @see _.uniq + **/ + unique( + array: List, + callback: ListIterator, + thisArg?: any): T[]; - unique( - array: List, - pluckValue: string): T[]; + /** + * @see _.uniq + **/ + unique( + array: Array, + isSorted: boolean, + callback: ListIterator, + thisArg?: any): T[]; - /** - * @see _.uniq - * @param whereValue _.where style callback - **/ - unique( - array: List, - whereValue?: W): T[]; + /** + * @see _.uniq + **/ + unique( + array: List, + isSorted: boolean, + callback: ListIterator, + thisArg?: any): T[]; - unique( - array: List, - isSorted: boolean, - whereValue?: W): T[]; + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + unique( + array: Array, + isSorted: boolean, + pluckValue: string): T[]; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + unique( + array: List, + isSorted: boolean, + pluckValue: string): T[]; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + unique( + array: Array, + pluckValue: string): T[]; + + /** + * @see _.uniq + * @param pluckValue _.pluck style callback + **/ + unique( + array: List, + pluckValue: string): T[]; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + unique( + array: Array, + whereValue?: W): T[]; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + unique( + array: List, + whereValue?: W): T[]; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + unique( + array: Array, + isSorted: boolean, + whereValue?: W): T[]; + + /** + * @see _.uniq + * @param whereValue _.where style callback + **/ + unique( + array: List, + isSorted: boolean, + whereValue?: W): T[]; } //_.without @@ -1091,6 +1758,13 @@ declare module _ { * @param values The value(s) to exclude. * @return A new array of filtered values. **/ + without( + array: Array, + ...values: T[]): T[]; + + /** + * @see _.without + **/ without( array: List, ...values: T[]): T[]; @@ -1112,15 +1786,15 @@ declare module _ { **/ zip(...arrays: any[]): any[]; - /** - * @see _.zip - **/ - unzip(...arrays: any[][]): any[][]; + /** + * @see _.zip + **/ + unzip(...arrays: any[][]): any[][]; - /** - * @see _.zip - **/ - unzip(...arrays: any[]): any[]; + /** + * @see _.zip + **/ + unzip(...arrays: any[]): any[]; } //_.zipObject @@ -1137,12 +1811,12 @@ declare module _ { keys: List, values: List): TResult; - /** - * @see _.object - **/ - object( - keys: List, - values: List): TResult; + /** + * @see _.object + **/ + object( + keys: List, + values: List): TResult; } /* ************* @@ -1160,14 +1834,42 @@ declare module _ { * @return A new array of elements corresponding to the provided indexes. **/ at( - collection: Collection, + collection: Array, indexes: number[]): T[]; /** * @see _.at **/ at( - collection: Collection, + collection: List, + indexes: number[]): T[]; + + /** + * @see _.at + **/ + at( + collection: Dictionary, + indexes: number[]): T[]; + + /** + * @see _.at + **/ + at( + collection: Array, + ...indexes: number[]): T[]; + + /** + * @see _.at + **/ + at( + collection: List, + ...indexes: number[]): T[]; + + /** + * @see _.at + **/ + at( + collection: Dictionary, ...indexes: number[]): T[]; } @@ -1182,7 +1884,15 @@ declare module _ { * @return True if the target element is found, else false. **/ contains( - collection: Collection, + collection: Array, + target: T, + fromIndex?: number): boolean; + + /** + * @see _.contains + **/ + contains( + collection: List, target: T, fromIndex?: number): boolean; @@ -1206,29 +1916,37 @@ declare module _ { targetString: string, fromIndex?: number): boolean; - /** - * @see _.contains - **/ - include( - collection: Collection, - target: T, - fromIndex?: number): boolean; + /** + * @see _.contains + **/ + include( + collection: Array, + target: T, + fromIndex?: number): boolean; - /** - * @see _.contains - **/ - include( - dictionary: Dictionary, - key: string, - fromIndex?: number): boolean; + /** + * @see _.contains + **/ + include( + collection: List, + target: T, + fromIndex?: number): boolean; - /** - * @see _.contains - **/ - include( - searchString: string, - targetString: string, - fromIndex?: number): boolean; + /** + * @see _.contains + **/ + include( + dictionary: Dictionary, + key: string, + fromIndex?: number): boolean; + + /** + * @see _.contains + **/ + include( + searchString: string, + targetString: string, + fromIndex?: number): boolean; } //_.countBy @@ -1250,7 +1968,7 @@ declare module _ { * @return Returns the composed aggregate object. **/ countBy( - collection: Collection, + collection: Array, callback?: ListIterator, thisArg?: any): Dictionary; @@ -1259,16 +1977,52 @@ declare module _ { * @param callback Function name **/ countBy( - collection: Collection, + collection: List, + callback?: ListIterator, + thisArg?: any): Dictionary; + + /** + * @see _.countBy + * @param callback Function name + **/ + countBy( + collection: Dictionary, + callback?: ListIterator, + thisArg?: any): Dictionary; + + /** + * @see _.countBy + * @param callback Function name + **/ + countBy( + collection: Array, callback: string, - thisArg?: any): Dictionary; + thisArg?: any): Dictionary; + + /** + * @see _.countBy + * @param callback Function name + **/ + countBy( + collection: List, + callback: string, + thisArg?: any): Dictionary; + + /** + * @see _.countBy + * @param callback Function name + **/ + countBy( + collection: Dictionary, + callback: string, + thisArg?: any): Dictionary; } interface LoDashArrayWrapper { /** * @see _.countBy **/ - countBy( + countBy( callback?: ListIterator, thisArg?: any): LoDashObjectWrapper>; @@ -1276,7 +2030,7 @@ declare module _ { * @see _.countBy * @param callback Function name **/ - countBy( + countBy( callback: string, thisArg?: any): LoDashObjectWrapper>; } @@ -1299,7 +2053,7 @@ declare module _ { * @return True if all elements passed the callback check, else false. **/ every( - collection: Collection, + collection: Array, callback?: ListIterator, thisArg?: any): boolean; @@ -1308,7 +2062,41 @@ declare module _ { * @param pluckValue _.pluck style callback **/ every( - collection: Collection, + collection: List, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.every + * @param pluckValue _.pluck style callback + **/ + every( + collection: Dictionary, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.every + * @param pluckValue _.pluck style callback + **/ + every( + collection: Array, + pluckValue: string): boolean; + + /** + * @see _.every + * @param pluckValue _.pluck style callback + **/ + every( + collection: List, + pluckValue: string): boolean; + + /** + * @see _.every + * @param pluckValue _.pluck style callback + **/ + every( + collection: Dictionary, pluckValue: string): boolean; /** @@ -1316,32 +2104,96 @@ declare module _ { * @param whereValue _.where style callback **/ every( - collection: Collection, + collection: Array, whereValue: W): boolean; - /** - * @see _.every - **/ - all( - collection: Collection, - callback?: ListIterator, - thisArg?: any): boolean; + /** + * @see _.every + * @param whereValue _.where style callback + **/ + every( + collection: List, + whereValue: W): boolean; - /** - * @see _.every - * @param pluckValue _.pluck style callback - **/ - all( - collection: Collection, - pluckValue: string): boolean; + /** + * @see _.every + * @param whereValue _.where style callback + **/ + every( + collection: Dictionary, + whereValue: W): boolean; - /** - * @see _.every - * @param whereValue _.where style callback - **/ - all( - collection: Collection, - whereValue: W): boolean; + /** + * @see _.every + **/ + all( + collection: Array, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.every + **/ + all( + collection: List, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.every + **/ + all( + collection: Dictionary, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.every + * @param pluckValue _.pluck style callback + **/ + all( + collection: Array, + pluckValue: string): boolean; + + /** + * @see _.every + * @param pluckValue _.pluck style callback + **/ + all( + collection: List, + pluckValue: string): boolean; + + /** + * @see _.every + * @param pluckValue _.pluck style callback + **/ + all( + collection: Dictionary, + pluckValue: string): boolean; + + /** + * @see _.every + * @param whereValue _.where style callback + **/ + all( + collection: Array, + whereValue: W): boolean; + + /** + * @see _.every + * @param whereValue _.where style callback + **/ + all( + collection: List, + whereValue: W): boolean; + + /** + * @see _.every + * @param whereValue _.where style callback + **/ + all( + collection: Dictionary, + whereValue: W): boolean; } //_.filter @@ -1362,7 +2214,23 @@ declare module _ { * @return Returns a new array of elements that passed the callback check. **/ filter( - collection: Collection, + collection: Array, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.filter + **/ + filter( + collection: List, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.filter + **/ + filter( + collection: Dictionary, callback: ListIterator, thisArg?: any): T[]; @@ -1371,47 +2239,127 @@ declare module _ { * @param pluckValue _.pluck style callback **/ filter( - collection: Collection, + collection: Array, pluckValue: string): T[]; /** * @see _.filter * @param pluckValue _.pluck style callback **/ - filter( - collection: Collection, - whereValue: W): T[]; + filter( + collection: List, + pluckValue: string): T[]; - /** - * @see _.filter - **/ - select( - collection: Collection, - callback: ListIterator, - thisArg?: any): T[]; + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + filter( + collection: Dictionary, + pluckValue: string): T[]; - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - collection: Collection, - pluckValue: string): T[]; + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + filter( + collection: Array, + whereValue: W): T[]; - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - collection: Collection, - whereValue: W): T[]; + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + filter( + collection: List, + whereValue: W): T[]; + + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + filter( + collection: Dictionary, + whereValue: W): T[]; + + /** + * @see _.filter + **/ + select( + collection: Array, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.filter + **/ + select( + collection: List, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.filter + **/ + select( + collection: Dictionary, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + select( + collection: Array, + pluckValue: string): T[]; + + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + select( + collection: List, + pluckValue: string): T[]; + + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + select( + collection: Dictionary, + pluckValue: string): T[]; + + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + select( + collection: Array, + whereValue: W): T[]; + + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + select( + collection: List, + whereValue: W): T[]; + + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + select( + collection: Dictionary, + whereValue: W): T[]; } interface LoDashArrayWrapper { /** * @see _.filter **/ - filter( + filter( callback: ListIterator, thisArg?: any): LoDashArrayWrapper; @@ -1419,36 +2367,36 @@ declare module _ { * @see _.filter * @param pluckValue _.pluck style callback **/ - filter( + filter( pluckValue: string): LoDashArrayWrapper; /** * @see _.filter * @param pluckValue _.pluck style callback **/ - filter( + filter( whereValue: W): LoDashArrayWrapper; - /** - * @see _.filter - **/ - select( - callback: ListIterator, - thisArg?: any): LoDashArrayWrapper; + /** + * @see _.filter + **/ + select( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - pluckValue: string): LoDashArrayWrapper; + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + select( + pluckValue: string): LoDashArrayWrapper; - /** - * @see _.filter - * @param pluckValue _.pluck style callback - **/ - select( - whereValue: W): LoDashArrayWrapper; + /** + * @see _.filter + * @param pluckValue _.pluck style callback + **/ + select( + whereValue: W): LoDashArrayWrapper; } //_.find @@ -1469,7 +2417,23 @@ declare module _ { * @return The found element, else undefined. **/ find( - collection: Collection, + collection: Array, + callback: ListIterator, + thisArg?: any): T; + + /** + * @see _.find + **/ + find( + collection: List, + callback: ListIterator, + thisArg?: any): T; + + /** + * @see _.find + **/ + find( + collection: Dictionary, callback: ListIterator, thisArg?: any): T; @@ -1478,7 +2442,23 @@ declare module _ { * @param _.pluck style callback **/ find( - collection: Collection, + collection: Array, + whereValue: W): T; + + /** + * @see _.find + * @param _.pluck style callback + **/ + find( + collection: List, + whereValue: W): T; + + /** + * @see _.find + * @param _.pluck style callback + **/ + find( + collection: Dictionary, whereValue: W): T; /** @@ -1486,56 +2466,168 @@ declare module _ { * @param _.where style callback **/ find( - collection: Collection, + collection: Array, pluckValue: string): T; - /** - * @see _.find - **/ - detect( - collection: Collection, - callback: ListIterator, - thisArg?: any): T; + /** + * @see _.find + * @param _.where style callback + **/ + find( + collection: List, + pluckValue: string): T; - /** - * @see _.find - * @param _.pluck style callback - **/ - detect( - collection: Collection, - whereValue: W): T; + /** + * @see _.find + * @param _.where style callback + **/ + find( + collection: Dictionary, + pluckValue: string): T; - /** - * @see _.find - * @param _.where style callback - **/ - detect( - collection: Collection, - pluckValue: string): T; + /** + * @see _.find + **/ + detect( + collection: Array, + callback: ListIterator, + thisArg?: any): T; - /** - * @see _.find - **/ - findWhere( - collection: Collection, - callback: ListIterator, - thisArg?: any): T; + /** + * @see _.find + **/ + detect( + collection: List, + callback: ListIterator, + thisArg?: any): T; - /** - * @see _.find - * @param _.pluck style callback - **/ - findWhere( - collection: Collection, - whereValue: W): T; + /** + * @see _.find + **/ + detect( + collection: Dictionary, + callback: ListIterator, + thisArg?: any): T; - /** - * @see _.find - * @param _.where style callback - **/ - findWhere( - collection: Collection, - pluckValue: string): T; + /** + * @see _.find + * @param _.pluck style callback + **/ + detect( + collection: Array, + whereValue: W): T; + + /** + * @see _.find + * @param _.pluck style callback + **/ + detect( + collection: List, + whereValue: W): T; + + /** + * @see _.find + * @param _.pluck style callback + **/ + detect( + collection: Dictionary, + whereValue: W): T; + + /** + * @see _.find + * @param _.where style callback + **/ + detect( + collection: Array, + pluckValue: string): T; + + /** + * @see _.find + * @param _.where style callback + **/ + detect( + collection: List, + pluckValue: string): T; + + /** + * @see _.find + * @param _.where style callback + **/ + detect( + collection: Dictionary, + pluckValue: string): T; + + /** + * @see _.find + **/ + findWhere( + collection: Array, + callback: ListIterator, + thisArg?: any): T; + + /** + * @see _.find + **/ + findWhere( + collection: List, + callback: ListIterator, + thisArg?: any): T; + + /** + * @see _.find + **/ + findWhere( + collection: Dictionary, + callback: ListIterator, + thisArg?: any): T; + + /** + * @see _.find + * @param _.pluck style callback + **/ + findWhere( + collection: Array, + whereValue: W): T; + + /** + * @see _.find + * @param _.pluck style callback + **/ + findWhere( + collection: List, + whereValue: W): T; + + /** + * @see _.find + * @param _.pluck style callback + **/ + findWhere( + collection: Dictionary, + whereValue: W): T; + + /** + * @see _.find + * @param _.where style callback + **/ + findWhere( + collection: Array, + pluckValue: string): T; + + /** + * @see _.find + * @param _.where style callback + **/ + findWhere( + collection: List, + pluckValue: string): T; + + /** + * @see _.find + * @param _.where style callback + **/ + findWhere( + collection: Dictionary, + pluckValue: string): T; } //_.findLast @@ -1549,7 +2641,23 @@ declare module _ { * @return The found element, else undefined. **/ findLast( - collection: Collection, + collection: Array, + callback: ListIterator, + thisArg?: any): T; + + /** + * @see _.find + **/ + findLast( + collection: List, + callback: ListIterator, + thisArg?: any): T; + + /** + * @see _.find + **/ + findLast( + collection: Dictionary, callback: ListIterator, thisArg?: any): T; @@ -1558,7 +2666,23 @@ declare module _ { * @param _.pluck style callback **/ findLast( - collection: Collection, + collection: Array, + whereValue: W): T; + + /** + * @see _.find + * @param _.pluck style callback + **/ + findLast( + collection: List, + whereValue: W): T; + + /** + * @see _.find + * @param _.pluck style callback + **/ + findLast( + collection: Dictionary, whereValue: W): T; /** @@ -1566,7 +2690,23 @@ declare module _ { * @param _.where style callback **/ findLast( - collection: Collection, + collection: Array, + pluckValue: string): T; + + /** + * @see _.find + * @param _.where style callback + **/ + findLast( + collection: List, + pluckValue: string): T; + + /** + * @see _.find + * @param _.where style callback + **/ + findLast( + collection: Dictionary, pluckValue: string): T; } @@ -1580,9 +2720,17 @@ declare module _ { * @param callback The function called per iteration. * @param thisArg The this binding of callback. **/ + forEach( + collection: Array, + callback: ListIterator, + thisArg?: any): Array; + + /** + * @see _.forEach + **/ forEach( collection: List, - callback: ListIterator, + callback: ListIterator, thisArg?: any): List; /** @@ -1590,43 +2738,51 @@ declare module _ { **/ forEach( object: Dictionary, - callback: ObjectIterator, + callback: ObjectIterator, thisArg?: any): Dictionary; - /** - * @see _.forEach - **/ - each( - collection: List, - callback: ListIterator, - thisArg?: any): List; + /** + * @see _.forEach + **/ + each( + collection: Array, + callback: ListIterator, + thisArg?: any): Array; - /** - * @see _.forEach - * @param object The object to iterate over - * @param callback The function called per iteration. - * @param thisArg The this binding of callback. - **/ - each( - object: Dictionary, - callback: ObjectIterator, - thisArg?: any): Dictionary; + /** + * @see _.forEach + **/ + each( + collection: List, + callback: ListIterator, + thisArg?: any): List; + + /** + * @see _.forEach + * @param object The object to iterate over + * @param callback The function called per iteration. + * @param thisArg The this binding of callback. + **/ + each( + object: Dictionary, + callback: ObjectIterator, + thisArg?: any): Dictionary; } interface LoDashArrayWrapper { /** * @see _.forEach **/ - forEach( - callback: ListIterator, + forEach( + callback: ListIterator, thisArg?: any): LoDashArrayWrapper; - /** - * @see _.forEach - **/ - each( - callback: ListIterator, - thisArg?: any): LoDashArrayWrapper; + /** + * @see _.forEach + **/ + each( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; } interface LoDashObjectWrapper { @@ -1634,15 +2790,15 @@ declare module _ { * @see _.forEach **/ forEach( - callback: ObjectIterator, + callback: ObjectIterator, thisArg?: any): LoDashObjectWrapper; - /** - * @see _.forEach - **/ - each( - callback: ObjectIterator, - thisArg?: any): LoDashObjectWrapper; + /** + * @see _.forEach + **/ + each( + callback: ObjectIterator, + thisArg?: any): LoDashObjectWrapper; } //_.forEachRight @@ -1654,9 +2810,17 @@ declare module _ { * @param callback The function called per iteration. * @param thisArg The this binding of callback. **/ + forEachRight( + collection: Array, + callback: ListIterator, + thisArg?: any): Array; + + /** + * @see _.forEachRight + **/ forEachRight( collection: List, - callback: ListIterator, + callback: ListIterator, thisArg?: any): List; /** @@ -1664,43 +2828,51 @@ declare module _ { **/ forEachRight( object: Dictionary, - callback: ObjectIterator, + callback: ObjectIterator, thisArg?: any): Dictionary; - /** - * @see _.forEachRight - **/ - eachRight( - collection: List, - callback: ListIterator, - thisArg?: any): List; + /** + * @see _.forEachRight + **/ + eachRight( + collection: Array, + callback: ListIterator, + thisArg?: any): Array; - /** - * @see _.forEachRight - * @param object The object to iterate over - * @param callback The function called per iteration. - * @param thisArg The this binding of callback. - **/ - eachRight( - object: Dictionary, - callback: ObjectIterator, - thisArg?: any): Dictionary; + /** + * @see _.forEachRight + **/ + eachRight( + collection: List, + callback: ListIterator, + thisArg?: any): List; + + /** + * @see _.forEachRight + * @param object The object to iterate over + * @param callback The function called per iteration. + * @param thisArg The this binding of callback. + **/ + eachRight( + object: Dictionary, + callback: ObjectIterator, + thisArg?: any): Dictionary; } interface LoDashArrayWrapper { /** * @see _.forEachRight **/ - forEachRight( - callback: ListIterator, + forEachRight( + callback: ListIterator, thisArg?: any): LoDashArrayWrapper; - /** - * @see _.forEachRight - **/ - eachRight( - callback: ListIterator, - thisArg?: any): LoDashArrayWrapper; + /** + * @see _.forEachRight + **/ + eachRight( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; } interface LoDashObjectWrapper { @@ -1708,18 +2880,18 @@ declare module _ { * @see _.forEachRight **/ forEachRight( - callback: ObjectIterator, + callback: ObjectIterator, thisArg?: any): LoDashObjectWrapper>; - /** - * @see _.forEachRight - * @param object The object to iterate over - * @param callback The function called per iteration. - * @param thisArg The this binding of callback. - **/ - eachRight( - callback: ObjectIterator, - thisArg?: any): LoDashObjectWrapper>; + /** + * @see _.forEachRight + * @param object The object to iterate over + * @param callback The function called per iteration. + * @param thisArg The this binding of callback. + **/ + eachRight( + callback: ObjectIterator, + thisArg?: any): LoDashObjectWrapper>; } //_.groupBy @@ -1739,11 +2911,27 @@ declare module _ { * @param thisArg The this binding of callback. * @return Returns the composed aggregate object. **/ + groupBy( + collection: Array, + callback?: ListIterator, + thisArg?: any): Dictionary; + + /** + * @see _.groupBy + **/ groupBy( collection: List, callback?: ListIterator, thisArg?: any): Dictionary; + /** + * @see _.groupBy + * @param pluckValue _.pluck style callback + **/ + groupBy( + collection: Array, + pluckValue: string): Dictionary; + /** * @see _.groupBy * @param pluckValue _.pluck style callback @@ -1752,6 +2940,14 @@ declare module _ { collection: List, pluckValue: string): Dictionary; + /** + * @see _.groupBy + * @param whereValue _.where style callback + **/ + groupBy( + collection: Array, + whereValue: W): Dictionary; + /** * @see _.groupBy * @param whereValue _.where style callback @@ -1761,24 +2957,24 @@ declare module _ { whereValue: W): Dictionary; } - interface LoDashArrayWrapper { + interface LoDashArrayWrapper { /** * @see _.groupBy **/ - groupBy( + groupBy( callback: ListIterator, thisArg?: any): _.LoDashObjectWrapper>; /** * @see _.groupBy **/ - groupBy( + groupBy( pluckValue: string): _.LoDashObjectWrapper>; /** * @see _.groupBy **/ - groupBy( + groupBy( whereValue: W): _.LoDashObjectWrapper>; } @@ -1800,11 +2996,27 @@ declare module _ { * @param thisArg The this binding of callback. * @return Returns the composed aggregate object. **/ + indexBy( + list: Array, + iterator: ListIterator, + context?: any): Dictionary; + + /** + * @see _.indexBy + **/ indexBy( list: List, iterator: ListIterator, context?: any): Dictionary; + /** + * @see _.indexBy + * @param pluckValue _.pluck style callback + **/ + indexBy( + collection: Array, + pluckValue: string): Dictionary; + /** * @see _.indexBy * @param pluckValue _.pluck style callback @@ -1813,6 +3025,14 @@ declare module _ { collection: List, pluckValue: string): Dictionary; + /** + * @see _.indexBy + * @param whereValue _.where style callback + **/ + indexBy( + collection: Array, + whereValue: W): Dictionary; + /** * @see _.indexBy * @param whereValue _.where style callback @@ -1834,7 +3054,7 @@ declare module _ { * @param args Arguments to invoke the method with. **/ invoke( - collection: Collection, + collection: Array, methodName: string, ...args: any[]): any; @@ -1842,7 +3062,39 @@ declare module _ { * @see _.invoke **/ invoke( - collection: Collection, + collection: List, + methodName: string, + ...args: any[]): any; + + /** + * @see _.invoke + **/ + invoke( + collection: Dictionary, + methodName: string, + ...args: any[]): any; + + /** + * @see _.invoke + **/ + invoke( + collection: Array, + method: Function, + ...args: any[]): any; + + /** + * @see _.invoke + **/ + invoke( + collection: List, + method: Function, + ...args: any[]): any; + + /** + * @see _.invoke + **/ + invoke( + collection: Dictionary, method: Function, ...args: any[]): any; } @@ -1864,6 +3116,14 @@ declare module _ { * @param theArg The this binding of callback. * @return The mapped array result. **/ + map( + collection: Array, + callback: ListIterator, + thisArg?: any): TResult[]; + + /** + * @see _.map + **/ map( collection: List, callback: ListIterator, @@ -1881,6 +3141,14 @@ declare module _ { callback: ObjectIterator, thisArg?: any): TResult[]; + /** + * @see _.map + * @param pluckValue _.pluck style callback + **/ + map( + collection: Array, + pluckValue: string): TResult[]; + /** * @see _.map * @param pluckValue _.pluck style callback @@ -1889,35 +3157,50 @@ declare module _ { collection: List, pluckValue: string): TResult[]; - /** - * @see _.map - **/ - collect( - collection: List, - callback: ListIterator, - thisArg?: any): TResult[]; + /** + * @see _.map + **/ + collect( + collection: Array, + callback: ListIterator, + thisArg?: any): TResult[]; - /** - * @see _.map - **/ - collect( - object: Dictionary, - callback: ObjectIterator, - thisArg?: any): TResult[]; + /** + * @see _.map + **/ + collect( + collection: List, + callback: ListIterator, + thisArg?: any): TResult[]; - /** - * @see _.map - **/ - collect( - collection: List, - pluckValue: string): TResult[]; + /** + * @see _.map + **/ + collect( + object: Dictionary, + callback: ObjectIterator, + thisArg?: any): TResult[]; + + /** + * @see _.map + **/ + collect( + collection: Array, + pluckValue: string): TResult[]; + + /** + * @see _.map + **/ + collect( + collection: List, + pluckValue: string): TResult[]; } interface LoDashArrayWrapper { /** * @see _.map **/ - map( + map( callback: ListIterator, thisArg?: any): LoDashArrayWrapper; @@ -1925,21 +3208,21 @@ declare module _ { * @see _.map * @param pluckValue _.pluck style callback **/ - map( + map( pluckValue: string): LoDashArrayWrapper; - /** - * @see _.map - **/ - collect( - callback: ListIterator, - thisArg?: any): LoDashArrayWrapper; + /** + * @see _.map + **/ + collect( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; - /** - * @see _.map - **/ - collect( - pluckValue: string): LoDashArrayWrapper; + /** + * @see _.map + **/ + collect( + pluckValue: string): LoDashArrayWrapper; } interface LoDashObjectWrapper { @@ -1948,14 +3231,14 @@ declare module _ { **/ map( callback: ObjectIterator, - thisArg?: any): LoDashObjectWrapper; + thisArg?: any): LoDashArrayWrapper; - /** - * @see _.map - **/ - collect( - callback: ObjectIterator, - thisArg?: any): LoDashObjectWrapper; + /** + * @see _.map + **/ + collect( + callback: ObjectIterator, + thisArg?: any): LoDashArrayWrapper; } //_.max @@ -1977,7 +3260,23 @@ declare module _ { * @return Returns the maximum value. **/ max( - collection: Collection, + collection: Array, + callback?: ListIterator, + thisArg?: any): T; + + /** + * @see _.max + **/ + max( + collection: List, + callback?: ListIterator, + thisArg?: any): T; + + /** + * @see _.max + **/ + max( + collection: Dictionary, callback?: ListIterator, thisArg?: any): T; @@ -1986,7 +3285,23 @@ declare module _ { * @param pluckValue _.pluck style callback **/ max( - collection: Collection, + collection: Array, + pluckValue: string): T; + + /** + * @see _.max + * @param pluckValue _.pluck style callback + **/ + max( + collection: List, + pluckValue: string): T; + + /** + * @see _.max + * @param pluckValue _.pluck style callback + **/ + max( + collection: Dictionary, pluckValue: string): T; /** @@ -1994,7 +3309,23 @@ declare module _ { * @param whereValue _.where style callback **/ max( - collection: Collection, + collection: Array, + whereValue: W): T; + + /** + * @see _.max + * @param whereValue _.where style callback + **/ + max( + collection: List, + whereValue: W): T; + + /** + * @see _.max + * @param whereValue _.where style callback + **/ + max( + collection: Dictionary, whereValue: W): T; } @@ -2017,7 +3348,23 @@ declare module _ { * @return Returns the maximum value. **/ min( - collection: Collection, + collection: Array, + callback?: ListIterator, + thisArg?: any): T; + + /** + * @see _.min + **/ + min( + collection: List, + callback?: ListIterator, + thisArg?: any): T; + + /** + * @see _.min + **/ + min( + collection: Dictionary, callback?: ListIterator, thisArg?: any): T; @@ -2026,7 +3373,23 @@ declare module _ { * @param pluckValue _.pluck style callback **/ min( - collection: Collection, + collection: Array, + pluckValue: string): T; + + /** + * @see _.min + * @param pluckValue _.pluck style callback + **/ + min( + collection: List, + pluckValue: string): T; + + /** + * @see _.min + * @param pluckValue _.pluck style callback + **/ + min( + collection: Dictionary, pluckValue: string): T; /** @@ -2034,7 +3397,23 @@ declare module _ { * @param whereValue _.where style callback **/ min( - collection: Collection, + collection: Array, + whereValue: W): T; + + /** + * @see _.min + * @param whereValue _.where style callback + **/ + min( + collection: List, + whereValue: W): T; + + /** + * @see _.min + * @param whereValue _.where style callback + **/ + min( + collection: Dictionary, whereValue: W): T; } @@ -2047,7 +3426,21 @@ declare module _ { * @return A new array of property values. **/ pluck( - collection: Collection, + collection: Array, + property: string): any[]; + + /** + * @see _.pluck + **/ + pluck( + collection: List, + property: string): any[]; + + /** + * @see _.pluck + **/ + pluck( + collection: Dictionary, property: string): any[]; } @@ -2066,52 +3459,154 @@ declare module _ { * @return Returns the accumulated value. **/ reduce( - collection: Collection, + collection: Array, callback: MemoIterator, accumulator: TResult, thisArg?: any): TResult; - /** - * @see _.reduce - **/ + /** + * @see _.reduce + **/ reduce( - collection: Collection, + collection: List, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + reduce( + collection: Dictionary, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + reduce( + collection: Array, callback: MemoIterator, thisArg?: any): TResult; - /** - * @see _.reduce - **/ - inject( - collection: Collection, - callback: MemoIterator, - accumulator: TResult, - thisArg?: any): TResult; + /** + * @see _.reduce + **/ + reduce( + collection: List, + callback: MemoIterator, + thisArg?: any): TResult; - /** - * @see _.reduce - **/ - inject( - collection: Collection, - callback: MemoIterator, - thisArg?: any): TResult; + /** + * @see _.reduce + **/ + reduce( + collection: Dictionary, + callback: MemoIterator, + thisArg?: any): TResult; - /** - * @see _.reduce - **/ - foldl( - collection: Collection, - callback: MemoIterator, - accumulator: TResult, - thisArg?: any): TResult; + /** + * @see _.reduce + **/ + inject( + collection: Array, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; - /** - * @see _.reduce - **/ - foldl( - collection: Collection, - callback: MemoIterator, - thisArg?: any): TResult; + /** + * @see _.reduce + **/ + inject( + collection: List, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + collection: Dictionary, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + collection: Array, + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + collection: List, + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + inject( + collection: Dictionary, + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + collection: Array, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + collection: List, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + collection: Dictionary, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + collection: Array, + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + collection: List, + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduce + **/ + foldl( + collection: Dictionary, + callback: MemoIterator, + thisArg?: any): TResult; } //_.reduceRight @@ -2126,35 +3621,103 @@ declare module _ { * @return The accumulated value. **/ reduceRight( - collection: Collection, + collection: Array, callback: MemoIterator, accumulator: TResult, thisArg?: any): TResult; - /** - * @see _.reduceRight - **/ + /** + * @see _.reduceRight + **/ reduceRight( - collection: Collection, + collection: List, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduceRight + **/ + reduceRight( + collection: Dictionary, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduceRight + **/ + reduceRight( + collection: Array, callback: MemoIterator, thisArg?: any): TResult; - /** - * @see _.reduceRight - **/ - foldr( - collection: Collection, - callback: MemoIterator, - accumulator: TResult, - thisArg?: any): TResult; + /** + * @see _.reduceRight + **/ + reduceRight( + collection: List, + callback: MemoIterator, + thisArg?: any): TResult; - /** - * @see _.reduceRight - **/ - foldr( - collection: Collection, - callback: MemoIterator, - thisArg?: any): TResult; + /** + * @see _.reduceRight + **/ + reduceRight( + collection: Dictionary, + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduceRight + **/ + foldr( + collection: Array, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduceRight + **/ + foldr( + collection: List, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduceRight + **/ + foldr( + collection: Dictionary, + callback: MemoIterator, + accumulator: TResult, + thisArg?: any): TResult; + + /** + * @see _.reduceRight + **/ + foldr( + collection: Array, + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduceRight + **/ + foldr( + collection: List, + callback: MemoIterator, + thisArg?: any): TResult; + + /** + * @see _.reduceRight + **/ + foldr( + collection: Dictionary, + callback: MemoIterator, + thisArg?: any): TResult; } //_.reject @@ -2174,7 +3737,23 @@ declare module _ { * @return A new array of elements that failed the callback check. **/ reject( - collection: Collection, + collection: Array, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.reject + **/ + reject( + collection: List, + callback: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.reject + **/ + reject( + collection: Dictionary, callback: ListIterator, thisArg?: any): T[]; @@ -2183,7 +3762,23 @@ declare module _ { * @param pluckValue _.pluck style callback **/ reject( - collection: Collection, + collection: Array, + pluckValue: string): T[]; + + /** + * @see _.reject + * @param pluckValue _.pluck style callback + **/ + reject( + collection: List, + pluckValue: string): T[]; + + /** + * @see _.reject + * @param pluckValue _.pluck style callback + **/ + reject( + collection: Dictionary, pluckValue: string): T[]; /** @@ -2191,7 +3786,23 @@ declare module _ { * @param whereValue _.where style callback **/ reject( - collection: Collection, + collection: Array, + whereValue: W): T[]; + + /** + * @see _.reject + * @param whereValue _.where style callback + **/ + reject( + collection: List, + whereValue: W): T[]; + + /** + * @see _.reject + * @param whereValue _.where style callback + **/ + reject( + collection: Dictionary, whereValue: W): T[]; } @@ -2202,13 +3813,35 @@ declare module _ { * @param collection The collection to sample. * @return Returns the random sample(s) of collection. **/ - sample(collection: Collection): T; + sample(collection: Array): T; + + /** + * @see _.sample + **/ + sample(collection: List): T; + + /** + * @see _.sample + **/ + sample(collection: Dictionary): T; /** * @see _.sample * @param n The number of elements to sample. **/ - sample(collection: Collection, n: number): T[]; + sample(collection: Array, n: number): T[]; + + /** + * @see _.sample + * @param n The number of elements to sample. + **/ + sample(collection: List, n: number): T[]; + + /** + * @see _.sample + * @param n The number of elements to sample. + **/ + sample(collection: Dictionary, n: number): T[]; } //_.shuffle @@ -2219,7 +3852,17 @@ declare module _ { * @param collection The collection to shuffle. * @return Returns a new shuffled collection. **/ - shuffle(collection: Collection): T[]; + shuffle(collection: Array): T[]; + + /** + * @see _.shuffle + **/ + shuffle(collection: List): T[]; + + /** + * @see _.shuffle + **/ + shuffle(collection: Dictionary): T[]; } //_.size @@ -2230,6 +3873,11 @@ declare module _ { * @param collection The collection to inspect. * @return collection.length **/ + size(collection: Array): number; + + /** + * @see _.size + **/ size(collection: List): number; /** @@ -2265,7 +3913,23 @@ declare module _ { * @return True if any element passed the callback check, else false. **/ some( - collection: Collection, + collection: Array, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.some + **/ + some( + collection: List, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.some + **/ + some( + collection: Dictionary, callback?: ListIterator, thisArg?: any): boolean; @@ -2274,7 +3938,23 @@ declare module _ { * @param pluckValue _.pluck style callback **/ some( - collection: Collection, + collection: Array, + pluckValue: string): boolean; + + /** + * @see _.some + * @param pluckValue _.pluck style callback + **/ + some( + collection: List, + pluckValue: string): boolean; + + /** + * @see _.some + * @param pluckValue _.pluck style callback + **/ + some( + collection: Dictionary, pluckValue: string): boolean; /** @@ -2282,32 +3962,96 @@ declare module _ { * @param whereValue _.where style callback **/ some( - collection: Collection, + collection: Array, whereValue: W): boolean; - /** - * @see _.some - **/ - any( - collection: Collection, - callback?: ListIterator, - thisArg?: any): boolean; + /** + * @see _.some + * @param whereValue _.where style callback + **/ + some( + collection: List, + whereValue: W): boolean; - /** - * @see _.some - * @param pluckValue _.pluck style callback - **/ - any( - collection: Collection, - pluckValue: string): boolean; + /** + * @see _.some + * @param whereValue _.where style callback + **/ + some( + collection: Dictionary, + whereValue: W): boolean; - /** - * @see _.some - * @param whereValue _.where style callback - **/ - any( - collection: Collection, - whereValue: W): boolean; + /** + * @see _.some + **/ + any( + collection: Array, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.some + **/ + any( + collection: List, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.some + **/ + any( + collection: Dictionary, + callback?: ListIterator, + thisArg?: any): boolean; + + /** + * @see _.some + * @param pluckValue _.pluck style callback + **/ + any( + collection: Array, + pluckValue: string): boolean; + + /** + * @see _.some + * @param pluckValue _.pluck style callback + **/ + any( + collection: List, + pluckValue: string): boolean; + + /** + * @see _.some + * @param pluckValue _.pluck style callback + **/ + any( + collection: Dictionary, + pluckValue: string): boolean; + + /** + * @see _.some + * @param whereValue _.where style callback + **/ + any( + collection: Array, + whereValue: W): boolean; + + /** + * @see _.some + * @param whereValue _.where style callback + **/ + any( + collection: List, + whereValue: W): boolean; + + /** + * @see _.some + * @param whereValue _.where style callback + **/ + any( + collection: Dictionary, + whereValue: W): boolean; } //_.sortBy @@ -2328,11 +4072,27 @@ declare module _ { * @param thisArg The this binding of callback. * @return A new array of sorted elements. **/ + sortBy( + collection: Array, + callback?: ListIterator, + thisArg?: any): T[]; + + /** + * @see _.sortBy + **/ sortBy( collection: List, callback?: ListIterator, thisArg?: any): T[]; + /** + * @see _.sortBy + * @param pluckValue _.pluck style callback + **/ + sortBy( + collection: Array, + pluckValue: string): T[]; + /** * @see _.sortBy * @param pluckValue _.pluck style callback @@ -2341,6 +4101,14 @@ declare module _ { 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 @@ -2357,7 +4125,17 @@ declare module _ { * @param collection The collection to convert. * @return The new converted array. **/ - toArray(collection: Collection): T[]; + toArray(collection: Array): T[]; + + /** + * @see _.toArray + **/ + toArray(collection: List): T[]; + + /** + * @see _.toArray + **/ + toArray(collection: Dictionary): T[]; } //_.where @@ -2370,7 +4148,21 @@ declare module _ { * @return A new array of elements that have the given properties. **/ where( - list: Collection, + list: Array, + properties: U): T[]; + + /** + * @see _.where + **/ + where( + list: List, + properties: U): T[]; + + /** + * @see _.where + **/ + where( + list: Dictionary, properties: U): T[]; } @@ -2389,7 +4181,7 @@ declare module _ { **/ after( n: number, - func: Function): Function; + func: Function): Function; } interface LoDashWrapper { @@ -2412,7 +4204,7 @@ declare module _ { bind( func: Function, thisArg: any, - ...args: any[]): () => any; + ...args: any[]): () => any; } interface LoDashObjectWrapper { @@ -2437,14 +4229,14 @@ declare module _ { **/ bindAll( object: T, - ...methodNames: string[]): T; + ...methodNames: string[]): T; } interface LoDashObjectWrapper { /** * @see _.bindAll **/ - bindAll(...methodNames: string[]): LoDashWrapper; + bindAll(...methodNames: string[]): LoDashWrapper; } //_.bindKey @@ -2462,7 +4254,7 @@ declare module _ { bindKey( object: T, key: string, - ...args: any[]): Function; + ...args: any[]): Function; } interface LoDashObjectWrapper { @@ -2484,7 +4276,7 @@ declare module _ { * @param funcs Functions to compose. * @return The new composed function. **/ - compose(...funcs: Function[]): Function; + compose(...funcs: Function[]): Function; } interface LoDashObjectWrapper { @@ -2517,7 +4309,7 @@ declare module _ { createCallback( func: Dictionary, thisArg?: any, - argCount?: number): () => boolean; + argCount?: number): () => boolean; } interface LoDashWrapper { @@ -2551,7 +4343,7 @@ declare module _ { **/ curry( func: Function, - arity?: number): Function; + arity?: number): Function; } interface LoDashObjectWrapper { @@ -2583,7 +4375,7 @@ declare module _ { debounce( func: T, wait: number, - options?: DebounceSettings): T; + options?: DebounceSettings): T; } interface LoDashObjectWrapper { @@ -2600,7 +4392,7 @@ declare module _ { * Specify execution on the leading edge of the timeout. **/ leading?: boolean; - + /** * The maximum time func is allowed to be delayed before it’s called. **/ @@ -2623,7 +4415,7 @@ declare module _ { **/ defer( func: Function, - ...args: any[]): number; + ...args: any[]): number; } interface LoDashObjectWrapper { @@ -2646,7 +4438,7 @@ declare module _ { delay( func: Function, wait: number, - ...args: any[]): number; + ...args: any[]): number; } interface LoDashObjectWrapper { @@ -2670,7 +4462,7 @@ declare module _ { * @param resolver Hash function for storing the result of `fn`. * @return Returns the new memoizing function. **/ - memoize( + memoize( func: T, resolver?: Function): T; } @@ -2684,7 +4476,7 @@ declare module _ { * @param func Function to only execute once. * @return The new restricted function. **/ - once(func: T): T; + once(func: T): T; } //_.partial @@ -2733,7 +4525,7 @@ declare module _ { * @param options.trailing Specify execution on the trailing edge of the timeout. * @return The new throttled function. **/ - throttle( + throttle( func: T, wait: number, options?: ThrottleSettings): T; @@ -2784,86 +4576,86 @@ declare module _ { * @param thisArg The this binding of callback. * @return The destination object. **/ - assign( - object: T, - s1: S1, + assign( + object: T, + s1: S1, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.assign **/ - assign( - object: T, - s1: S1, - s2: S2, + assign( + object: T, + s1: S1, + s2: S2, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.assign **/ - assign( - object: T, - s1: S1, - s2: S2, - s3: S3, + assign( + object: T, + s1: S1, + s2: S2, + s3: S3, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.assign **/ - assign( - object: T, - s1: S1, - s2: S2, - s3: S3, - s4: S4, + assign( + object: T, + s1: S1, + s2: S2, + s3: S3, + s4: S4, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.assign **/ - extend( - object: T, - s1: S1, + extend( + object: T, + s1: S1, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.assign **/ - extend( - object: T, - s1: S1, - s2: S2, + extend( + object: T, + s1: S1, + s2: S2, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.assign **/ - extend( - object: T, - s1: S1, - s2: S2, - s3: S3, + extend( + object: T, + s1: S1, + s2: S2, + s3: S3, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.assign **/ - extend( - object: T, - s1: S1, - s2: S2, - s3: S3, - s4: S4, + extend( + object: T, + s1: S1, + s2: S2, + s3: S3, + s4: S4, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; } interface LoDashObjectWrapper { @@ -2914,52 +4706,52 @@ declare module _ { callback?: (objectValue: Value, sourceValue: Value) => Value, thisArg?: any): TResult; - /** - * @see _.assign - **/ - extend( - s1: S1, - callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): TResult; + /** + * @see _.assign + **/ + extend( + s1: S1, + callback?: (objectValue: Value, sourceValue: Value) => Value, + thisArg?: any): TResult; - /** - * @see _.assign - **/ - extend( - s1: S1, - s2: S2, - callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): TResult; - /** - * @see _.assign - **/ - extend( - s1: S1, - s2: S2, - s3: S3, - callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): TResult; - /** - * @see _.assign - **/ - extend( - s1: S1, - s2: S2, - s3: S3, - s4: S4, - callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): TResult; - /** - * @see _.assign - **/ - extend( - s1: S1, - s2: S2, - s3: S3, - s4: S4, - s5: S5, - callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): TResult; + /** + * @see _.assign + **/ + extend( + s1: S1, + s2: S2, + callback?: (objectValue: Value, sourceValue: Value) => Value, + thisArg?: any): TResult; + /** + * @see _.assign + **/ + extend( + s1: S1, + s2: S2, + s3: S3, + callback?: (objectValue: Value, sourceValue: Value) => Value, + thisArg?: any): TResult; + /** + * @see _.assign + **/ + extend( + s1: S1, + s2: S2, + s3: S3, + s4: S4, + callback?: (objectValue: Value, sourceValue: Value) => Value, + thisArg?: any): TResult; + /** + * @see _.assign + **/ + extend( + s1: S1, + s2: S2, + s3: S3, + s4: S4, + s5: S5, + callback?: (objectValue: Value, sourceValue: Value) => Value, + thisArg?: any): TResult; } @@ -3017,7 +4809,7 @@ declare module _ { **/ defaults( object: T, - ...sources: any[]): TResult; + ...sources: any[]): TResult; } interface LoDashObjectWrapper { @@ -3054,7 +4846,7 @@ declare module _ { * @see _.findKey * @param whereValue _.where style callback **/ - findKey, T>( + findKey, T>( object: T, whereValue: W): string; } @@ -3085,7 +4877,7 @@ declare module _ { * @see _.findLastKey * @param whereValue _.where style callback **/ - findLastKey, T>( + findLastKey, T>( object: T, whereValue: W): string; } @@ -3105,9 +4897,17 @@ declare module _ { object: Dictionary, callback?: ObjectIterator, thisArg?: any): Dictionary; + + /** + * @see _.forIn + **/ + forIn( + object: T, + callback?: ObjectIterator, + thisArg?: any): T; } - interface LoDashObjectWrapper { + interface LoDashObjectWrapper { /** * @see _.forIn **/ @@ -3130,9 +4930,17 @@ declare module _ { object: Dictionary, callback?: ObjectIterator, thisArg?: any): Dictionary; + + /** + * @see _.forInRight + **/ + forInRight( + object: T, + callback?: ObjectIterator, + thisArg?: any): T; } - interface LoDashObjectWrapper { + interface LoDashObjectWrapper { /** * @see _.forInRight **/ @@ -3156,9 +4964,17 @@ declare module _ { object: Dictionary, callback?: ObjectIterator, thisArg?: any): Dictionary; + + /** + * @see _.forOwn + **/ + forOwn( + object: T, + callback?: ObjectIterator, + thisArg?: any): T; } - interface LoDashObjectWrapper { + interface LoDashObjectWrapper { /** * @see _.forOwn **/ @@ -3181,9 +4997,16 @@ declare module _ { object: Dictionary, callback?: ObjectIterator, thisArg?: any): Dictionary; + /** + * @see _.forOwnRight + **/ + forOwnRight( + object: T, + callback?: ObjectIterator, + thisArg?: any): T; } - interface LoDashObjectWrapper { + interface LoDashObjectWrapper { /** * @see _.forOwnRight **/ @@ -3202,22 +5025,22 @@ declare module _ { **/ functions(object: any): string[]; - /** - * @see _functions - **/ - methods(object: any): string[]; + /** + * @see _functions + **/ + methods(object: any): string[]; } - interface LoDashObjectWrapper { + interface LoDashObjectWrapper { /** * @see _.functions **/ functions(): _.LoDashArrayWrapper; - /** - * @see _.functions - **/ - methods(): _.LoDashArrayWrapper; + /** + * @see _.functions + **/ + methods(): _.LoDashArrayWrapper; } //_.has @@ -3311,7 +5134,7 @@ declare module _ { * @see _.isEmpty **/ isEmpty(value: string): boolean; - + /** * @see _.isEmpty **/ @@ -3472,44 +5295,44 @@ declare module _ { * @param thisArg The this binding of callback. * @return The destination object. **/ - merge( - object: T, - s1: S1, + merge( + object: T, + s1: S1, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.merge **/ - merge( - object: T, - s1: S1, - s2: S2, + merge( + object: T, + s1: S1, + s2: S2, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.merge **/ - merge( - object: T, - s1: S1, - s2: S2, - s3: S3, + merge( + object: T, + s1: S1, + s2: S2, + s3: S3, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; /** * @see _.merge **/ - merge( - object: T, - s1: S1, - s2: S2, - s3: S3, - s4: S4, + merge( + object: T, + s1: S1, + s2: S2, + s3: S3, + s4: S4, callback?: (objectValue: Value, sourceValue: Value) => Value, - thisArg?: any): Result; + thisArg?: any): Result; } //_.omit @@ -3524,7 +5347,7 @@ declare module _ { * @param keys The properties to omit. * @return An object without the omitted properties. **/ - omit( + omit( object: T, ...keys: string[]): Omitted; @@ -3567,7 +5390,7 @@ declare module _ { * @param keys Property names to pick * @return An object composed of the picked properties. **/ - pick( + pick( object: T, ...keys: string[]): Picked; @@ -3602,7 +5425,7 @@ declare module _ { * @return The accumulated value. **/ transform( - collection: Collection, + collection: Array, callback: MemoVoidIterator, accumulator: Acc, thisArg?: any): Acc; @@ -3611,7 +5434,41 @@ declare module _ { * @see _.transform **/ transform( - collection: Collection, + collection: List, + callback: MemoVoidIterator, + accumulator: Acc, + thisArg?: any): Acc; + + /** + * @see _.transform + **/ + transform( + collection: Dictionary, + callback: MemoVoidIterator, + accumulator: Acc, + thisArg?: any): Acc; + + /** + * @see _.transform + **/ + transform( + collection: Array, + callback?: MemoVoidIterator, + thisArg?: any): Acc; + + /** + * @see _.transform + **/ + transform( + collection: List, + callback?: MemoVoidIterator, + thisArg?: any): Acc; + + /** + * @see _.transform + **/ + transform( + collection: Dictionary, callback?: MemoVoidIterator, thisArg?: any): Acc; } @@ -3693,7 +5550,7 @@ declare module _ { * @return A random number. **/ random(max: number, floating?: boolean): number; - + /** * @see _.random * @param min The minimum possible value. @@ -3752,13 +5609,13 @@ declare module _ { **/ template( text: string): TemplateExecutor; - + /** * @see _.template **/ template( text: string, - data: any, + data: any, options?: TemplateSettings, sourceURL?: string, variable?: string): any /* string or TemplateExecutor*/; @@ -3768,7 +5625,7 @@ declare module _ { (...data: any[]): string; source: string; } - + //_.times interface LoDashStatic { /** @@ -3779,8 +5636,8 @@ declare module _ { * @param thisArg The this binding of callback. **/ times( - n: number, - callback: (num: number) => TResult, + n: number, + callback: (num: number) => TResult, context?: any): TResult[]; } @@ -3820,24 +5677,24 @@ declare module _ { interface MemoIterator { (prev: TResult, curr: T, indexOrKey: any, list?: T[]): TResult; } - /* + /* interface MemoListIterator { (prev: TResult, curr: T, index: number, list?: T[]): TResult; } interface MemoObjectIterator { (prev: TResult, curr: T, index: string, object?: Dictionary): TResult; } - */ + */ - interface Collection { } + //interface Collection {} // Common interface between Arrays and jQuery objects - interface List extends Collection { + interface List { [index: number]: T; length: number; } - interface Dictionary extends Collection { + interface Dictionary { [index: string]: T; } } From d98910416f97ee6f5635ef7bd8e68b70565616ad Mon Sep 17 00:00:00 2001 From: miffels Date: Tue, 8 Apr 2014 12:05:23 +0200 Subject: [PATCH 02/49] Adjusting type angular.resource type definitions and tests to better reflect actual interface (particularly promises) --- angularjs/angular-resource-tests.ts | 49 +++++++++++- angularjs/angular-resource.d.ts | 112 +++++++++++++++++----------- 2 files changed, 117 insertions(+), 44 deletions(-) diff --git a/angularjs/angular-resource-tests.ts b/angularjs/angular-resource-tests.ts index 2870b21ad8..5a276e949d 100644 --- a/angularjs/angular-resource-tests.ts +++ b/angularjs/angular-resource-tests.ts @@ -19,7 +19,9 @@ actionDescriptor.params = { key: 'value' }; /////////////////////////////////////// var resourceClass: IMyResourceClass; var resource: IMyResource; -var resourceArray: IMyResource[]; +var resourceArray: ng.resource.IResourceArray; +var promise : ng.IPromise; +var arrayPromise : ng.IPromise; resource = resourceClass.delete(); resource = resourceClass.delete({ key: 'value' }); @@ -30,6 +32,15 @@ resource = resourceClass.delete({ key: 'value' }, { key: 'value' }); resource = resourceClass.delete({ key: 'value' }, { key: 'value' }, function () { }); resource = resourceClass.delete({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +promise = resource.$delete(); +promise = resource.$delete({ key: 'value' }); +promise = resource.$delete({ key: 'value' }, function () { }); +promise = resource.$delete(function () { }); +promise = resource.$delete(function () { }, function () { }); +promise = resource.$delete({ key: 'value' }, { key: 'value' }); +promise = resource.$delete({ key: 'value' }, { key: 'value' }, function () { }); +promise = resource.$delete({ key: 'value' }, { key: 'value' }, function () { }, function () { }); + resource = resourceClass.get(); resource = resourceClass.get({ key: 'value' }); resource = resourceClass.get({ key: 'value' }, function () { }); @@ -39,6 +50,15 @@ resource = resourceClass.get({ key: 'value' }, { key: 'value' }); resource = resourceClass.get({ key: 'value' }, { key: 'value' }, function () { }); resource = resourceClass.get({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +promise = resource.$get(); +promise = resource.$get({ key: 'value' }); +promise = resource.$get({ key: 'value' }, function () { }); +promise = resource.$get(function () { }); +promise = resource.$get(function () { }, function () { }); +promise = resource.$get({ key: 'value' }, { key: 'value' }); +promise = resource.$get({ key: 'value' }, { key: 'value' }, function () { }); +promise = resource.$get({ key: 'value' }, { key: 'value' }, function () { }, function () { }); + resourceArray = resourceClass.query(); resourceArray = resourceClass.query({ key: 'value' }); resourceArray = resourceClass.query({ key: 'value' }, function () { }); @@ -48,6 +68,15 @@ resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }); resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }, function () { }); resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +arrayPromise = resourceArray[0].query(); +arrayPromise = resourceArray[0].query({ key: 'value' }); +arrayPromise = resourceArray[0].query({ key: 'value' }, function () { }); +arrayPromise = resourceArray[0].query(function () { }); +arrayPromise = resourceArray[0].query(function () { }, function () { }); +arrayPromise = resourceArray[0].query({ key: 'value' }, { key: 'value' }); +arrayPromise = resourceArray[0].query({ key: 'value' }, { key: 'value' }, function () { }); +arrayPromise = resourceArray[0].query({ key: 'value' }, { key: 'value' }, function () { }, function () { }); + resource = resourceClass.remove(); resource = resourceClass.remove({ key: 'value' }); resource = resourceClass.remove({ key: 'value' }, function () { }); @@ -57,6 +86,15 @@ resource = resourceClass.remove({ key: 'value' }, { key: 'value' }); resource = resourceClass.remove({ key: 'value' }, { key: 'value' }, function () { }); resource = resourceClass.remove({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +promise = resource.$remove(); +promise = resource.$remove({ key: 'value' }); +promise = resource.$remove({ key: 'value' }, function () { }); +promise = resource.$remove(function () { }); +promise = resource.$remove(function () { }, function () { }); +promise = resource.$remove({ key: 'value' }, { key: 'value' }); +promise = resource.$remove({ key: 'value' }, { key: 'value' }, function () { }); +promise = resource.$remove({ key: 'value' }, { key: 'value' }, function () { }, function () { }); + resource = resourceClass.save(); resource = resourceClass.save({ key: 'value' }); resource = resourceClass.save({ key: 'value' }, function () { }); @@ -66,6 +104,15 @@ resource = resourceClass.save({ key: 'value' }, { key: 'value' }); resource = resourceClass.save({ key: 'value' }, { key: 'value' }, function () { }); resource = resourceClass.save({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +promise = resource.$save(); +promise = resource.$save({ key: 'value' }); +promise = resource.$save({ key: 'value' }, function () { }); +promise = resource.$save(function () { }); +promise = resource.$save(function () { }, function () { }); +promise = resource.$save({ key: 'value' }, { key: 'value' }); +promise = resource.$save({ key: 'value' }, { key: 'value' }, function () { }); +promise = resource.$save({ key: 'value' }, { key: 'value' }, function () { }, function () { }); + /////////////////////////////////////// // IResourceService /////////////////////////////////////// diff --git a/angularjs/angular-resource.d.ts b/angularjs/angular-resource.d.ts index a0cd4ab85a..942e5e120d 100644 --- a/angularjs/angular-resource.d.ts +++ b/angularjs/angular-resource.d.ts @@ -53,64 +53,90 @@ declare module ng.resource { interface IResourceClass { new(dataOrParams? : any) : T; get(): T; - get(dataOrParams: any): T; - get(dataOrParams: any, success: Function): T; + get(params: Object): T; get(success: Function, error?: Function): T; - get(params: any, data: any, success?: Function, error?: Function): T; + get(params: Object, success: Function, error?: Function): T; + get(params: Object, data: Object, success?: Function): T; + get(params: Object, data: Object, success: Function, error?: Function): T; + + query(): IResourceArray; + query(params: Object): IResourceArray; + query(success: Function, error?: Function): IResourceArray; + query(params: Object, success: Function, error?: Function): IResourceArray; + query(params: Object, data: Object, success?: Function): IResourceArray; + query(params: Object, data: Object, success: Function, error?: Function): IResourceArray; + save(): T; - save(dataOrParams: any): T; - save(dataOrParams: any, success: Function): T; + save(data: Object): T; save(success: Function, error?: Function): T; - save(params: any, data: any, success?: Function, error?: Function): T; - query(): T[]; - query(dataOrParams: any): T[]; - query(dataOrParams: any, success: Function): T[]; - query(success: Function, error?: Function): T[]; - query(params: any, data: any, success?: Function, error?: Function): T[]; + save(data: Object, success: Function, error?: Function): T; + save(params: Object, data: Object, success?: Function): T; + save(params: Object, data: Object, success: Function, error?: Function): T; + remove(): T; - remove(dataOrParams: any): T; - remove(dataOrParams: any, success: Function): T; + remove(params: Object): T; remove(success: Function, error?: Function): T; - remove(params: any, data: any, success?: Function, error?: Function): T; + remove(params: Object, success: Function, error?: Function): T; + remove(params: Object, data: Object, success?: Function): T; + remove(params: Object, data: Object, success: Function, error?: Function): T; + delete(): T; - delete(dataOrParams: any): T; - delete(dataOrParams: any, success: Function): T; + delete(params: Object): T; delete(success: Function, error?: Function): T; - delete(params: any, data: any, success?: Function, error?: Function): T; + delete(params: Object, success: Function, error?: Function): T; + delete(params: Object, data: Object, success?: Function): T; + delete(params: Object, data: Object, success: Function, error?: Function): T; } interface IResource { - $get(): T; - $get(dataOrParams: any): T; - $get(dataOrParams: any, success: Function): T; - $get(success: Function, error?: Function): T; - $get(params: any, data: any, success?: Function, error?: Function): T; - $save(): T; - $save(dataOrParams: any): T; - $save(dataOrParams: any, success: Function): T; - $save(success: Function, error?: Function): T; - $save(params: any, data: any, success?: Function, error?: Function): T; - $query(): T[]; - $query(dataOrParams: any): T[]; - $query(dataOrParams: any, success: Function): T[]; - $query(success: Function, error?: Function): T[]; - $query(params: any, data: any, success?: Function, error?: Function): T[]; - $remove(): T; - $remove(dataOrParams: any): T; - $remove(dataOrParams: any, success: Function): T; - $remove(success: Function, error?: Function): T; - $remove(params: any, data: any, success?: Function, error?: Function): T; - $delete(): T; - $delete(dataOrParams: any): T; - $delete(dataOrParams: any, success: Function): T; - $delete(success: Function, error?: Function): T; - $delete(params: any, data: any, success?: Function, error?: Function): T; - + $get(): ng.IPromise; + $get(params: Object): ng.IPromise; + $get(success: Function, error?: Function): ng.IPromise; + $get(params: Object, success: Function, error?: Function): ng.IPromise; + $get(params: Object, data: Object, success?: Function): ng.IPromise; + $get(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; + + $query(): ng.IPromise; + $query(params: Object): ng.IPromise; + $query(success: Function, error?: Function): ng.IPromise; + $query(params: Object, success: Function, error?: Function): ng.IPromise; + $query(params: Object, data: Object, success?: Function): ng.IPromise; + $query(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; + + $save(): ng.IPromise; + $save(data: Object): ng.IPromise; + $save(success: Function, error?: Function): ng.IPromise; + $save(data: Object, success: Function, error?: Function): ng.IPromise; + $save(params: Object, data: Object, success?: Function): ng.IPromise; + $save(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; + + $remove(): ng.IPromise; + $remove(params: Object): ng.IPromise; + $remove(success: Function, error?: Function): ng.IPromise; + $remove(params: Object, success: Function, error?: Function): ng.IPromise; + $remove(params: Object, data: Object, success?: Function): ng.IPromise; + $remove(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; + + $delete(): ng.IPromise; + $delete(params: Object): ng.IPromise; + $delete(success: Function, error?: Function): ng.IPromise; + $delete(params: Object, success: Function, error?: Function): ng.IPromise; + $delete(params: Object, data: Object, success?: Function): ng.IPromise; + $delete(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; + /** the promise of the original server interaction that created this instance. **/ $promise : ng.IPromise; $resolved : boolean; } + interface Array {} + + interface IResourceArray extends Array { + /** the promise of the original server interaction that created this collection. **/ + $promise : ng.IPromise; + $resolved : boolean; + } + /** when creating a resource factory via IModule.factory */ interface IResourceServiceFactoryFunction { ($resource: ng.resource.IResourceService): IResourceClass; From f037b846658263f8eb8d7a01de7d072b5c7289e2 Mon Sep 17 00:00:00 2001 From: miffels Date: Tue, 8 Apr 2014 13:46:34 +0200 Subject: [PATCH 03/49] Fixing array interface and tests and adding humble co-author note --- angularjs/angular-resource-tests.ts | 86 ++++++++++++++++------------- angularjs/angular-resource.d.ts | 11 ++-- 2 files changed, 54 insertions(+), 43 deletions(-) diff --git a/angularjs/angular-resource-tests.ts b/angularjs/angular-resource-tests.ts index 5a276e949d..327fcaba6e 100644 --- a/angularjs/angular-resource-tests.ts +++ b/angularjs/angular-resource-tests.ts @@ -20,8 +20,6 @@ actionDescriptor.params = { key: 'value' }; var resourceClass: IMyResourceClass; var resource: IMyResource; var resourceArray: ng.resource.IResourceArray; -var promise : ng.IPromise; -var arrayPromise : ng.IPromise; resource = resourceClass.delete(); resource = resourceClass.delete({ key: 'value' }); @@ -32,15 +30,6 @@ resource = resourceClass.delete({ key: 'value' }, { key: 'value' }); resource = resourceClass.delete({ key: 'value' }, { key: 'value' }, function () { }); resource = resourceClass.delete({ key: 'value' }, { key: 'value' }, function () { }, function () { }); -promise = resource.$delete(); -promise = resource.$delete({ key: 'value' }); -promise = resource.$delete({ key: 'value' }, function () { }); -promise = resource.$delete(function () { }); -promise = resource.$delete(function () { }, function () { }); -promise = resource.$delete({ key: 'value' }, { key: 'value' }); -promise = resource.$delete({ key: 'value' }, { key: 'value' }, function () { }); -promise = resource.$delete({ key: 'value' }, { key: 'value' }, function () { }, function () { }); - resource = resourceClass.get(); resource = resourceClass.get({ key: 'value' }); resource = resourceClass.get({ key: 'value' }, function () { }); @@ -50,15 +39,6 @@ resource = resourceClass.get({ key: 'value' }, { key: 'value' }); resource = resourceClass.get({ key: 'value' }, { key: 'value' }, function () { }); resource = resourceClass.get({ key: 'value' }, { key: 'value' }, function () { }, function () { }); -promise = resource.$get(); -promise = resource.$get({ key: 'value' }); -promise = resource.$get({ key: 'value' }, function () { }); -promise = resource.$get(function () { }); -promise = resource.$get(function () { }, function () { }); -promise = resource.$get({ key: 'value' }, { key: 'value' }); -promise = resource.$get({ key: 'value' }, { key: 'value' }, function () { }); -promise = resource.$get({ key: 'value' }, { key: 'value' }, function () { }, function () { }); - resourceArray = resourceClass.query(); resourceArray = resourceClass.query({ key: 'value' }); resourceArray = resourceClass.query({ key: 'value' }, function () { }); @@ -67,15 +47,7 @@ resourceArray = resourceClass.query(function () { }, function () { }); resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }); resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }, function () { }); resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }, function () { }, function () { }); - -arrayPromise = resourceArray[0].query(); -arrayPromise = resourceArray[0].query({ key: 'value' }); -arrayPromise = resourceArray[0].query({ key: 'value' }, function () { }); -arrayPromise = resourceArray[0].query(function () { }); -arrayPromise = resourceArray[0].query(function () { }, function () { }); -arrayPromise = resourceArray[0].query({ key: 'value' }, { key: 'value' }); -arrayPromise = resourceArray[0].query({ key: 'value' }, { key: 'value' }, function () { }); -arrayPromise = resourceArray[0].query({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +resourceArray.push(resource); resource = resourceClass.remove(); resource = resourceClass.remove({ key: 'value' }); @@ -86,15 +58,6 @@ resource = resourceClass.remove({ key: 'value' }, { key: 'value' }); resource = resourceClass.remove({ key: 'value' }, { key: 'value' }, function () { }); resource = resourceClass.remove({ key: 'value' }, { key: 'value' }, function () { }, function () { }); -promise = resource.$remove(); -promise = resource.$remove({ key: 'value' }); -promise = resource.$remove({ key: 'value' }, function () { }); -promise = resource.$remove(function () { }); -promise = resource.$remove(function () { }, function () { }); -promise = resource.$remove({ key: 'value' }, { key: 'value' }); -promise = resource.$remove({ key: 'value' }, { key: 'value' }, function () { }); -promise = resource.$remove({ key: 'value' }, { key: 'value' }, function () { }, function () { }); - resource = resourceClass.save(); resource = resourceClass.save({ key: 'value' }); resource = resourceClass.save({ key: 'value' }, function () { }); @@ -104,6 +67,49 @@ resource = resourceClass.save({ key: 'value' }, { key: 'value' }); resource = resourceClass.save({ key: 'value' }, { key: 'value' }, function () { }); resource = resourceClass.save({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +/////////////////////////////////////// +// IResource +/////////////////////////////////////// + +var promise : ng.IPromise; +var arrayPromise : ng.IPromise; + +promise = resource.$delete(); +promise = resource.$delete({ key: 'value' }); +promise = resource.$delete({ key: 'value' }, function () { }); +promise = resource.$delete(function () { }); +promise = resource.$delete(function () { }, function () { }); +promise = resource.$delete({ key: 'value' }, { key: 'value' }); +promise = resource.$delete({ key: 'value' }, { key: 'value' }, function () { }); +promise = resource.$delete({ key: 'value' }, { key: 'value' }, function () { }, function () { }); + +promise = resource.$get(); +promise = resource.$get({ key: 'value' }); +promise = resource.$get({ key: 'value' }, function () { }); +promise = resource.$get(function () { }); +promise = resource.$get(function () { }, function () { }); +promise = resource.$get({ key: 'value' }, { key: 'value' }); +promise = resource.$get({ key: 'value' }, { key: 'value' }, function () { }); +promise = resource.$get({ key: 'value' }, { key: 'value' }, function () { }, function () { }); + +arrayPromise = resourceArray[0].$query(); +arrayPromise = resourceArray[0].$query({ key: 'value' }); +arrayPromise = resourceArray[0].$query({ key: 'value' }, function () { }); +arrayPromise = resourceArray[0].$query(function () { }); +arrayPromise = resourceArray[0].$query(function () { }, function () { }); +arrayPromise = resourceArray[0].$query({ key: 'value' }, { key: 'value' }); +arrayPromise = resourceArray[0].$query({ key: 'value' }, { key: 'value' }, function () { }); +arrayPromise = resourceArray[0].$query({ key: 'value' }, { key: 'value' }, function () { }, function () { }); + +promise = resource.$remove(); +promise = resource.$remove({ key: 'value' }); +promise = resource.$remove({ key: 'value' }, function () { }); +promise = resource.$remove(function () { }); +promise = resource.$remove(function () { }, function () { }); +promise = resource.$remove({ key: 'value' }, { key: 'value' }); +promise = resource.$remove({ key: 'value' }, { key: 'value' }, function () { }); +promise = resource.$remove({ key: 'value' }, { key: 'value' }, function () { }, function () { }); + promise = resource.$save(); promise = resource.$save({ key: 'value' }); promise = resource.$save({ key: 'value' }, function () { }); @@ -132,3 +138,7 @@ resourceClass = resourceServiceFactoryFunction(resourceService resourceServiceFactoryFunction = function (resourceService: ng.resource.IResourceService) { return resourceClass; }; mod = mod.factory('factory name', resourceServiceFactoryFunction); + +/////////////////////////////////////// +// IResource +/////////////////////////////////////// \ No newline at end of file diff --git a/angularjs/angular-resource.d.ts b/angularjs/angular-resource.d.ts index 942e5e120d..52706d68d2 100644 --- a/angularjs/angular-resource.d.ts +++ b/angularjs/angular-resource.d.ts @@ -1,6 +1,6 @@ // Type definitions for Angular JS 1.2 (ngResource module) // Project: http://angularjs.org -// Definitions by: Diego Vilar +// Definitions by: Diego Vilar , Michael Jess (minor enhancements) // Definitions: https://github.com/daptiv/DefinitelyTyped /// @@ -129,11 +129,12 @@ declare module ng.resource { $resolved : boolean; } - interface Array {} - - interface IResourceArray extends Array { + /** + * Really just a regular Array object with $promise and $resolve attached to it + */ + interface IResourceArray extends Array { /** the promise of the original server interaction that created this collection. **/ - $promise : ng.IPromise; + $promise : ng.IPromise; $resolved : boolean; } From fffce8af7d5cae04f62f0f6082f6e3d8adfbefb5 Mon Sep 17 00:00:00 2001 From: miffels Date: Tue, 8 Apr 2014 14:15:34 +0200 Subject: [PATCH 04/49] Simplifying instance API and adding some explanatory comments --- angularjs/angular-resource-tests.ts | 20 +++--------- angularjs/angular-resource.d.ts | 50 ++++++++++++----------------- 2 files changed, 25 insertions(+), 45 deletions(-) diff --git a/angularjs/angular-resource-tests.ts b/angularjs/angular-resource-tests.ts index 327fcaba6e..107d6b29e0 100644 --- a/angularjs/angular-resource-tests.ts +++ b/angularjs/angular-resource-tests.ts @@ -79,45 +79,35 @@ promise = resource.$delete({ key: 'value' }); promise = resource.$delete({ key: 'value' }, function () { }); promise = resource.$delete(function () { }); promise = resource.$delete(function () { }, function () { }); -promise = resource.$delete({ key: 'value' }, { key: 'value' }); -promise = resource.$delete({ key: 'value' }, { key: 'value' }, function () { }); -promise = resource.$delete({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +promise = resource.$delete({ key: 'value' }, function () { }, function () { }); promise = resource.$get(); promise = resource.$get({ key: 'value' }); promise = resource.$get({ key: 'value' }, function () { }); promise = resource.$get(function () { }); promise = resource.$get(function () { }, function () { }); -promise = resource.$get({ key: 'value' }, { key: 'value' }); -promise = resource.$get({ key: 'value' }, { key: 'value' }, function () { }); -promise = resource.$get({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +promise = resource.$get({ key: 'value' }, function () { }, function () { }); arrayPromise = resourceArray[0].$query(); arrayPromise = resourceArray[0].$query({ key: 'value' }); arrayPromise = resourceArray[0].$query({ key: 'value' }, function () { }); arrayPromise = resourceArray[0].$query(function () { }); arrayPromise = resourceArray[0].$query(function () { }, function () { }); -arrayPromise = resourceArray[0].$query({ key: 'value' }, { key: 'value' }); -arrayPromise = resourceArray[0].$query({ key: 'value' }, { key: 'value' }, function () { }); -arrayPromise = resourceArray[0].$query({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +arrayPromise = resourceArray[0].$query({ key: 'value' }, function () { }, function () { }); promise = resource.$remove(); promise = resource.$remove({ key: 'value' }); promise = resource.$remove({ key: 'value' }, function () { }); promise = resource.$remove(function () { }); promise = resource.$remove(function () { }, function () { }); -promise = resource.$remove({ key: 'value' }, { key: 'value' }); -promise = resource.$remove({ key: 'value' }, { key: 'value' }, function () { }); -promise = resource.$remove({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +promise = resource.$remove({ key: 'value' }, function () { }, function () { }); promise = resource.$save(); promise = resource.$save({ key: 'value' }); promise = resource.$save({ key: 'value' }, function () { }); promise = resource.$save(function () { }); promise = resource.$save(function () { }, function () { }); -promise = resource.$save({ key: 'value' }, { key: 'value' }); -promise = resource.$save({ key: 'value' }, { key: 'value' }, function () { }); -promise = resource.$save({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +promise = resource.$save({ key: 'value' }, function () { }, function () { }); /////////////////////////////////////// // IResourceService diff --git a/angularjs/angular-resource.d.ts b/angularjs/angular-resource.d.ts index 52706d68d2..393362a95e 100644 --- a/angularjs/angular-resource.d.ts +++ b/angularjs/angular-resource.d.ts @@ -50,79 +50,69 @@ declare module ng.resource { // PATCH (in other words, methods with body). Otherwise, it's going // to be considered as parameters to the request. // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L461-L465 + // + // Only those methods with an HTTP body do have 'data' as first parameter: + // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L463 + // More specifically, those methods are POST, PUT and PATCH: + // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L432 + // + // Also, static calls always return the IResource (or IResourceArray) retrieved + // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L538-L549 interface IResourceClass { new(dataOrParams? : any) : T; get(): T; get(params: Object): T; get(success: Function, error?: Function): T; get(params: Object, success: Function, error?: Function): T; - get(params: Object, data: Object, success?: Function): T; - get(params: Object, data: Object, success: Function, error?: Function): T; + get(params: Object, data: Object, success?: Function, error?: Function): T; query(): IResourceArray; query(params: Object): IResourceArray; query(success: Function, error?: Function): IResourceArray; query(params: Object, success: Function, error?: Function): IResourceArray; - query(params: Object, data: Object, success?: Function): IResourceArray; - query(params: Object, data: Object, success: Function, error?: Function): IResourceArray; + query(params: Object, data: Object, success?: Function, error?: Function): IResourceArray; save(): T; save(data: Object): T; save(success: Function, error?: Function): T; save(data: Object, success: Function, error?: Function): T; - save(params: Object, data: Object, success?: Function): T; - save(params: Object, data: Object, success: Function, error?: Function): T; + save(params: Object, data: Object, success?: Function, error?: Function): T; remove(): T; remove(params: Object): T; remove(success: Function, error?: Function): T; remove(params: Object, success: Function, error?: Function): T; - remove(params: Object, data: Object, success?: Function): T; - remove(params: Object, data: Object, success: Function, error?: Function): T; + remove(params: Object, data: Object, success?: Function, error?: Function): T; delete(): T; delete(params: Object): T; delete(success: Function, error?: Function): T; delete(params: Object, success: Function, error?: Function): T; - delete(params: Object, data: Object, success?: Function): T; - delete(params: Object, data: Object, success: Function, error?: Function): T; + delete(params: Object, data: Object, success?: Function, error?: Function): T; } + // Instance calls always return the the promise of the request which retrieved the object + // https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L538-L546 interface IResource { $get(): ng.IPromise; - $get(params: Object): ng.IPromise; + $get(params?: Object, success?: Function, error?: Function): ng.IPromise; $get(success: Function, error?: Function): ng.IPromise; - $get(params: Object, success: Function, error?: Function): ng.IPromise; - $get(params: Object, data: Object, success?: Function): ng.IPromise; - $get(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; $query(): ng.IPromise; - $query(params: Object): ng.IPromise; + $query(params?: Object, success?: Function, error?: Function): ng.IPromise; $query(success: Function, error?: Function): ng.IPromise; - $query(params: Object, success: Function, error?: Function): ng.IPromise; - $query(params: Object, data: Object, success?: Function): ng.IPromise; - $query(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; $save(): ng.IPromise; - $save(data: Object): ng.IPromise; + $save(params?: Object, success?: Function, error?: Function): ng.IPromise; $save(success: Function, error?: Function): ng.IPromise; - $save(data: Object, success: Function, error?: Function): ng.IPromise; - $save(params: Object, data: Object, success?: Function): ng.IPromise; - $save(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; $remove(): ng.IPromise; - $remove(params: Object): ng.IPromise; + $remove(params?: Object, success?: Function, error?: Function): ng.IPromise; $remove(success: Function, error?: Function): ng.IPromise; - $remove(params: Object, success: Function, error?: Function): ng.IPromise; - $remove(params: Object, data: Object, success?: Function): ng.IPromise; - $remove(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; $delete(): ng.IPromise; - $delete(params: Object): ng.IPromise; + $delete(params?: Object, success?: Function, error?: Function): ng.IPromise; $delete(success: Function, error?: Function): ng.IPromise; - $delete(params: Object, success: Function, error?: Function): ng.IPromise; - $delete(params: Object, data: Object, success?: Function): ng.IPromise; - $delete(params: Object, data: Object, success: Function, error?: Function): ng.IPromise; /** the promise of the original server interaction that created this instance. **/ $promise : ng.IPromise; From 1efaca22797fc58df97aad212de755730ae07203 Mon Sep 17 00:00:00 2001 From: miffels Date: Tue, 8 Apr 2014 19:47:20 +0200 Subject: [PATCH 05/49] Fixing array call promise inconsistency (thanks @jackdolabany) and adding tests --- angularjs/angular-resource-tests.ts | 4 ++++ angularjs/angular-resource.d.ts | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/angularjs/angular-resource-tests.ts b/angularjs/angular-resource-tests.ts index 107d6b29e0..c80cc662de 100644 --- a/angularjs/angular-resource-tests.ts +++ b/angularjs/angular-resource-tests.ts @@ -29,6 +29,7 @@ resource = resourceClass.delete(function () { }, function () { }); resource = resourceClass.delete({ key: 'value' }, { key: 'value' }); resource = resourceClass.delete({ key: 'value' }, { key: 'value' }, function () { }); resource = resourceClass.delete({ key: 'value' }, { key: 'value' }, function () { }, function () { }); +resource.$promise.then(function(data: IMyResource) {}); resource = resourceClass.get(); resource = resourceClass.get({ key: 'value' }); @@ -48,6 +49,7 @@ resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }); resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }, function () { }); resourceArray = resourceClass.query({ key: 'value' }, { key: 'value' }, function () { }, function () { }); resourceArray.push(resource); +resourceArray.$promise.then(function(data: ng.resource.IResourceArray) {}); resource = resourceClass.remove(); resource = resourceClass.remove({ key: 'value' }); @@ -80,6 +82,7 @@ promise = resource.$delete({ key: 'value' }, function () { }); promise = resource.$delete(function () { }); promise = resource.$delete(function () { }, function () { }); promise = resource.$delete({ key: 'value' }, function () { }, function () { }); +promise.then(function(data: IMyResource) {}); promise = resource.$get(); promise = resource.$get({ key: 'value' }); @@ -94,6 +97,7 @@ arrayPromise = resourceArray[0].$query({ key: 'value' }, function () { }); arrayPromise = resourceArray[0].$query(function () { }); arrayPromise = resourceArray[0].$query(function () { }, function () { }); arrayPromise = resourceArray[0].$query({ key: 'value' }, function () { }, function () { }); +arrayPromise.then(function(data: ng.resource.IResourceArray) {}); promise = resource.$remove(); promise = resource.$remove({ key: 'value' }); diff --git a/angularjs/angular-resource.d.ts b/angularjs/angular-resource.d.ts index 393362a95e..51b93091fa 100644 --- a/angularjs/angular-resource.d.ts +++ b/angularjs/angular-resource.d.ts @@ -98,9 +98,9 @@ declare module ng.resource { $get(params?: Object, success?: Function, error?: Function): ng.IPromise; $get(success: Function, error?: Function): ng.IPromise; - $query(): ng.IPromise; - $query(params?: Object, success?: Function, error?: Function): ng.IPromise; - $query(success: Function, error?: Function): ng.IPromise; + $query(): ng.IPromise>; + $query(params?: Object, success?: Function, error?: Function): ng.IPromise>; + $query(success: Function, error?: Function): ng.IPromise>; $save(): ng.IPromise; $save(params?: Object, success?: Function, error?: Function): ng.IPromise; @@ -124,7 +124,7 @@ declare module ng.resource { */ interface IResourceArray extends Array { /** the promise of the original server interaction that created this collection. **/ - $promise : ng.IPromise; + $promise : ng.IPromise>; $resolved : boolean; } From d9539f82c479ecb68987724159a8332ae7ce3a2b Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Tue, 15 Apr 2014 15:12:23 -0400 Subject: [PATCH 06/49] Reduce text differences with the old version (Visual Studio being mean!) --- lodash/lodash-tests.disabled.ts | 588 ++++++++++++++++---------------- lodash/lodash.d.ts | 14 +- 2 files changed, 301 insertions(+), 301 deletions(-) diff --git a/lodash/lodash-tests.disabled.ts b/lodash/lodash-tests.disabled.ts index 97c2709405..de96b3d978 100644 --- a/lodash/lodash-tests.disabled.ts +++ b/lodash/lodash-tests.disabled.ts @@ -41,16 +41,16 @@ interface IKey { var foodsOrganic: IFoodOrganic[] = [ { name: 'banana', organic: true }, - { name: 'beet', organic: false }, + { name: 'beet', organic: false }, ]; var foodsType: IFoodType[] = [ - { name: 'apple', type: 'fruit' }, + { name: 'apple', type: 'fruit' }, { name: 'banana', type: 'fruit' }, - { name: 'beet', type: 'vegetable' } + { name: 'beet', type: 'vegetable' } ]; var foodsCombined: IFoodCombined[] = [ - { 'name': 'apple', 'organic': false, 'type': 'fruit' }, - { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } + { 'name': 'apple', 'organic': false, 'type': 'fruit' }, + { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } ]; var stoogesQuotes: IStoogesQuote[] = [ @@ -63,24 +63,24 @@ var stoogesAges: IStoogesAge[] = [ ]; var stoogesCombined: IStoogesCombined[] = [ - { 'name': 'curly', 'age': 30, 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, - { 'name': 'moe', 'age': 40, 'quotes': ['Spread out!', 'You knucklehead!'] } + { 'name': 'curly', 'age': 30, 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, + { 'name': 'moe', 'age': 40, 'quotes': ['Spread out!', 'You knucklehead!'] } ]; var keys: IKey[] = [ - { 'dir': 'left', 'code': 97 }, - { 'dir': 'right', 'code': 100 } + { 'dir': 'left', 'code': 97 }, + { 'dir': 'right', 'code': 100 } ]; class Dog { - constructor(public name: string) { } + constructor(public name: string) {} public bark() { - console.log('Woof, woof!'); + console.log('Woof, woof!'); } } -var result: any; +var result : any; /************* * Chaining * @@ -119,14 +119,14 @@ result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).splice(1); result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).splice(1, 2, 5, 6); result = <_.LoDashWrapper>_([1, 2, 3, 4]).unshift(5, 6); -result = _.tap([1, 2, 3, 4], function (array) { console.log(array); }); -result = <_.LoDashWrapper>_('test').tap(function (value) { console.log(value); }); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).tap(function (array) { console.log(array); }); +result = _.tap([1, 2, 3, 4], function(array) { console.log(array); }); +result = <_.LoDashWrapper>_('test').tap(function(value) { console.log(value); }); +result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).tap(function(array) { console.log(array); }); result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).tap(function (array) { console.log(array); }); result = _('test').toString(); result = _([1, 2, 3]).toString(); -result = _({ 'key1': 'test1', 'key2': 'test2' }).toString(); +result = _({'key1': 'test1', 'key2': 'test2'}).toString(); result = _('test').valueOf(); result = _([1, 2, 3]).valueOf(); @@ -140,10 +140,10 @@ result = <_.Dictionary>_(<{ [index: string]: string; }>{ 'key1': 'test1' // * Arrays * // *************/ result = _.compact([0, 1, false, 2, '', 3]); -result = <_.LoDashArrayWrapper>_([0, 1, false, 2, '', 3]).compact(); + result = <_.LoDashArrayWrapper>_([0, 1, false, 2, '', 3]).compact(); result = _.difference([1, 2, 3, 4, 5], [5, 2, 10]); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4, 5]).difference([5, 2, 10]); + result = <_.LoDashArrayWrapper>_([1, 2, 3, 4, 5]).difference([5, 2, 10]); result = _.rest([1, 2, 3]); result = _.rest([1, 2, 3], 2); @@ -163,48 +163,48 @@ result = _.tail([1, 2, 3], (num) => num < 3) result = _.tail(foodsOrganic, 'test') result = _.tail(foodsType, { 'type': 'value' }) -result = _.findIndex(['apple', 'banana', 'beet'], function (f) { - return /^b/.test(f); +result = _.findIndex(['apple', 'banana', 'beet'], function(f) { + return /^b/.test(f); }); result = _.findIndex(['apple', 'banana', 'beet'], 'apple'); -result = _.findIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple' }); +result = _.findIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple'}); -result = _.findLastIndex(['apple', 'banana', 'beet'], function (f: string) { - return /^b/.test(f); +result = _.findLastIndex(['apple', 'banana', 'beet'], function(f: string) { + return /^b/.test(f); }); result = _.findLastIndex(['apple', 'banana', 'beet'], 'apple'); -result = _.findLastIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple' }); +result = _.findLastIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple'}); result = _.first([1, 2, 3]); result = _.first([1, 2, 3], 2); -result = _.first([1, 2, 3], function (num) { - return num < 3; +result = _.first([1, 2, 3], function(num) { + return num < 3; }); result = _.first(foodsOrganic, 'organic'); result = _.first(foodsType, { 'type': 'fruit' }); -result = _.head([1, 2, 3]); -result = _.head([1, 2, 3], 2); -result = _.head([1, 2, 3], function (num) { - return num < 3; -}); -result = _.head(foodsOrganic, 'organic'); -result = _.head(foodsType, { 'type': 'fruit' }); + result = _.head([1, 2, 3]); + result = _.head([1, 2, 3], 2); + result = _.head([1, 2, 3], function(num) { + return num < 3; + }); + result = _.head(foodsOrganic, 'organic'); + result = _.head(foodsType, { 'type': 'fruit' }); -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 = _.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 = _.flatten([1, [2], [3, [[4]]]]); result = _.flatten([1, [2], [3, [[4]]]], true); var result: any result = _.flatten(stoogesQuotes, 'quotes'); -result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(); -result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(true); -result = <_.LoDashArrayWrapper>_(stoogesQuotes).flatten('quotes'); + result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(); + result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(true); + result = <_.LoDashArrayWrapper>_(stoogesQuotes).flatten('quotes'); result = _.indexOf([1, 2, 3, 1, 2, 3], 2); result = _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); @@ -212,8 +212,8 @@ result = _.indexOf([1, 1, 2, 2, 3, 3], 2, true); result = _.initial([1, 2, 3]); result = _.initial([1, 2, 3], 2); -result = _.initial([1, 2, 3], function (num) { - return num > 1; +result = _.initial([1, 2, 3], function(num) { + return num > 1; }); result = _.initial(foodsOrganic, 'organic'); result = _.initial(foodsType, { 'type': 'vegetable' }); @@ -222,8 +222,8 @@ result = _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); result = _.last([1, 2, 3]); result = _.last([1, 2, 3], 2); -result = _.last([1, 2, 3], function (num) { - return num > 1; +result = _.last([1, 2, 3], function(num) { + return num > 1; }); result = _.last(foodsOrganic, 'organic'); result = _.last(foodsType, { 'type': 'vegetable' }); @@ -231,8 +231,8 @@ result = _.last(foodsType, { 'type': 'vegetable' }); result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); -result = <{ [key: string]: any }>_.zipObject(['moe', 'larry'], [30, 40]); -result = <{ [key: string]: any }>_.object(['moe', 'larry'], [30, 40]); +result = <{[key: string]: any}>_.zipObject(['moe', 'larry'], [30, 40]); +result = <{[key: string]: any}>_.object(['moe', 'larry'], [30, 40]); result = _.pull([1, 2, 3, 1, 2, 3], 2, 3); @@ -243,39 +243,39 @@ result = _.range(0, -10, -1); result = _.range(1, 4, 0); result = _.range(0); -result = _.remove([1, 2, 3, 4, 5, 6], function (num: number) { return num % 2 == 0; }); +result = _.remove([1, 2, 3, 4, 5, 6], function(num: number) { return num % 2 == 0; }); result = _.remove(foodsOrganic, 'organic'); -result = _.remove(foodsType, { 'type': 'vegetable' }); +result = _.remove(foodsType, { 'type': 'vegetable'}); result = _.sortedIndex([20, 30, 50], 40); result = _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); var sortedIndexDict = { - 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } + 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } }; -result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word) { - return sortedIndexDict.wordToNumber[word]; +result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { + return sortedIndexDict.wordToNumber[word]; }); -result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word) { - return this.wordToNumber[word]; +result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { + return this.wordToNumber[word]; }, sortedIndexDict); result = _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); 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) { - return letter.toLowerCase(); +result = _.uniq(['A', 'b', 'C', 'a', 'B', 'c'], function(letter) { + return letter.toLowerCase(); }); -result = _.uniq([1, 2.5, 3, 1.5, 2, 3.5], function (num) { return this.floor(num); }, Math); -result = <{ x: number; }[]>_.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); +result = _.uniq([1, 2.5, 3, 1.5, 2, 3.5], function(num) { return this.floor(num); }, Math); +result = <{x: number;}[]>_.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); -result = _.unique([1, 2, 1, 3, 1]); -result = _.unique([1, 1, 2, 2, 3], true); -result = _.unique(['A', 'b', 'C', 'a', 'B', 'c'], function (letter) { - return letter.toLowerCase(); -}); -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 = _.unique([1, 2, 1, 3, 1]); + result = _.unique([1, 1, 2, 2, 3], true); + result = _.unique(['A', 'b', 'C', 'a', 'B', 'c'], function(letter) { + return letter.toLowerCase(); + }); + 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 = _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); @@ -294,13 +294,13 @@ result = _.contains([1, 2, 3], 1, 2); result = _.contains({ 'name': 'moe', 'age': 40 }, 'moe'); result = _.contains('curly', 'ur'); -result = _.include([1, 2, 3], 1); -result = _.include([1, 2, 3], 1, 2); -result = _.include({ 'name': 'moe', 'age': 40 }, 'moe'); -result = _.include('curly', 'ur'); + result = _.include([1, 2, 3], 1); + result = _.include([1, 2, 3], 1, 2); + result = _.include({ 'name': 'moe', 'age': 40 }, 'moe'); + result = _.include('curly', 'ur'); -result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return Math.floor(num); }); -result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return this.floor(num); }, Math); +result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); +result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); result = <_.Dictionary>_.countBy(['one', 'two', 'three'], 'length'); result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function (num) { return Math.floor(num); }); @@ -311,55 +311,55 @@ result = _.every([true, 1, null, 'yes'], Boolean); result = _.every(stoogesAges, 'age'); result = _.every(stoogesAges, { 'age': 50 }); -result = _.all([true, 1, null, 'yes'], Boolean); -result = _.all(stoogesAges, 'age'); -result = _.all(stoogesAges, { 'age': 50 }); + result = _.all([true, 1, null, 'yes'], Boolean); + result = _.all(stoogesAges, 'age'); + result = _.all(stoogesAges, { 'age': 50 }); -result = _.filter([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); +result = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); result = _.filter(foodsCombined, 'organic'); result = _.filter(foodsCombined, { 'type': 'fruit' }); -result = _([1, 2, 3, 4, 5, 6]).filter(function (num) { return num % 2 == 0; }).value(); -result = _(foodsCombined).filter('organic').value(); -result = _(foodsCombined).filter({ 'type': 'fruit' }).value(); + result = _([1, 2, 3, 4, 5, 6]).filter(function(num) { return num % 2 == 0; }).value(); + result = _(foodsCombined).filter('organic').value(); + result = _(foodsCombined).filter({ 'type': 'fruit' }).value(); -result = _.select([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); -result = _.select(foodsCombined, 'organic'); -result = _.select(foodsCombined, { 'type': 'fruit' }); + result = _.select([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); + result = _.select(foodsCombined, 'organic'); + result = _.select(foodsCombined, { 'type': 'fruit' }); -result = _([1, 2, 3, 4, 5, 6]).select(function (num) { return num % 2 == 0; }).value(); -result = _(foodsCombined).select('organic').value(); -result = _(foodsCombined).select({ 'type': 'fruit' }).value(); + result = _([1, 2, 3, 4, 5, 6]).select(function(num) { return num % 2 == 0; }).value(); + result = _(foodsCombined).select('organic').value(); + result = _(foodsCombined).select({ 'type': 'fruit' }).value(); -result = _.find([1, 2, 3, 4], function (num) { - return num % 2 == 0; +result = _.find([1, 2, 3, 4], function(num) { + return num % 2 == 0; }); result = _.find(foodsCombined, { 'type': 'vegetable' }); result = _.find(foodsCombined, 'organic'); -result = _.detect([1, 2, 3, 4], function (num) { - return num % 2 == 0; -}); -result = _.detect(foodsCombined, { 'type': 'vegetable' }); -result = _.detect(foodsCombined, 'organic'); + result = _.detect([1, 2, 3, 4], function(num) { + return num % 2 == 0; + }); + result = _.detect(foodsCombined, { 'type': 'vegetable' }); + result = _.detect(foodsCombined, 'organic'); -result = _.findWhere([1, 2, 3, 4], function (num) { - return num % 2 == 0; -}); -result = _.findWhere(foodsCombined, { 'type': 'vegetable' }); -result = _.findWhere(foodsCombined, 'organic'); + result = _.findWhere([1, 2, 3, 4], function(num) { + return num % 2 == 0; + }); + result = _.findWhere(foodsCombined, { 'type': 'vegetable' }); + result = _.findWhere(foodsCombined, 'organic'); -result = _.findLast([1, 2, 3, 4], function (num) { - return num % 2 == 0; +result = _.findLast([1, 2, 3, 4], function(num) { + return num % 2 == 0; }); result = _.findLast(foodsCombined, { 'type': 'vegetable' }); 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([1, 2, 3], function(num) { console.log(num); }); +result = <_.Dictionary>_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); }); -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([1, 2, 3], function(num) { console.log(num); }); + result = <_.Dictionary>_.each({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); }); 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); }); @@ -367,11 +367,11 @@ result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: numb result = <_.LoDashArrayWrapper>_([1, 2, 3]).each(function (num) { console.log(num); }); result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).each(function (num) { console.log(num); }); -result = _.forEachRight([1, 2, 3], function (num) { console.log(num); }); -result = <_.Dictionary>_.forEachRight({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); +result = _.forEachRight([1, 2, 3], function(num) { console.log(num); }); +result = <_.Dictionary>_.forEachRight({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); }); -result = _.eachRight([1, 2, 3], function (num) { console.log(num); }); -result = <_.Dictionary>_.eachRight({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); }); + result = _.eachRight([1, 2, 3], function(num) { console.log(num); }); + result = <_.Dictionary>_.eachRight({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); }); result = <_.LoDashArrayWrapper>_([1, 2, 3]).forEachRight(function (num) { console.log(num); }); result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).forEachRight(function (num) { console.log(num); }); @@ -379,80 +379,80 @@ result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: numb result = <_.LoDashArrayWrapper>_([1, 2, 3]).eachRight(function (num) { console.log(num); }); result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).eachRight(function (num) { console.log(num); }); -result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function (num) { return Math.floor(num); }); -result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function (num) { return this.floor(num); }, Math); +result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); +result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); result = <_.Dictionary>_.groupBy(['one', 'two', 'three'], 'length'); -result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function (num) { return Math.floor(num); }); -result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function (num) { return this.floor(num); }, Math); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).groupBy('length'); + result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function(num) { return Math.floor(num); }); + result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function(num) { return this.floor(num); }, Math); + result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).groupBy('length'); result = <_.Dictionary>_.indexBy(keys, 'dir'); -result = <_.Dictionary>_.indexBy(keys, function (key) { return String.fromCharCode(key.code); }); -result = <_.Dictionary>_.indexBy(keys, function (key) { this.fromCharCode(key.code); }, String); +result = <_.Dictionary>_.indexBy(keys, function(key) { return String.fromCharCode(key.code); }); +result = <_.Dictionary>_.indexBy(keys, function(key) { this.fromCharCode(key.code); }, String); result = _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); result = _.invoke([123, 456], String.prototype.split, ''); -result = _.map([1, 2, 3], function (num) { return num * 3; }); -result = _.map({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { return num * 3; }); +result = _.map([1, 2, 3], function(num) { return num * 3; }); +result = _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); result = _.map(stoogesAges, 'name'); -result = _([1, 2, 3]).map(function (num) { return num * 3; }).value(); -result = _({ 'one': 1, 'two': 2, 'three': 3 }).map(function (num) { return num * 3; }).value(); -result = _(stoogesAges).map('name').value(); + result = _([1, 2, 3]).map(function(num) { return num * 3; }).value(); + result = _({ 'one': 1, 'two': 2, 'three': 3 }).map(function(num) { return num * 3; }).value(); + result = _(stoogesAges).map('name').value(); -result = _.collect([1, 2, 3], function (num) { return num * 3; }); -result = _.collect({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { return num * 3; }); +result = _.collect([1, 2, 3], function(num) { return num * 3; }); +result = _.collect({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); result = _.collect(stoogesAges, 'name'); -result = _([1, 2, 3]).collect(function (num) { return num * 3; }).value(); -result = _({ 'one': 1, 'two': 2, 'three': 3 }).collect(function (num) { return num * 3; }).value(); -result = _(stoogesAges).collect('name').value(); + result = _([1, 2, 3]).collect(function(num) { return num * 3; }).value(); + result = _({ 'one': 1, 'two': 2, 'three': 3 }).collect(function(num) { return num * 3; }).value(); + result = _(stoogesAges).collect('name').value(); result = _.max([4, 2, 8, 6]); -result = _.max(stoogesAges, function (stooge) { return stooge.age; }); +result = _.max(stoogesAges, function(stooge) { return stooge.age; }); result = _.max(stoogesAges, 'age'); result = _.min([4, 2, 8, 6]); -result = _.min(stoogesAges, function (stooge) { return stooge.age; }); +result = _.min(stoogesAges, function(stooge) { return stooge.age; }); result = _.min(stoogesAges, 'age'); result = _.pluck(stoogesAges, 'name'); -result = _.reduce([1, 2, 3], function (sum: number, num: number) { - return sum + num; +result = _.reduce([1, 2, 3], function(sum: number, num: number) { + return sum + num; }); interface ABC { - a: number; - b: number; - c: number; + a: number; + b: number; + c: number; } -result = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num, key) { - r[key] = num * 3; - return r; +result = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(r: ABC, num, key) { + r[key] = num * 3; + return r; }, {}); -result = _.foldl([1, 2, 3], function (sum, num) { - return sum + num; +result = _.foldl([1, 2, 3], function(sum, num) { + return sum + num; }); -result = _.foldl({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num, key) { - r[key] = num * 3; - return r; +result = _.foldl({ 'a': 1, 'b': 2, 'c': 3 }, function(r: ABC, num, key) { + r[key] = num * 3; + return r; }, {}); -result = _.inject([1, 2, 3], function (sum, num) { - return sum + num; +result = _.inject([1, 2, 3], function(sum, num) { + return sum + num; }); -result = _.inject({ 'a': 1, 'b': 2, 'c': 3 }, function (r: ABC, num, key) { - r[key] = num * 3; - return r; +result = _.inject({ 'a': 1, 'b': 2, 'c': 3 }, function(r: ABC, num, key) { + 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); }, []); +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); }, []); -result = _.reject([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); +result = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); result = _.reject(foodsCombined, 'organic'); result = _.reject(foodsCombined, { 'type': 'fruit' }); @@ -473,11 +473,11 @@ result = _.any([null, 0, 'yes', false], Boolean); result = _.any(foodsCombined, 'organic'); result = _.any(foodsCombined, { 'type': 'meat' }); -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([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'); -(function (a: number, b: number, c: number, d: number) { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); +(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!'] }); @@ -489,20 +489,20 @@ var saves = ['profile', 'settings']; var asyncSave = (obj: any) => obj.done(); var done: Function; -done = _.after(saves.length, function () { - console.log('Done saving!'); +done = _.after(saves.length, function() { + console.log('Done saving!'); }); -_.forEach(saves, function (type) { - asyncSave({ 'type': type, 'complete': done }); +_.forEach(saves, function(type) { + asyncSave({ 'type': type, 'complete': done }); }); -done = _(saves.length).after(function () { - console.log('Done saving!'); +done = _(saves.length).after(function() { + console.log('Done saving!'); }).value(); -_.forEach(saves, function (type) { - asyncSave({ 'type': type, 'complete': done }); +_.forEach(saves, function(type) { + asyncSave({ 'type': type, 'complete': done }); }); var funcBind = function (greeting: string) { return greeting + ' ' + this.name }; @@ -513,8 +513,8 @@ var funcBind3: () => any = _(funcBind).bind({ 'name': 'moe' }, 'hi').value(); funcBind3(); var view = { - 'label': 'docs', - 'onClick': function () { console.log('clicked ' + this.label); } + 'label': 'docs', + 'onClick': function() { console.log('clicked ' + this.label); } }; view = _.bindAll(view); @@ -524,17 +524,17 @@ view = _(view).bindAll().value(); jQuery('#docs').on('click', view.onClick); var objectBindKey = { - 'name': 'moe', - 'greet': function (greeting: string) { - return greeting + ' ' + this.name; - } + 'name': 'moe', + 'greet': function(greeting: string) { + return greeting + ' ' + this.name; + } }; var funcBindKey: Function = _.bindKey(objectBindKey, 'greet', 'hi'); funcBindKey(); -objectBindKey.greet = function (greeting) { - return greeting + ', ' + this.name + '!'; +objectBindKey.greet = function(greeting) { + return greeting + ', ' + this.name + '!'; }; funcBindKey(); @@ -543,16 +543,16 @@ funcBindKey = _(objectBindKey).bindKey('greet', 'hi').value(); funcBindKey(); var realNameMap = { - 'curly': 'jerome' + 'curly': 'jerome' }; -var format = function (name: string) { - name = realNameMap[name.toLowerCase()] || name; - return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase(); +var format = function(name: string) { + name = realNameMap[name.toLowerCase()] || name; + return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase(); }; -var greet = function (formatted: string) { - return 'Hiya ' + formatted + '!'; +var greet = function(formatted: string) { + return 'Hiya ' + formatted + '!'; }; result = _.compose(greet, format); @@ -564,57 +564,57 @@ result = <() => boolean>_.createCallback(createCallbackObj); result = <_.LoDashObjectWrapper<() => any>>_('name').createCallback(); result = <_.LoDashObjectWrapper<() => boolean>>_(createCallbackObj).createCallback(); -result = _.curry(function (a, b, c) { - console.log(a + b + c); +result = _.curry(function(a, b, c) { + console.log(a + b + c); }); -result = <_.LoDashObjectWrapper>_(function (a, b, c) { - console.log(a + b + c); +result = <_.LoDashObjectWrapper>_(function(a, b, c) { + console.log(a + b + c); }).curry(); declare var source: any; -result = _.debounce(function () { }, 150); +result = _.debounce(function() {}, 150); -jQuery('#postbox').on('click', _.debounce(function () { }, 300, { - 'leading': true, - 'trailing': false +jQuery('#postbox').on('click', _.debounce(function() {}, 300, { + 'leading': true, + 'trailing': false })); -source.addEventListener('message', _.debounce(function () { }, 250, { - 'maxWait': 1000 +source.addEventListener('message', _.debounce(function() {}, 250, { + 'maxWait': 1000 }), false); -result = <_.LoDashObjectWrapper>_(function () { }).debounce(150); +result = <_.LoDashObjectWrapper>_(function() {}).debounce(150); -jQuery('#postbox').on('click', <_.LoDashObjectWrapper>_(function () { }).debounce(300, { - 'leading': true, - 'trailing': false +jQuery('#postbox').on('click', <_.LoDashObjectWrapper>_(function() {}).debounce(300, { + 'leading': true, + 'trailing': false })); -source.addEventListener('message', <_.LoDashObjectWrapper>_(function () { }).debounce(250, { - 'maxWait': 1000 +source.addEventListener('message', <_.LoDashObjectWrapper>_(function() {}).debounce(250, { + 'maxWait': 1000 }), false); var returnedDebounce = _.throttle(function (a) { return a * 5; }, 5); returnedThrottled(4); -result = _.defer(function () { console.log('deferred'); }); -result = <_.LoDashWrapper>_(function () { console.log('deferred'); }).defer(); +result = _.defer(function() { console.log('deferred'); }); +result = <_.LoDashWrapper>_(function() { console.log('deferred'); }).defer(); var log = _.bind(console.log, console); result = _.delay(log, 1000, 'logged later'); result = <_.LoDashWrapper>_(log).delay(1000, 'logged later'); -var fibonacci = _.memoize(function (n) { - return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); +var fibonacci = _.memoize(function(n) { + return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); }); var data = { - 'moe': { 'name': 'moe', 'age': 40 }, - 'curly': { 'name': 'curly', 'age': 60 } + 'moe': { 'name': 'moe', 'age': 40 }, + 'curly': { 'name': 'curly', 'age': 60 } }; -var stooge = _.memoize(function (name: string) { return data[name]; }, _.identity); +var stooge = _.memoize(function(name: string) { return data[name]; }, _.identity); stooge('curly'); stooge['cache']['curly'].name = 'jerome'; @@ -623,21 +623,21 @@ stooge('curly'); var returnedMemoize = _.throttle(function (a) { return a * 5; }, 5); returnedMemoize(4); -var initialize = _.once(function () { }); +var initialize = _.once(function(){ }); initialize(); initialize();'' var returnedOnce = _.throttle(function (a) { return a * 5; }, 5); returnedOnce(4); -var greetPartial = function (greeting: string, name: string) { return greeting + ' ' + name; }; +var greetPartial = function(greeting: string, name: string) { return greeting + ' ' + name; }; var hi = _.partial(greetPartial, 'hi'); hi('moe'); var defaultsDeep = _.partialRight(_.merge, _.defaults); var optionsPartialRight = { - 'variable': 'data', - 'imports': { 'jq': $ } + 'variable': 'data', + 'imports': { 'jq': $ } }; defaultsDeep(optionsPartialRight, _.templateSettings); @@ -645,16 +645,16 @@ defaultsDeep(optionsPartialRight, _.templateSettings); var throttled = _.throttle(function () { }, 100); jQuery(window).on('scroll', throttled); -jQuery('.interactive').on('click', _.throttle(function () { }, 300000, { - 'trailing': false +jQuery('.interactive').on('click', _.throttle(function() { }, 300000, { + 'trailing': false })); -var returnedThrottled = _.throttle(function (a) { return a * 5; }, 5); +var returnedThrottled = _.throttle(function (a) { return a*5; }, 5); returnedThrottled(4); -var helloWrap = function (name: string) { return 'hello ' + name; }; -var helloWrap2 = _.wrap(helloWrap, function (func) { - return 'before, ' + func('moe') + ', after'; +var helloWrap = function(name: string) { return 'hello ' + name; }; +var helloWrap2 = _.wrap(helloWrap, function(func) { + return 'before, ' + func('moe') + ', after'; }); helloWrap2(); @@ -662,93 +662,93 @@ helloWrap2(); * Objects * ***********/ interface NameAge { - name: string; - age: number; + name: string; + age: number; } result = _.assign({ 'name': 'moe' }, { 'age': 40 }); -result = _.assign({ 'name': 'moe' }, { 'age': 40 }, function (a, b) { - return typeof a == 'undefined' ? b : a; +result = _.assign({ 'name': 'moe' }, { 'age': 40 }, function(a, b) { + return typeof a == 'undefined' ? b : a; }); result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).assign({ 'age': 40 }); -result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).assign({ 'age': 40 }, function (a, b) { - return typeof a == 'undefined' ? b : a; +result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).assign({ 'age': 40 }, function(a, b) { + return typeof a == 'undefined' ? b : a; }); result = _.extend({ 'name': 'moe' }, { 'age': 40 }); -result = _.extend({ 'name': 'moe' }, { 'age': 40 }, function (a, b) { - return typeof a == 'undefined' ? b : a; +result = _.extend({ 'name': 'moe' }, { 'age': 40 }, function(a, b) { + return typeof a == 'undefined' ? b : a; }); result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).extend({ 'age': 40 }); -result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).extend({ 'age': 40 }, function (a, b) { - return typeof a == 'undefined' ? b : a; +result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).extend({ 'age': 40 }, function(a, b) { + return typeof a == 'undefined' ? b : a; }); result = _.clone(stoogesAges); result = _.clone(stoogesAges, true); -result = _.clone(stoogesAges, true, function (value) { - return _.isElement(value) ? value.cloneNode(false) : undefined; +result = _.clone(stoogesAges, true, function(value) { + return _.isElement(value) ? value.cloneNode(false) : undefined; }); result = _.cloneDeep(stoogesAges); -result = _.cloneDeep(stoogesAges, function (value) { - return _.isElement(value) ? value.cloneNode(false) : undefined; +result = _.cloneDeep(stoogesAges, function(value) { + return _.isElement(value) ? value.cloneNode(false) : undefined; }); interface Food { - name: string; - type: string; + name: string; + type: string; } var foodDefaults = { 'name': 'apple' }; result = _.defaults(foodDefaults, { 'name': 'banana', 'type': 'fruit' }); -result = <_.LoDashObjectWrapper>_(foodDefaults).defaults({ 'name': 'banana', 'type': 'fruit' }); + result = <_.LoDashObjectWrapper>_(foodDefaults).defaults({ 'name': 'banana', 'type': 'fruit' }); -result = _.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) { - return num % 2 == 0; +result = _.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { + return num % 2 == 0; }); -result = _.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function (num) { - return num % 2 == 1; +result = _.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { + return num % 2 == 1; }); -result = _.forIn(new Dog('Dagny'), function (value, key) { - console.log(key); +result = _.forIn(new Dog('Dagny'), function(value, key) { + console.log(key); }); -result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forIn(function (value, key) { - console.log(key); +result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forIn(function(value, key) { + console.log(key); }); -result = _.forInRight(new Dog('Dagny'), function (value, key) { - console.log(key); +result = _.forInRight(new Dog('Dagny'), function(value, key) { + console.log(key); }); -result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forInRight(function (value, key) { - console.log(key); +result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forInRight(function(value, key) { + console.log(key); }); interface ZeroOne { - 0: string; - 1: string; - one: string; + 0: string; + 1: string; + one: string; } -result = _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function (num, key) { - console.log(key); +result = _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { + console.log(key); }); -result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwn(function (num, key) { - console.log(key); + result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwn(function(num, key) { + console.log(key); + }); + +result = _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { + console.log(key); }); -result = _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function (num, key) { - console.log(key); -}); - -result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwnRight(function (num, key) { - console.log(key); -}); + result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwnRight(function(num, key) { + console.log(key); + }); result = _.functions(_); result = _.methods(_); @@ -759,12 +759,12 @@ result = <_.LoDashArrayWrapper>_(_).methods(); result = _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); interface FirstSecond { - first: string; - second: string; + first: string; + second: string; } result = _.invert({ 'first': 'moe', 'second': 'larry' }); -(function (...args: any[]) { return _.isArguments(arguments); })(1, 2, 3); +(function(...args: any[]) { return _.isArguments(arguments); })(1, 2, 3); (function () { return _.isArray(arguments); })(); result = _.isArray([1, 2, 3]); @@ -787,12 +787,12 @@ result = _.isEqual(moe, copy); var words = ['hello', 'goodbye']; var otherWords = ['hi', 'goodbye']; -result = _.isEqual(words, otherWords, function (a, b) { - var reGreet = /^(?:hello|hi)$/i, - aGreet = _.isString(a) && reGreet.test(a), - bGreet = _.isString(b) && reGreet.test(b); +result = _.isEqual(words, otherWords, function(a, b) { + var reGreet = /^(?:hello|hi)$/i, + aGreet = _.isString(a) && reGreet.test(a), + bGreet = _.isString(b) && reGreet.test(b); - return (aGreet || bGreet) ? (aGreet == bGreet) : undefined; + return (aGreet || bGreet) ? (aGreet == bGreet) : undefined; }); result = _.isFinite(-101); @@ -820,7 +820,7 @@ class Stooge { constructor( public name: string, public age: number - ) { } + ) {} } result = _.isPlainObject(new Stooge('moe', 40)); @@ -836,67 +836,67 @@ result = _.isUndefined(void 0); result = _.keys({ 'one': 1, 'two': 2, 'three': 3 }); var mergeNames = { - 'stooges': [ - { 'name': 'moe' }, - { 'name': 'larry' } - ] + 'stooges': [ + { 'name': 'moe' }, + { 'name': 'larry' } + ] }; var mergeAges = { - 'stooges': [ - { 'age': 40 }, - { 'age': 50 } - ] + 'stooges': [ + { 'age': 40 }, + { 'age': 50 } + ] }; result = _.merge(mergeNames, mergeAges); var mergeFood = { - 'fruits': ['apple'], - 'vegetables': ['beet'] + 'fruits': ['apple'], + 'vegetables': ['beet'] }; var mergeOtherFood = { - 'fruits': ['banana'], - 'vegetables': ['carrot'] + 'fruits': ['banana'], + 'vegetables': ['carrot'] }; interface FruitVeg { - fruits: string[]; - vegetables: string[] + fruits: string[]; + vegetables: string[] }; -result = _.merge(mergeFood, mergeOtherFood, function (a, b) { - return _.isArray(a) ? a.concat(b) : undefined; +result = _.merge(mergeFood, mergeOtherFood, function(a, b) { + return _.isArray(a) ? a.concat(b) : undefined; }); interface HasName { - name: string; + name: string; } result = _.omit({ 'name': 'moe', 'age': 40 }, 'age'); result = _.omit({ 'name': 'moe', 'age': 40 }, ['age']); -result = _.omit({ 'name': 'moe', 'age': 40 }, function (value) { - return typeof value == 'number'; +result = _.omit({ 'name': 'moe', 'age': 40 }, function(value) { + return typeof value == 'number'; }); result = _.pairs({ 'moe': 30, 'larry': 40 }); result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, 'name'); result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, ['name']); -result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, function (value, key) { - return key.charAt(0) != '_'; +result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key) { + return key.charAt(0) != '_'; }); -result = _.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (r, num) { - num *= num; - if (num % 2) { - return r.push(num) < 3; - } +result = _.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function(r, num) { + num *= num; + if (num % 2) { + return r.push(num) < 3; + } }); // → [1, 9, 25] -result = <{ a: number; b: number; c: number; }>_.transform({ 'a': 1, 'b': 2, 'c': 3 }, function (r, num, key) { - r[key] = num * 3; +result = <{a:number;b:number;c:number;}>_.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(r, num, key) { + r[key] = num * 3; }); result = _.values({ 'one': 1, 'two': 2, 'three': 3 }); @@ -910,9 +910,9 @@ result = _.escape('Moe, Larry & Curly'); result = <{ name: string }>_.identity({ 'name': 'moe' }); _.mixin({ - 'capitalize': function (string) { - return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); - } + 'capitalize': function(string) { + return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); + } }); var lodash = _.noConflict(); @@ -926,10 +926,10 @@ result = _.random(1.2, 5.2); result = _.random(0, 5, true); var object = { - 'cheese': 'crumpets', - 'stuff': function () { - return 'nonsense'; - } + 'cheese': 'crumpets', + 'stuff': function() { + return 'nonsense'; + } }; result = _.result(object, 'cheese'); @@ -963,10 +963,10 @@ class Mage { } } -var mage = new Mage(); +var mage = new Mage(); result = _.times(3, <() => number>_.partial(_.random, 1, 6)); -result = _.times(3, function (n: number) { mage.castSpell(n); }); -result = _.times(3, function (n: number) { this.cast(n); }, mage); +result = _.times(3, function(n: number) { mage.castSpell(n); }); +result = _.times(3, function(n: number) { this.cast(n); }, mage); result = _.unescape('Moe, Larry & Curly'); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 3c4b572c15..80b1940c98 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -181,15 +181,15 @@ declare module _ { **/ valueOf(): T; - /** - * @see valueOf - **/ - value(): T; - } + /** + * @see valueOf + **/ + value(): T; + } - interface LoDashWrapper extends LoDashWrapperBase> { } + interface LoDashWrapper extends LoDashWrapperBase> {} - interface LoDashObjectWrapper extends LoDashWrapperBase> { } + interface LoDashObjectWrapper extends LoDashWrapperBase> {} interface LoDashArrayWrapper extends LoDashWrapperBase> { concat(...items: T[]): LoDashArrayWrapper; From bb05b91c9ca3e806ecb0471166a2edcc3b2ec5a1 Mon Sep 17 00:00:00 2001 From: JeremyCBrooks Date: Sun, 13 Apr 2014 11:24:48 -0400 Subject: [PATCH 07/49] added definition for jquery total-storage fixed failing test updated CONTRIBUTORS --- CONTRIBUTORS.md | 1 + .../jquery.total-storage-tests.ts | 21 ++++++ .../jquery.total-storage.d.ts | 64 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 jquery.total-storage/jquery.total-storage-tests.ts create mode 100644 jquery.total-storage/jquery.total-storage.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index d68e3061cc..dd09cf2830 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -151,6 +151,7 @@ All definitions files include a header with the author and editors, so at some p * [jQuery.TinyCarousel](http://baijs.nl/tinycarousel/) (by [Christiaan Rakowski](https://github.com/csrakowski)) * [jQuery.TinyScrollbar](http://baijs.nl/tinyscrollbar/) (by [Christiaan Rakowski](https://github.com/csrakowski)) * [jQuery.tooltipster](https://github.com/iamceege/tooltipster) (by [Patrick Magee](https://github.com/pjmagee)) +* [jQuery.total-storage](https://github.com/Upstatement/jquery-total-storage) (by [Jeremy Brooks](https://github.com/JeremyCBrooks/)) * [jQuery.Transit](http://ricostacruz.com/jquery.transit/) (by [MrBigDog2U](https://github.com/MrBigDog2U)) * [jQuery.Validation](http://bassistance.de/jquery-plugins/jquery-plugin-validation/) (by [Boris Yankov](https://github.com/borisyankov)) * [jQuery.Watermark](http://jquery-watermark.googlecode.com) (by [Anwar Javed](https://github.com/anwarjaved)) diff --git a/jquery.total-storage/jquery.total-storage-tests.ts b/jquery.total-storage/jquery.total-storage-tests.ts new file mode 100644 index 0000000000..0ba3700eee --- /dev/null +++ b/jquery.total-storage/jquery.total-storage-tests.ts @@ -0,0 +1,21 @@ +// Type definitions for jQueryTotalStorage 1.1.2 +// Project: https://github.com/Upstatement/jquery-total-storage +// Definitions by: Jeremy Brooks +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +//direct call +$.totalStorage("test_key1", "test_value"); +var val1:string = $.totalStorage("test_key"); + +//set/get +$.totalStorage.setItem("test_key2", 123); +var val2:number = $.totalStorage.getItem("test_key2"); + +//get all items +var list = $.totalStorage.getAll(); + +//delete item +var deleted = $.totalStorage.deleteItem("test_key1"); \ No newline at end of file diff --git a/jquery.total-storage/jquery.total-storage.d.ts b/jquery.total-storage/jquery.total-storage.d.ts new file mode 100644 index 0000000000..8bfed0a4d3 --- /dev/null +++ b/jquery.total-storage/jquery.total-storage.d.ts @@ -0,0 +1,64 @@ +// Type definitions for jQueryTotalStorage 1.1.2 +// Project: https://github.com/Upstatement/jquery-total-storage +// Definitions by: Jeremy Brooks +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +/** +* @desc Set the value of a key to a string +* @example $.totalStorage('the_key', 'the_value'); +* @desc Set the value of a key to a number +* @example $.totalStorage('the_key', 800.2); +* @desc Set the value of a key to a complex Array +* @example var myArray = new Array(); +* myArray.push({name:'Jared', company:'Upstatement', zip:63124}); +* myArray.push({name:'McGruff', company:'Police', zip:60652}; +* $.totalStorage('people', myArray); +* //to return: +* $.totalStorage('people'); +* +*/ + +interface JQueryTotalStorage { + + /** + * @desc Set or get a key's value + * @param key Key to set. + * @param value Value to set for key. If ommited, current value for key is returned. + * @param options Not implemented. + */ + (key: string, value?: any, options?: JQueryTotalStorageOptions): any; + + /** + * @desc Set a key's value + * @param key Key to set. + * @param value Value to set for key. + */ + setItem(key: string, value: any): any; + + /** + * @desc Get a key's value + * @param key Key to get. + */ + getItem(key: string): any; + + /** + * @desc Get all set values + */ + getAll(): any[]; + + /** + * @desc Delete item by key + * @param key Key of item to delete + */ + deleteItem(key: string): boolean; +} + +interface JQueryTotalStorageOptions { + //not implemented... +} + +interface JQueryStatic { + totalStorage: JQueryTotalStorage; +} \ No newline at end of file From 114f930fbd62b5de7715feb6e144bf2c44b52888 Mon Sep 17 00:00:00 2001 From: Keats Date: Sun, 27 Apr 2014 09:55:40 +0100 Subject: [PATCH 08/49] Update Restangular definition Add enhanced promises Add new methods up to current 1.4 Rewrite tests to make them more realistic --- restangular/restangular-tests.ts | 240 ++++++++++++++++--------------- restangular/restangular.d.ts | 180 +++++++++++++---------- 2 files changed, 228 insertions(+), 192 deletions(-) diff --git a/restangular/restangular-tests.ts b/restangular/restangular-tests.ts index 9643c9e6b3..9d5aa9fb4f 100644 --- a/restangular/restangular-tests.ts +++ b/restangular/restangular-tests.ts @@ -1,145 +1,159 @@ /// -function test_basic() { - var $scope; - Restangular.all('accounts'); - Restangular.one('accounts', 1234); - Restangular.all('users').getList().then(function (users) { - $scope.user = users[0]; - }) - $scope.cars = $scope.user.getList('cars'); - $scope.user.sendMessage(); - $scope.user.one('message', 123).all('unread').getList(); +var myApp = angular.module('testModule'); - var baseAccounts = Restangular.all('accounts'); +myApp.config((RestangularProvider: restangular.IProvider) => { + RestangularProvider.setBaseUrl('/api/v1'); + RestangularProvider.setExtraFields(['name']); + RestangularProvider.setResponseExtractor(function (response, operation) { + return response.data; + }); - $scope.allAccounts = baseAccounts.getList(); + RestangularProvider.setDefaultHttpFields({ cache: true }); + RestangularProvider.setMethodOverriders(["put", "patch"]); - var newAccount = { name: "Gonto's account" }; + RestangularProvider.setErrorInterceptor(function (response) { + console.error('' + response.status + ' ' + response.data); + }); - baseAccounts.post(newAccount); + RestangularProvider.setRequestSuffix('.json'); - Restangular.one('accounts', 123).one('buildings', 456).get() + RestangularProvider.setRequestInterceptor(function (element, operation, route, url) { + }); - Restangular.one('accounts', 123).all('buildings').getList() + RestangularProvider.addElementTransformer('accounts', false, function (elem) { + elem.accountName = 'Changed'; + return elem; + }); - baseAccounts.getList().then(function (accounts) { + RestangularProvider.setRestangularFields({ + id: "_id", + route: "restangularRoute", + selfLink: "self.href" + }); - var firstAccount = accounts[0]; - $scope.buildings = firstAccount.getList("buildings"); - $scope.loggedInPlaces = firstAccount.getList("places", { query: 'wuut' }, { 'x-user': 'mgonto' }) + RestangularProvider.addRequestInterceptor(function(element, operation, route, url) { + delete element.name; + return element; + }); - firstAccount.name = "Gonto" - - var editFirstAccount = Restangular.copy(firstAccount); - - firstAccount.put(); - editFirstAccount.put(); - - firstAccount.remove(); - - var myBuilding = { - name: "Gonto's Building", - place: "Argentina" - }; + RestangularProvider.setFullRequestInterceptor(function(element, operation, route, url, headers, params, httpConfig) { + delete element.name; + return { + element: element, + params: params, + headers: headers, + httpConfig: httpConfig + }; + }); +}); - firstAccount.post("Buildings", myBuilding).then(function () { - console.log("Object saved OK"); - }, function () { - console.log("There was an error saving"); - }); - - - firstAccount.getList("users", { query: 'wuut' }).then(function (users) { - - users.post({ userName: 'unknown' }); - - - users.customGET("messages", { param: "myParam" }) - - var firstUser = users[0]; - - $scope.userFromServer = firstUser.get(); - - firstUser.head() - - }); - - }, function errorCallback() { - alert("Oops error from server :("); - }) - - var account = Restangular.one("accounts", 123); - - $scope.account = account.get({ single: true }); - - account.customPOST({ name: "My Message" }, "messages", { param: "myParam" }, {}) +interface MyAppScope extends ng.IScope { + accounts: string[]; + allAccounts: any[]; + account: any; + buildings: restangular.ICollectionPromise; + loggedInPlaces: restangular.ICollectionPromise; + userFromServer: restangular.IPromise; } -function test_config() { - RestangularProvider.setBaseUrl('/api/v1'); - RestangularProvider.setExtraFields(['name']); - RestangularProvider.setResponseExtractor(function (response, operation) { - return response.data; +myApp.controller('TestCtrl', ( + $scope: MyAppScope, + Restangular: restangular.IService + ) => { + var baseAccounts = Restangular.all('accounts'); + + baseAccounts.getList().then(function(accounts) { + $scope.allAccounts = accounts; + }); + + $scope.accounts = Restangular.all('accounts').getList().$object; + var newAccount = {name: "Gonto's account"}; + baseAccounts.post(newAccount); + + Restangular.allUrl('googlers', 'http://www.google.com/').getList(); + Restangular.oneUrl('googlers', 'http://www.google.com/1').get(); + Restangular.one('accounts', 123).one('buildings', 456).get(); + Restangular.one('accounts', 123).getList('buildings'); + + baseAccounts.getList().then(function (accounts) { + var firstAccount = accounts[0]; + $scope.buildings = firstAccount.getList("buildings"); + $scope.loggedInPlaces = firstAccount.getList("places", {query: "param"}, {'x-user': 'mgonto'}); + + firstAccount.name = "Gonto"; + var editFirstAccount = Restangular.copy(firstAccount); + + firstAccount.put(); + editFirstAccount.put(); + + firstAccount.save(); + + firstAccount.remove(); + + var myBuilding = { + name: "Gonto's Building", + place: "Argentina" + }; + + firstAccount.post("Buildings", myBuilding).then(function() { + console.log("Object saved OK"); + }, function() { + console.log("There was an error saving"); }); - RestangularProvider.setDefaultHttpFields({ cache: true }); - RestangularProvider.setMethodOverriders(["put", "patch"]); + firstAccount.getList("users", {query: "params"}).then(function(users) { + users.post({userName: 'unknown'}); + users.customGET("messages", {param: "myParam"}); - RestangularProvider.setErrorInterceptor(function (response) { + var firstUser = users[0]; + $scope.userFromServer = firstUser.get(); + firstUser.head() + + }); + + }, function errorCallback() { + alert("Oops error from server :("); + }); + + var account = Restangular.one("accounts", 123); + + $scope.account = account.get({single: true}); + + account.customPOST({name: "My Message"}, "messages", {param: "myParam"}, {}); + + Restangular.one('accounts', 123).withHttpConfig({timeout: 100}).getList('buildings'); + $scope.account = Restangular.one('accounts', 123); + $scope.account.withHttpConfig({timeout: 100}).put(); + + var myRestangular = Restangular.withConfig((configurer: restangular.IProvider) => { + configurer.setBaseUrl('/api/v1'); + configurer.setExtraFields(['name']); + + configurer.setErrorInterceptor(function (response) { console.error('' + response.status + ' ' + response.data); }); + configurer.setResponseExtractor(function (response, operation) { + return response.data; + }); + configurer.setDefaultHttpFields({ cache: true }); + configurer.setMethodOverriders(["put", "patch"]); - RestangularProvider.setRestangularFields({ + configurer.setRestangularFields({ id: "_id", route: "restangularRoute" }); - RestangularProvider.setRequestSuffix('.json'); + configurer.setRequestSuffix('.json'); - RestangularProvider.setRequestInterceptor(function (element, operation, route, url) { + configurer.setRequestInterceptor(function (element, operation, route, url) { }); - RestangularProvider.addElementTransformer('accounts', false, function (elem) { + configurer.addElementTransformer('accounts', false, function (elem) { elem.accountName = 'Changed'; return elem; }); - - var myRestangular = Restangular.withConfig((configurer: RestangularProvider) => { - configurer.setBaseUrl('/api/v1'); - configurer.setExtraFields(['name']); - - configurer.setErrorInterceptor(function (response) { - console.error('' + response.status + ' ' + response.data); - }); - configurer.setResponseExtractor(function (response, operation) { - return response.data; - }); - configurer.setDefaultHttpFields({ cache: true }); - configurer.setMethodOverriders(["put", "patch"]); - - configurer.setRestangularFields({ - id: "_id", - route: "restangularRoute" - }); - - configurer.setRequestSuffix('.json'); - - configurer.setRequestInterceptor(function (element, operation, route, url) { - }); - - configurer.addElementTransformer('accounts', false, function (elem) { - elem.accountName = 'Changed'; - return elem; - }); - }); -} - -function test_withHttpConfig() { - var $scope; - Restangular.one('accounts', 123).withHttpConfig({timeout: 100}).getList('buildings'); - $scope.account = Restangular.one('accounts', 123); - $scope.account.withHttpConfig({timeout: 100}).put(); -} + }); +}); diff --git a/restangular/restangular.d.ts b/restangular/restangular.d.ts index 0cc4321afb..9fd397bf57 100644 --- a/restangular/restangular.d.ts +++ b/restangular/restangular.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Restangular v1.2.2 +// Type definitions for Restangular v1.4.0 // Project: https://github.com/mgonto/restangular // Definitions by: Boris Yankov // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -6,7 +6,23 @@ /// -interface RestangularRequestConfig { + +declare module restangular { + + interface IPromise extends ng.IPromise { + call(methodName: string, params?: any): IPromise; + get(fieldName: string): IPromise; + $object: T; +} + + interface ICollectionPromise extends ng.IPromise { + push(object: any): ICollectionPromise; + call(methodName: string, params?: any): ICollectionPromise; + get(fieldName: string): ICollectionPromise; + $object: T[]; + } + + interface IRequestConfig { params?: any; headers?: any; cache?: any; @@ -15,81 +31,9 @@ interface RestangularRequestConfig { transformRequest?: any; transformResponse?: any; timeout?: any; // number | promise -} + } -interface Restangular extends RestangularCustom { - one(route: string, id?: number): RestangularElement; - one(route: string, id?: string): RestangularElement; - oneUrl(route: string, url: string): RestangularElement; - all(route: string): RestangularCollection; - allUrl(route: string, url: string): RestangularCollection; - copy(fromElement: any): RestangularElement; - withConfig(configurer: (RestangularProvider: RestangularProvider) => any): Restangular; - restangularizeElement(parent: any, element: any, route: string, collection?: any, reqParams?: any): RestangularElement; - restangularizeCollection(parent: any, element: any, route: string): RestangularCollection; - stripRestangular(element: any): any; -} - -interface RestangularElement extends Restangular { - get(queryParams?: any, headers?: any): ng.IPromise; - getList(subElement: any, queryParams?: any, headers?: any): ng.IPromise; - put(queryParams?: any, headers?: any): ng.IPromise; - post(subElement: any, elementToPost: any, queryParams?: any, headers?: any): ng.IPromise; - remove(queryParams?: any, headers?: any): ng.IPromise; - head(queryParams?: any, headers?: any): ng.IPromise; - trace(queryParams?: any, headers?: any): ng.IPromise; - options(queryParams?: any, headers?: any): ng.IPromise; - patch(queryParams?: any, headers?: any): ng.IPromise; - withHttpConfig(httpConfig: RestangularRequestConfig): RestangularElement; - getRestangularUrl(): string; -} - -interface RestangularCollection extends Restangular { - getList(queryParams?: any, headers?: any): ng.IPromise; - post(elementToPost: any, queryParams?: any, headers?: any): ng.IPromise; - head(queryParams?: any, headers?: any): ng.IPromise; - trace(queryParams?: any, headers?: any): ng.IPromise; - options(queryParams?: any, headers?: any): ng.IPromise; - patch(queryParams?: any, headers?: any): ng.IPromise; - putElement(idx: any, params: any, headers: any): ng.IPromise; - withHttpConfig(httpConfig: RestangularRequestConfig): RestangularCollection; - getRestangularUrl(): string; -} - -interface RestangularCustom { - customGET(path: string, params?: any, headers?: any): ng.IPromise; - customGETLIST(path: string, params?: any, headers?: any): ng.IPromise; - customDELETE(path: string, params?: any, headers?: any): ng.IPromise; - customPOST(elem?: any, path?: string, params?: any, headers?: any): ng.IPromise; - customPUT(elem?: any, path?: string, params?: any, headers?: any): ng.IPromise; - customOperation(operation: string, path: string, params?: any, headers?: any, elem?: any): ng.IPromise; - addRestangularMethod(name: string, operation: string, path?: string, params?: any, headers?: any, elem?: any): ng.IPromise; -} - -interface RestangularProvider { - setBaseUrl(baseUrl: string): void; - setExtraFields(fields: string[]): void; - setParentless(parentless: boolean, routes: string[]): void; - setDefaultHttpFields(httpFields: any): void; - addElementTransformer(route: string, transformer: Function): void; - addElementTransformer(route: string, isCollection: boolean, transformer: Function): void; - setOnElemRestangularized(callback: (elem: any, isCollection: boolean, what: string, restangular: Restangular) => any): void; - setResponseInterceptor(responseInterceptor: (data: any, operation: string, what: string, url: string, response: RestangularResponse, deferred: ng.IDeferred) => any): void; - setResponseExtractor(responseInterceptor: (data: any, operation: string, what: string, url: string, response: RestangularResponse, deferred: ng.IDeferred) => any): void; - setRequestInterceptor(requestInterceptor: (element: any, operation: string, what: string, url: string) => any): void; - setFullRequestInterceptor(fullRequestInterceptor: (element: any, operation: string, what: string, url: string, headers: any, params: any) => {element: any; headers: any; params: any}): void; - setErrorInterceptor(errorInterceptor: (response: RestangularResponse) => any): void; - setRestangularFields(fields: {[fieldName: string]: string}): void; - setMethodOverriders(overriders: string[]): void; - setDefaultRequestParams(params: any): void; - setDefaultRequestParams(methods: any, params: any): void; - setFullResponse(fullResponse: boolean): void; - setDefaultHeaders(headers: any): void; - setRequestSuffix(suffix: string): void; - setUseCannonicalId(useCannonicalId: boolean): void; -} - -interface RestangularResponse { + interface IResponse { status: number; data: any; config: { @@ -97,7 +41,85 @@ interface RestangularResponse { url: string; params: any; } -} + } -declare var Restangular: Restangular; -declare var RestangularProvider: RestangularProvider; + interface IProvider { + setBaseUrl(baseUrl: string): void; + setExtraFields(fields: string[]): void; + setParentless(parentless: boolean, routes: string[]): void; + setDefaultHttpFields(httpFields: any): void; + addElementTransformer(route: string, transformer: Function): void; + addElementTransformer(route: string, isCollection: boolean, transformer: Function): void; + setTransformOnlyServerElements(active: boolean): void; + setOnElemRestangularized(callback: (elem: any, isCollection: boolean, what: string, restangular: IService) => any): void; + setResponseInterceptor(responseInterceptor: (data: any, operation: string, what: string, url: string, response: IResponse, deferred: ng.IDeferred) => any): void; + setResponseExtractor(responseInterceptor: (data: any, operation: string, what: string, url: string, response: IResponse, deferred: ng.IDeferred) => any): void; + addResponseInterceptor(responseInterceptor: (data: any, operation: string, what: string, url: string, response: IResponse, deferred: ng.IDeferred) => any): void; + setRequestInterceptor(requestInterceptor: (element: any, operation: string, what: string, url: string) => any): void; + addRequestInterceptor(requestInterceptor: (element: any, operation: string, what: string, url: string) => any): void; + setFullRequestInterceptor(fullRequestInterceptor: (element: any, operation: string, what: string, url: string, headers: any, params: any, httpConfig: IRequestConfig) => {element: any; headers: any; params: any}): void; + addFullRequestInterceptor(requestInterceptor: (element: any, operation: string, what: string, url: string, headers: any, params: any, httpConfig: IRequestConfig) => {headers: any; params: any; element: any; httpConfig: IRequestConfig}): void; + setErrorInterceptor(errorInterceptor: (response: IResponse, deferred: ng.IDeferred) => any): void; + setRestangularFields(fields: {[fieldName: string]: string}): void; + setMethodOverriders(overriders: string[]): void; + setJsonp(jsonp: boolean): void; + setDefaultRequestParams(params: any): void; + setDefaultRequestParams(method: string, params: any): void; + setDefaultRequestParams(methods: string[], params: any): void; + setFullResponse(fullResponse: boolean): void; + setDefaultHeaders(headers: any): void; + setRequestSuffix(suffix: string): void; + setUseCannonicalId(useCannonicalId: boolean): void; + setEncodeIds(encode: boolean): void; + } + + interface ICustom { + customGET(path: string, params?: any, headers?: any): IPromise; + customGETLIST(path: string, params?: any, headers?: any): ICollectionPromise; + customDELETE(path: string, params?: any, headers?: any): IPromise; + customPOST(elem?: any, path?: string, params?: any, headers?: any): IPromise; + customPUT(elem?: any, path?: string, params?: any, headers?: any): IPromise; + customOperation(operation: string, path: string, params?: any, headers?: any, elem?: any): IPromise; + addRestangularMethod(name: string, operation: string, path?: string, params?: any, headers?: any, elem?: any): IPromise; + } + + interface IService extends ICustom { + one(route: string, id?: number): IElement; + one(route: string, id?: string): IElement; + oneUrl(route: string, url: string): IElement; + all(route: string): IElement; + allUrl(route: string, url: string): IElement; + copy(fromElement: any): IElement; + withConfig(configurer: (RestangularProvider: IProvider) => any): IService; + restangularizeElement(parent: any, element: any, route: string, collection?: any, reqParams?: any): IElement; + restangularizeCollection(parent: any, element: any, route: string): ICollection; + stripRestangular(element: any): any; + } + + interface IElement extends IService { + get(queryParams?: any, headers?: any): IPromise; + getList(subElement?: any, queryParams?: any, headers?: any): ICollectionPromise; + put(queryParams?: any, headers?: any): IPromise; + post(subElement: any, elementToPost: any, queryParams?: any, headers?: any): IPromise; + post(elementToPost: any, queryParams?: any, headers?: any): IPromise; + remove(queryParams?: any, headers?: any): IPromise; + head(queryParams?: any, headers?: any): IPromise; + trace(queryParams?: any, headers?: any): IPromise; + options(queryParams?: any, headers?: any): IPromise; + patch(queryParams?: any, headers?: any): IPromise; + withHttpConfig(httpConfig: IRequestConfig): IElement; + getRestangularUrl(): string; + } + + interface ICollection extends IService { + getList(queryParams?: any, headers?: any): ICollectionPromise; + post(elementToPost: any, queryParams?: any, headers?: any): IPromise; + head(queryParams?: any, headers?: any): IPromise; + trace(queryParams?: any, headers?: any): IPromise; + options(queryParams?: any, headers?: any): IPromise; + patch(queryParams?: any, headers?: any): IPromise; + putElement(idx: any, params: any, headers: any): IPromise; + withHttpConfig(httpConfig: IRequestConfig): ICollection; + getRestangularUrl(): string; + } +} From 1d55f70e34b851d9bd2c9a855fb923e64db70ffb Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Sun, 27 Apr 2014 17:29:43 -0700 Subject: [PATCH 09/49] Fixed local, roaming and temp definitions on WinJS.Application object. These should be instances on IOHelper as defined in WinJS. --- winjs/winjs.d.ts | 161 +++++++++++++++-------------------------------- 1 file changed, 49 insertions(+), 112 deletions(-) diff --git a/winjs/winjs.d.ts b/winjs/winjs.d.ts index 20263a3bb9..d14238eeeb 100644 --- a/winjs/winjs.d.ts +++ b/winjs/winjs.d.ts @@ -25,7 +25,49 @@ and limitations under the License. **/ interface Element { winControl: any; // TODO: This should be control? -}/** +} + +/** + * Utility class for easy access to operations on application folders +**/ +interface IOHelper { + /** + * Instance of the currently wrapped application folder + **/ + folder: Windows.Storage.StorageFolder; + + /** + * Determines whether the specified file exists in the folder. + * @param filename The name of the file. + * @returns A promise that completes with a value of either true (if the file exists) or false. + **/ + exists(filename: string): WinJS.Promise; + + /** + * Reads the specified file. If the file doesn't exist, the specified default value is returned. + * @param fileName The file to read from. + * @param def The default value to be returned if the file failed to open. + * @returns A promise that completes with a value that is either the contents of the file, or the specified default value. + **/ + readText(fileName: string, def?: string): WinJS.Promise; + + /** + * Deletes a file from the folder. + * @param fileName The file to be deleted. + * @returns A promise that is fulfilled when the file has been deleted. + **/ + remove(fileName: string): WinJS.Promise; + + /** + * Writes the specified text to the specified file. + * @param fileName The name of the file. + * @param text The content to be written to the file. + * @returns A promise that completes with a value that is the number of characters written. + **/ + writeText(fileName: string, text: string): WinJS.Promise; +} + +/** * Provides application-level functionality, for example activation, storage, and application events. **/ declare module WinJS.Application { @@ -34,128 +76,23 @@ declare module WinJS.Application { /** * The local storage of the application. **/ - var local: { - //#region Methods - - /** - * Determines whether the specified file exists in the folder. - * @param filename The name of the file. - * @returns A promise that completes with a value of either true (if the file exists) or false. - **/ - exists(filename: string): Promise; - - /** - * Reads the specified file. If the file doesn't exist, the specified default value is returned. - * @param fileName The file to read from. - * @param def The default value to be returned if the file failed to open. - * @returns A promise that completes with a value that is either the contents of the file, or the specified default value. - **/ - readText(fileName: string, def?: string): Promise; - - /** - * Deletes a file from the folder. - * @param fileName The file to be deleted. - * @returns A promise that is fulfilled when the file has been deleted. - **/ - remove(fileName: string): Promise; - - /** - * Writes the specified text to the specified file. - * @param fileName The name of the file. - * @param text The content to be written to the file. - * @returns A promise that completes with a value that is the number of characters written. - **/ - writeText(fileName: string, text: string): Promise; - - //#endregion Methods - - }; + var local: IOHelper; /** * The roaming storage of the application. **/ - var roaming: { - //#region Methods + var roaming: IOHelper; - /** - * Determines whether the specified file exists in the folder. - * @param filename The name of the file. - * @returns A promise that completes with a value of either true (if the file exists) or false. - **/ - exists(filename: string): Promise; - - /** - * Reads the specified file. If the file doesn't exist, the specified default value is returned. - * @param fileName The file to read from. - * @param def The default value to be returned if the file failed to open. - * @returns A promise that completes with a value that is either the contents of the file, or the specified default value. - **/ - readText(fileName: string, def?: string): Promise; - - /** - * Deletes a file from the folder. - * @param fileName The file to be deleted. - * @returns A promise that is fulfilled when the file has been deleted. - **/ - remove(fileName: string): Promise; - - /** - * Writes the specified text to the specified file. - * @param fileName The name of the file. - * @param text The content to be written to the file. - * @returns A promise that completes with a value that is the number of characters written. - **/ - writeText(fileName: string, text: string): Promise; - - //#endregion Methods - - }; + /** + * The temp storage of the application. + **/ + var temp: IOHelper; /** * An object used for storing app information that can be used to restore the app's state after it has been suspended and then resumed. Data that can usefully be contained in this object includes the current navigation page or any information the user has added to the input controls on the page. You should not add information about customization (for example colors) or user-defined lists of content. **/ var sessionState: any; - /** - * The temp storage of the application. - **/ - var temp: { - //#region Methods - - /** - * Determines whether the specified file exists in the folder. - * @param filename The name of the file. - * @returns A promise that completes with a value of either true (if the file exists) or false. - **/ - exists(filename: string): Promise; - - /** - * Reads the specified file. If the file doesn't exist, the specified default value is returned. - * @param fileName The file to read from. - * @param def The default value to be returned if the file failed to open. - * @returns A promise that completes with a value that is either the contents of the file, or the specified default value. - **/ - readText(fileName: string, def?: string): Promise; - - /** - * Deletes a file from the folder. - * @param fileName The file to be deleted. - * @returns A promise that is fulfilled when the file has been deleted. - **/ - remove(fileName: string): Promise; - - /** - * Writes the specified text to the specified file. - * @param fileName The name of the file. - * @param text The text to write. - * @returns A Promise that completes with the number of bytes successfully written to the file. - **/ - writeText(fileName: string, text: string): Promise; - - //#endregion Methods - - }; - //#endregion Objects //#region Methods From 5051de332ff6c146df87526fe810f6b2d3313bd2 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Sun, 27 Apr 2014 17:33:12 -0700 Subject: [PATCH 10/49] Changed QueryCollection to be an interface instead of class so that it can extend Array interface. In WinJS implementaion, QueryCollection extends Array and all Array members should be available on QueryCollection. --- winjs/winjs.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/winjs/winjs.d.ts b/winjs/winjs.d.ts index d14238eeeb..f58c11d12d 100644 --- a/winjs/winjs.d.ts +++ b/winjs/winjs.d.ts @@ -76,17 +76,17 @@ declare module WinJS.Application { /** * The local storage of the application. **/ - var local: IOHelper; + var local: IOHelper; /** * The roaming storage of the application. **/ - var roaming: IOHelper; + var roaming: IOHelper; /** * The temp storage of the application. **/ - var temp: IOHelper; + var temp: IOHelper; /** * An object used for storing app information that can be used to restore the app's state after it has been suspended and then resumed. Data that can usefully be contained in this object includes the current navigation page or any information the user has added to the input controls on the page. You should not add information about customization (for example colors) or user-defined lists of content. @@ -7904,7 +7904,7 @@ declare module WinJS.Utilities { /** * Represents the result of a query selector, and provides various operations that perform actions over the elements of the collection. **/ - class QueryCollection { + interface QueryCollection extends Array { //#region Constructors /** From bfe38c6de7878946433025a4b69e34f53dc6ffab Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Sun, 27 Apr 2014 17:35:19 -0700 Subject: [PATCH 11/49] Made element parameter optional in WinJS.Utilities.query as it is optional in WinJS implementation. See http://msdn.microsoft.com/en-us/library/windows/apps/br229847.aspx. --- winjs/winjs.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winjs/winjs.d.ts b/winjs/winjs.d.ts index f58c11d12d..a2e95e557f 100644 --- a/winjs/winjs.d.ts +++ b/winjs/winjs.d.ts @@ -8243,7 +8243,7 @@ declare module WinJS.Utilities { * @param element Optional. The root element at which to start the query. If this parameter is omitted, the scope of the query is the entire document. * @returns A QueryCollection with zero or one elements matching the specified selector query. **/ - function query(query: any, element: HTMLElement): QueryCollection; + function query(query: any, element?: HTMLElement): QueryCollection; /** * Ensures that the specified function executes only after the DOMContentLoaded event has fired for the current page. The DOMContentLoaded event occurs after the page has been parsed but before all the resources are loaded. From 63ae54c867e3123af911927e7b2eab4b7f89174c Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Sun, 27 Apr 2014 18:38:43 -0700 Subject: [PATCH 12/49] Added constructor support for QueryCollection interface --- winjs/winjs.d.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/winjs/winjs.d.ts b/winjs/winjs.d.ts index a2e95e557f..b5ded7a592 100644 --- a/winjs/winjs.d.ts +++ b/winjs/winjs.d.ts @@ -7905,17 +7905,6 @@ declare module WinJS.Utilities { * Represents the result of a query selector, and provides various operations that perform actions over the elements of the collection. **/ interface QueryCollection extends Array { - //#region Constructors - - /** - * Initializes a new instance of a QueryCollection. - * @constructor - * @param items The items resulting from the query. - **/ - constructor(items: T[]); - - //#endregion Constructors - //#region Methods /** @@ -8062,6 +8051,14 @@ declare module WinJS.Utilities { } + /** + * Constructor support for QueryCollection interface + **/ + export var QueryCollection: { + new (items: T[]): QueryCollection; + prototype: QueryCollection; + } + //#endregion Objects //#region Functions From ab899ff5c4eb8ae26bbbd230854543e1769540e9 Mon Sep 17 00:00:00 2001 From: Steve Taylor Date: Tue, 29 Apr 2014 11:07:42 +0930 Subject: [PATCH 13/49] Updated fullCalendar to 1.6.4. Fixed typos, cleaned up comment formatting and added some documentation links in comments. --- fullCalendar/fullCalendar.d.ts | 257 ++++++++++++++++++++++----------- 1 file changed, 172 insertions(+), 85 deletions(-) diff --git a/fullCalendar/fullCalendar.d.ts b/fullCalendar/fullCalendar.d.ts index fd1303f69e..84e6ee6cc1 100644 --- a/fullCalendar/fullCalendar.d.ts +++ b/fullCalendar/fullCalendar.d.ts @@ -7,29 +7,37 @@ declare module FullCalendar { export interface Calendar { + /** - * Formats a Date object into a string. - */ + * Formats a Date object into a string. + */ formatDate(date: Date, format: string, options?: Options): string; + /** - * Formats a date range (two Date objects) into a string. - */ + * Formats a date range (two Date objects) into a string. + */ formatDates(date1: Date, date2: Date, format: string, options?: Options): string; + /** - * Parses a string into a Date object. - */ + * Parses a string into a Date object. + */ parseDate(dateString: string, ignoreTimezone?: boolean): Date; + /** - * Parses an ISO8601 string into a Date object. - */ + * Parses an ISO8601 string into a Date object. + */ parseISO8601(dateString: string, ignoreTimezone?: boolean): Date; + /** - * Gets the version of Fullcalendar - */ + * Gets the version of Fullcalendar + */ version: string; } export interface Options { + + // General display - http://arshaw.com/fullcalendar/docs/display/ + header?: { left: string; center: string; @@ -43,22 +51,31 @@ declare module FullCalendar { firstDay?: number; isRTL?: boolean; weekends?: boolean; + hiddenDays?: number[]; weekMode?: string; weekNumbers?: boolean; weekNumberCalculation?: any; // String/Function height?: number; contentHeight?: number; - aspectRation?: number; - viewDisplay?: (view: View) => void; - windowResize?: (view: View) => void; + aspectRatio?: number; + handleWindowResize?: boolean; + viewRender?: (view: View, element: JQuery) => void; + viewDestroy?: (view: View, element: JQuery) => void; dayRender?: (date: Date, cell: HTMLTableDataCellElement) => void; + windowResize?: (view: View) => void; + + // Views - http://arshaw.com/fullcalendar/docs/views/ defaultView?: string; + // Current Date - http://arshaw.com/fullcalendar/docs/current_date/ + year?: number; month?: number; date?: number; + // Text/Time Customization - http://arshaw.com/fullcalendar/docs/text/ + timeFormat?: any; // String/ViewOptionHash columnFormat?: any; // String/ViewOptionHash titleFormat?: any; // String/ViewOptionHash @@ -69,11 +86,15 @@ declare module FullCalendar { dayNamesShort?: Array; weekNumberTitle?: number; + // Clicking & Hovering - http://arshaw.com/fullcalendar/docs/mouse/ + dayClick?: (date: Date, allDay: boolean, jsEvent: MouseEvent, view: View) => void; eventClick?: (event: EventObject, jsEvent: MouseEvent, view: View) => any; // return type boolean or void eventMouseover?: (event: EventObject, jsEvent: MouseEvent, view: View) => void; eventMouseout?: (event: EventObject, jsEvent: MouseEvent, view: View) => void; + // Selection - http://arshaw.com/fullcalendar/docs/selection/ + selectable?: any; // Boolean/ViewOptionHash selectHelper?: any; // Boolean/Function unselectAuto?: boolean; @@ -81,26 +102,51 @@ declare module FullCalendar { select?: (startDate: Date, endDate: Date, allDay: boolean, jsEvent: MouseEvent, view: View) => void; unselect?: (view: View, jsEvent: Event) => void; - eventSources?: Array; + // Event Data - http://arshaw.com/fullcalendar/docs/event_data/ + + /** + * This has one of the following types: + * + * - EventObject[] + * - string (JSON feed) + * - (start: Date, end: Date, callback: {(events: EventObject[]) => void;}) => void; + */ + events?: any; + + /** + * An array, each element being one of the following types: + * + * - EventSource + * - EventObject[] + * - string (JSON feed) + * - (start: Date, end: Date, callback: {(events: EventObject[]) => void;}) => void; + */ + eventSources?: any[]; + allDayDefault?: boolean; ignoreTimezone?: boolean; - eventDataTransform?: (eventData: any) => EventObject; startParam?: string; endParam?: string lazyFetching?: boolean; + eventDataTransform?: (eventData: any) => EventObject; loading?: (isLoading: boolean, view: View) => void; + // Event Rendering - http://arshaw.com/fullcalendar/docs/event_rendering/ + eventColor?: string; eventBackgroundColor?: string; eventBorderColor?: string; eventTextColor?: string; eventRender?: (event: EventObject, element: HTMLDivElement, view: View) => void; eventAfterRender?: (event: EventObject, element: HTMLDivElement, view: View) => void; - eventAllAfterRender?: (view: View) => void; + eventAfterAllRender?: (view: View) => void; + eventDestroy?: (event: EventObject, element: JQuery, view: View) => void; + + // Event Dragging & Resizing editable?: boolean; - disableDragging?: boolean; - disableResizing?: boolean; + eventStartEditable?: boolean; + eventDurationEditable?: boolean; dragRevertDuration?: number; dragOpacity?: any; // Float/ViewOptionHash eventDragStart?: (event: EventObject, jsEvent: MouseEvent, ui: any, view: View) => void; @@ -119,7 +165,7 @@ declare module FullCalendar { name: string; title: string; start: Date; - End: Date; + end: Date; visStart: Date; visEnd: Date; } @@ -137,6 +183,9 @@ declare module FullCalendar { ''?: any; } + /** + * Agenda Options - http://arshaw.com/fullcalendar/docs/agenda/ + */ export interface AgendaOptions { allDaySlot?: boolean; allDayText?: string; @@ -147,6 +196,7 @@ declare module FullCalendar { firstHour?: number; minTime?: any; // Integer/String maxTime?: any; // Integer/String + slotEventOverlap?: boolean; } export interface ButtonTextObject { @@ -177,7 +227,16 @@ declare module FullCalendar { } export interface EventSource extends JQueryAjaxSettings { + + /** + * This has one of the following types: + * + * - EventObject[] + * - string (JSON feed) + * - (start: Date, end: Date, callback: {(events: EventObject[]) => void;}) => void; + */ events?: any; + color?: string; backgroundColor?: string; borderColor?: string; @@ -194,117 +253,145 @@ declare module FullCalendar { } interface JQuery { + /** - * Get/Set option value - */ + * Get/Set option value + */ fullCalendar(method: 'option', option: string, value?: any): void; + /** - * Immediately forces the calendar to render and/or readjusts its size. - */ + * Immediately forces the calendar to render and/or readjusts its size. + */ fullCalendar(method: 'render'): void; + /** - * Restores the element to the state before FullCalendar was initialized. - */ + * Restores the element to the state before FullCalendar was initialized. + */ fullCalendar(method: 'destroy'): void; + /** - * Moves the calendar one step back (either by a month, week, or day). - */ - fullCalendar(method: 'prev'): void; - /** - * Moves the calendar one step forward (either by a month, week, or day). - */ - fullCalendar(method: 'next'): void; - /** - * Moves the calendar back one year. - */ - fullCalendar(method: 'prevYear'): void; - /** - * Moves the calendar forward one year. - */ - fullCalendar(method: 'nextYear'): void; - /** - * Moves the calendar to the current date. - */ - fullCalendar(method: 'today'): void; - /** - * Returns the View Object for the current view. - */ + * Returns the View Object for the current view. + */ fullCalendar(method: 'getView'): FullCalendar.View; + /** - * Immediately switches to a different view. - */ + * Immediately switches to a different view. + */ fullCalendar(method: 'changeView', viewName: string): void; + /** - * Moves the calendar to an arbitrary year/month/date. - */ + * Moves the calendar one step back (either by a month, week, or day). + */ + fullCalendar(method: 'prev'): void; + + /** + * Moves the calendar one step forward (either by a month, week, or day). + */ + fullCalendar(method: 'next'): void; + + /** + * Moves the calendar back one year. + */ + fullCalendar(method: 'prevYear'): void; + + /** + * Moves the calendar forward one year. + */ + fullCalendar(method: 'nextYear'): void; + + /** + * Moves the calendar to the current date. + */ + fullCalendar(method: 'today'): void; + + /** + * Moves the calendar to an arbitrary year/month/date. + */ fullCalendar(method: 'gotoDate', year: number, month?: number, date?: number): void; + /** - * Moves the calendar to an arbitrary date. - */ + * Moves the calendar to an arbitrary date. + */ fullCalendar(method: 'gotoDate', date: Date): void; + /** - * Moves the calendar forward/backward an arbitrary amount of time. - */ + * Moves the calendar forward/backward an arbitrary amount of time. + */ fullCalendar(method: 'incrementDate', year: number, month?: number, date?: number): void; + /** - * Returns a Date object for the current date of the calendar. - */ + * Returns a Date object for the current date of the calendar. + */ fullCalendar(method: 'getDate'): Date; + /** - * A method for programmatically selecting a period of time. - */ + * A method for programmatically selecting a period of time. + */ fullCalendar(method: 'select', startDate: Date, endDate: Date, allDay: boolean): void; + /** - * A method for programmatically clearing the current selection. - */ + * A method for programmatically clearing the current selection. + */ fullCalendar(method: 'unselect'): void; + /** - * Reports changes to an event and renders them on the calendar. - */ + * Reports changes to an event and renders them on the calendar. + */ fullCalendar(method: 'updateEvent', event: FullCalendar.EventObject): void; + /** - * Retrieves events that FullCalendar has in memory. - */ + * Retrieves events that FullCalendar has in memory. + */ fullCalendar(method: 'clientEvents', idOrfilter?: any): Array; + /** - * Retrieves events that FullCalendar has in memory. - */ + * Retrieves events that FullCalendar has in memory. + */ fullCalendar(method: 'clientEvents', idOrfilter?: (e: FullCalendar.EventObject) => boolean): Array; + /** - * Removes events from the calendar. - */ + * Removes events from the calendar. + */ fullCalendar(method: 'removeEvents', idOrfilter?: any): void; + /** - * Removes events from the calendar. - */ + * Removes events from the calendar. + */ fullCalendar(method: 'removeEvents', idOrfilter?: (e: FullCalendar.EventObject) => boolean): void; + /** - * Refetches events from all sources and rerenders them on the screen. - */ + * Refetches events from all sources and rerenders them on the screen. + */ fullCalendar(method: 'refetchEvents'): void; + /** - * Dynamically adds an event source. - */ + * Dynamically adds an event source. + */ fullCalendar(method: 'addEventSource', source: any): void; + /** - * Dynamically removes an event source. - */ + * Dynamically removes an event source. + */ fullCalendar(method: 'removeEventSource', source: any): void; + /** - * Renders a new event on the calendar. - */ + * Renders a new event on the calendar. + */ fullCalendar(method: 'renderEvent', event: FullCalendar.EventObject, stick?: boolean): void; + /** - * Rerenders all events on the calendar. - */ + * Rerenders all events on the calendar. + */ fullCalendar(method: 'rerenderEvents'): void; + /** - * Create calendar object - */ + * Create calendar object + */ fullCalendar(options: FullCalendar.Options): JQuery; + /** - * Generic method function - */ + * Generic method function + */ fullCalendar(method: string, arg1: any, arg2: any, arg3: any): void; } From cc3aeaae755173cfb0e0ab4cf84d424e40503876 Mon Sep 17 00:00:00 2001 From: Jared Reynolds Date: Tue, 29 Apr 2014 14:05:14 -0700 Subject: [PATCH 14/49] Added definitions for chai-datetime - Added explicit "any" types to chai definitions --- chai-datetime/chai-datetime-tests.ts | 47 ++++++++++++++++++++++++++++ chai-datetime/chai-datetime.d.ts | 33 +++++++++++++++++++ chai/chai.d.ts | 32 +++++++++---------- 3 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 chai-datetime/chai-datetime-tests.ts create mode 100644 chai-datetime/chai-datetime.d.ts diff --git a/chai-datetime/chai-datetime-tests.ts b/chai-datetime/chai-datetime-tests.ts new file mode 100644 index 0000000000..0b7ff729ff --- /dev/null +++ b/chai-datetime/chai-datetime-tests.ts @@ -0,0 +1,47 @@ +/// +/// +/// + +var expect = chai.expect; + +function test_equalTime(){ + var date: Date = new Date(2014, 1, 1); + expect(date).to.be.equalTime(date); + date.should.be.equalTime(date); + assert.equalTime(date, date); +} + +function test_beforeTime(){ + var date: Date = new Date(2014, 1, 1); + expect(date).to.be.beforeTime(date); + date.should.be.beforeTime(date); + assert.beforeTime(date, date); +} + +function test_afterTime(){ + var date: Date = new Date(2014, 1, 1); + expect(date).to.be.afterTime(date); + date.should.be.afterTime(date); + assert.afterTime(date, date); +} + +function test_equalDate(){ + var date: Date = new Date(2014, 1, 1); + expect(date).to.equalDate(date); + date.should.equalDate(date); + assert.equalDate(date, date); +} + +function test_beforeDate(){ + var date: Date = new Date(2014, 1, 1); + expect(date).to.beforeDate(date); + date.should.beforeDate(date); + assert.beforeDate(date, date); +} + +function test_afterDate(){ + var date: Date = new Date(2014, 1, 1); + expect(date).to.afterDate(date); + date.should.afterDate(date); + assert.afterDate(date, date); +} \ No newline at end of file diff --git a/chai-datetime/chai-datetime.d.ts b/chai-datetime/chai-datetime.d.ts new file mode 100644 index 0000000000..432f6bb247 --- /dev/null +++ b/chai-datetime/chai-datetime.d.ts @@ -0,0 +1,33 @@ +// Type definitions for chai-datetime +// Project: https://github.com/gaslight/chai-datetime.git +// Definitions by: Cliff Burger +// DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module chai { + + interface Expect { + afterDate(date: Date): boolean; + beforeDate(date: Date): boolean; + equalDate(date: Date): boolean; + + afterTime(date: Date): boolean; + beforeTime(date: Date): boolean; + equalTime(date: Date): boolean; + } + + interface Assert { + afterDate(leftDate: Date, rightDate: Date): boolean; + beforeDate(leftDate: Date, rightDate: Date): boolean; + equalDate(leftDate: Date, rightDate: Date): boolean; + + afterTime(leftDate: Date, rightDate: Date): boolean; + beforeTime(leftDate: Date, rightDate: Date): boolean; + equalTime(leftDate: Date, rightDate: Date): boolean; + } +} + +interface Date { + should: chai.Expect; +} diff --git a/chai/chai.d.ts b/chai/chai.d.ts index 7318744012..d840aba964 100644 --- a/chai/chai.d.ts +++ b/chai/chai.d.ts @@ -9,28 +9,28 @@ declare module chai { function expect(target: any, message?: string): Expect; // Provides a way to extend the internals of Chai - function use(fn: (chai: any, utils: any) => void); + function use(fn: (chai: any, utils: any) => void): any; interface ExpectStatic { (target: any): Expect; } interface Assertions { - attr(name, value?); - css(name, value?); - data(name, value?); - class(className); - id(id); - html(html); - text(text); - value(value); - visible; - hidden; - selected; - checked; - disabled; - empty; - exist; + attr(name: string, value?: string): any; + css(name: string, value?: string): any; + data(name: string, value?: string): any; + class(className: string): any; + id(id: string): any; + html(html: string): any; + text(text: string): any; + value(value: string): any; + visible: any; + hidden: any; + selected: any; + checked: any; + disabled: any; + empty: any; + exist: any; } interface Expect extends LanguageChains, NumericComparison, TypeComparison, Assertions { From b7d67743e7d6aacdc8313164d9fcc9455a332aac Mon Sep 17 00:00:00 2001 From: Roland Zwaga Date: Wed, 30 Apr 2014 10:28:02 +0200 Subject: [PATCH 15/49] added definitions for missing ngGrid interfaces and created tests for them --- ng-grid/ng-grid-tests.ts | 277 +++++++++++++++++++++++++- ng-grid/ng-grid.d.ts | 418 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 689 insertions(+), 6 deletions(-) diff --git a/ng-grid/ng-grid-tests.ts b/ng-grid/ng-grid-tests.ts index 53763b1a51..d636753ba0 100644 --- a/ng-grid/ng-grid-tests.ts +++ b/ng-grid/ng-grid-tests.ts @@ -1,4 +1,5 @@ -/// +/// +/// var options1: ngGrid.IGridOptions = { data: [{ 'Name': 'Bob' }, { 'Name': 'Jane' }] @@ -25,3 +26,277 @@ var options4: ngGrid.IGridOptions = { currentPage: 1 } }; + +var columnDef: ngGrid.IColumnDef = { + width:{}, + minWidth:{}, + visible:false, + field:'', + displayName:'', + sortable:false, + resizable:false, + groupable:false, + pinnable:false, + editableCellTemplate:'', + enableCellEdit:false, + cellEditableCondition:'', + sortFn:(a:any, b:any):number=> { return 0 }, + cellTemplate:'', + cellClass:'', + headerClass:'', + headerCellTemplate:'', + cellFilter:'', + aggLabelFilter:'', + pinned:false +} + +var searchProvider: ngGrid.ISearchProvider = {}; +searchProvider.fieldMap = {}; +searchProvider.extFilter = false; +searchProvider.evalFilter(); + +var nr:number; + +var selectionProvider: ngGrid.ISelectionProvider = {}; +selectionProvider.multi = false; +selectionProvider.selectedItems = []; +selectionProvider.selectedIndex = 1; +selectionProvider.lastClickedRow = {}; +selectionProvider.ignoreSelectedItemChanges = false; +selectionProvider.pKeyParser = {}; +selectionProvider.ChangeSelection({}, {}); +nr = selectionProvider.getSelection({}); +nr = selectionProvider.getSelectionIndex({}); +selectionProvider.setSelection({}, false); +selectionProvider.toggleSelectAll(true, false, false); + +var eventProvider: ngGrid.IEventProvider = {}; +eventProvider.colToMove = {}; +eventProvider.groupToMove = {}; +eventProvider.assignEvents(); +eventProvider.assignGridEventHandlers(); +eventProvider.dragStart({}); +eventProvider.dragOver({}); +eventProvider.setDraggables(); +eventProvider.onGroupMouseDown({}); +eventProvider.onGroupDrop({}); +eventProvider.onHeaderMouseDown({}); +eventProvider.onHeaderDrop({}); + +var aggregate: ngGrid.IAggregate = {}; +aggregate.rowIndex = 0; +aggregate.offsetTop = 0; +aggregate.entity = {}; +aggregate.label = ''; +aggregate.field = ''; +aggregate.depth = 0; +aggregate.parent = {}; +aggregate.children = []; +aggregate.aggChildren = []; +aggregate.aggIndex = 0; +aggregate.collapsed = false; +aggregate.groupInitState = false; +aggregate.rowFactory = {}; +aggregate.rowHeight = 0; +aggregate.isAggRow = false; +aggregate.offsetLeft = 0; +aggregate.aggLabelFilter = {}; + +var rowConfig: ngGrid.IRowConfig = {}; +rowConfig.enableCellSelection = false; +rowConfig.enableRowSelection = false; +rowConfig.jqueryUITheme = false; +rowConfig.rowClasses = ['']; +rowConfig.rowHeight = 0; +rowConfig.selectWithCheckboxOnly = false; +rowConfig.selectedItems = []; +rowConfig.afterSelectionChangeCallback(); +rowConfig.beforeSelectionChangeCallback(); + +var renderedRange: ngGrid.IRenderedRange = {}; +renderedRange.bottomRow = 0; +renderedRange.topRow = 0; + +var rowFactory: ngGrid.IRowFactory = {}; +rowFactory.aggCache= null; +rowFactory.dataChanged= false; +rowFactory.groupedData= null; +rowFactory.numberOfAggregates = 0; +rowFactory.parentCache= []; +rowFactory.parsedData= []; +rowFactory.renderedRange = {}; +rowFactory.rowConfig = {}; +rowFactory.rowHeight = 0; +rowFactory.selectionProvider = {}; +rowFactory.UpdateViewableRange({}); +aggregate = rowFactory.buildAggregateRow({}, 0); +var row:ngGrid.IRow = rowFactory.buildEntityRow({}, 0); +rowFactory.filteredRowsChanged(); +rowFactory.fixRowCache(); +rowFactory.getGrouping({}); +rowFactory.parseGroupData({}); +rowFactory.renderedChange(); +rowFactory.renderedChangeNoGroups(); + +var dimension: ngGrid.IDimension = {}; +dimension.outerHeight = 0; +dimension.outerWidth = 0; +dimension.autoFitHeight = false; + +var elmDimension: ngGrid.IElementDimension = {}; +elmDimension.rootMaxH = 0; +elmDimension.rootMaxW = 0; +elmDimension.rowIndexCellW = 0; +elmDimension.rowSelectedCellW = 0; +elmDimension.scrollH = 0; +elmDimension.scrollW = 0; + +var row: ngGrid.IRow = {}; +row.entity= {}; +row.config = {}; +row.selectionProvider = {}; +row.rowIndex = 0; +row.utils= {}; +row.selected = false; +row.cursor = ''; +row.offsetTop = 0; +row.rowDisplayIndex = 0; +row.afterSelectionChange(); +row.beforeSelectionChange(); +row.setSelection(false); +row.continueSelection({}); +row.ensureEntity({}); +var b:boolean = row.toggleSelected({}); +row.alternatingRowClass(); +var a:any = row.getProperty(''); +var r:ngGrid.IRow = row.copy(); +row.setVars({}); + +var column: ngGrid.IColumn = {}; +column.colDef = {}; +column.width = 0; +column.groupIndex = 0; +column.isGroupedBy = false; +column.minWidth = 0; +column.maxWidth = 0; +column.enableCellEdit = false; +column.cellEditableCondition = {}; +column.headerRowHeight = 0; +column.displayName = ''; +column.index = 0; +column.isAggCol = false; +column.cellClass = ''; +column.sortPriority = 0; +column.cellFilter = {}; +column.field = ''; +column.aggLabelFilter = {}; +column.visible = false; +column.sortable = false; +column.resizable = false; +column.pinnable = false; +column.pinned = false; +column.originalIndex = 0; +column.groupable = false; +column.sortDirection = ''; +column.sortingAlgorithm = ()=>{}; +column.headerClass = ''; +column.cursor = ''; +column.headerCellTemplate = ''; +column.cellTemplate = ''; +var s:string = column.groupedByClass(); +column.toggleVisible(); +b = column.showSortButtonUp(); +b = column.showSortButtonDown(); +b = column.noSortVisible(); +b = column.sort({}); +a = column.gripClick(); +a = column.gripOnMouseDown({}); +column.onMouseMove({}); +column.gripOnMouseUp({}); +var c:ngGrid.IColumn = column.copy(); +column.setVars(c); + +var gridScope: ngGrid.IGridScope = {}; +gridScope.elementsNeedMeasuring = false; +gridScope.columns = []; +gridScope.renderedRows = []; +gridScope.renderedColumns = []; +gridScope.headerRow = {}; +gridScope.rowHeight = 0; +gridScope.jqueryUITheme = {}; +gridScope.showSelectionCheckbox = false; +gridScope.enableCellSelection = false; +gridScope.enableCellEditOnFocus = false; +gridScope.footer = {}; +gridScope.selectedItems = []; +gridScope.multiSelect = false; +gridScope.showFooter = false; +gridScope.footerRowHeight = 0; +gridScope.showColumnMenu = false; +gridScope.forceSyncScrolling = false; +gridScope.showMenu = false; +gridScope.configGroups = []; +gridScope.gridId = ''; +gridScope.enablePaging = false; +gridScope.pagingOptions = {}; +gridScope.i18n = {}; +gridScope.selectionProvider = {}; +gridScope.adjustScrollLeft(0); +gridScope.adjustScrollTop(0, true); +gridScope.toggleShowMenu(); +gridScope.toggleSelectAll(); +nr = gridScope.totalFilteredItemsLength(); +a = gridScope.showGroupPanel(); +nr = gridScope.topPanelHeight(); +nr = gridScope.viewportDimHeight(); +gridScope.groupBy({}); +gridScope.removeGroup(0); +gridScope.togglePin({}); +nr = gridScope.totalRowWidth(); +a = gridScope.headerScrollerDim(); + +var gridInstance: ngGrid.IGridInstance = {}; +gridInstance.$canvas = {}; +gridInstance.$viewport = {}; +gridInstance.$groupPanel = {}; +gridInstance.$footerPanel = {}; +gridInstance.$headerScroller = {}; +gridInstance.$headerContainer = {}; +gridInstance.$headers = {}; +gridInstance.$topPanel = {}; +gridInstance.$root = {}; +gridInstance.config = {}; +gridInstance.data = {}; +gridInstance.elementDims = {}; +gridInstance.eventProvider = {}; +gridInstance.filteredRows = [{}]; +gridInstance.footerController = {}; +gridInstance.gridId = ''; +gridInstance.lastSortedColumns = [{}]; +gridInstance.lateBindColumns = false; +gridInstance.maxCanvasHt = 0; +gridInstance.prevScrollIndex = 0; +gridInstance.prevScrollTop = 0; +gridInstance.rootDim = {}; +gridInstance.rowCache = [{}]; +gridInstance.rowFactory = {}; +gridInstance.rowMap = [{}]; +gridInstance.searchProvider = {}; +gridInstance.styleProvider = {}; +gridInstance.buildColumnDefsFromData(); +gridInstance.buildColumns(); +gridInstance.calcMaxCanvasHeight(); +gridInstance.clearSortingData(); +gridInstance.configureColumnWidths(); +gridInstance.fixColumnIndexes(); +gridInstance.fixGroupIndexes(); +var p:ng.IPromise = gridInstance.getTemplate(''); +p = gridInstance.init(); +p = gridInstance.initTemplates(); +gridInstance.minRowsToRender(); +gridInstance.refreshDomSizes(); +gridInstance.resizeOnData({}); +gridInstance.setRenderedRows([{}]); +gridInstance.sortActual(); +gridInstance.sortColumnsInit(); +gridInstance.sortData({}, {}); \ No newline at end of file diff --git a/ng-grid/ng-grid.d.ts b/ng-grid/ng-grid.d.ts index 70f4f569f8..dbf3666b4e 100644 --- a/ng-grid/ng-grid.d.ts +++ b/ng-grid/ng-grid.d.ts @@ -1,23 +1,318 @@ // Type definitions for ng-grid // Project: http://angular-ui.github.io/ng-grid/ -// Definitions by: Ken Smith +// Definitions by: Ken Smith and Roland Zwaga and Kent Cooper // DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped // These are very definitely preliminary. Please feel free to improve. +// Changelog: +// 25/4/2014: Added interfaces for all classes and services + +/// + declare class ngGridReorderable { constructor(); } declare module ngGrid { + export interface IDomAccessProvider { + previousColumn:IColumn; + grid:IGridInstance; + changeUserSelect(elm:ng.IAugmentedJQuery, value:string):void; + focusCellElement($scope:IGridScope, index:number):void; + selectionHandlers($scope:IGridScope, elm:ng.IAugmentedJQuery):void; + } + + export interface IStyleProvider { + new($scope:IGridScope, grid:IGridInstance):IStyleProvider; + } + + export interface ISearchProvider { + new($scope:IGridScope, grid:IGridInstance, $filter:ng.IFilterService):ISearchProvider; + fieldMap:any; + extFilter:boolean; + evalFilter():void; + } + + export interface ISelectionProvider { + new(grid:IGridInstance, $scope:IGridScope, $parse:ng.IParseService):ISelectionProvider; + multi:boolean; + selectedItems:any[]; + selectedIndex:number; + lastClickedRow:any; + ignoreSelectedItemChanges:boolean; + pKeyParser:ng.ICompiledExpression; + ChangeSelection(rowItem:any, event:any):void; + getSelection(entity:any):number; + getSelectionIndex(entity:any):number; + setSelection(rowItem:IRow, isSelected:boolean):void; + toggleSelectAll(checkAll:boolean, bypass:boolean, selectFiltered:boolean):void; + } + + export interface IEventProvider { + new(grid:IGridInstance, $scope:IGridScope, domUtilityService:any, $timeout:ng.ITimeoutService):IEventProvider; + colToMove:IColumn; + groupToMove:any; + assignEvents():void; + assignGridEventHandlers():void; + dragStart(event:any):void; + dragOver(event:any):void; + setDraggables():void; + onGroupMouseDown(event:any):void; + onGroupDrop(event:any):void; + onHeaderMouseDown(event:any):void; + onHeaderDrop(event:any):void; + } + + + export interface IAggregate { + new(aggEntity:any, rowFactory:IRowFactory, rowHeight:number, groupInitState:boolean):IAggregate; + rowIndex:number; + offsetTop:number; + entity:any; + label:string; + field:string; + depth:number; + parent:any; + children:any[]; + aggChildren:any[]; + aggIndex:number; + collapsed:boolean; + groupInitState:boolean; + rowFactory:IRowFactory; + rowHeight:number; + isAggRow:boolean; + offsetLeft:number; + aggLabelFilter:any; + } + + export interface IRowConfig { + enableCellSelection:boolean; + enableRowSelection:boolean; + jqueryUITheme:boolean; + rowClasses:string[]; + rowHeight:number; + selectWithCheckboxOnly:boolean; + selectedItems:any[]; + + afterSelectionChangeCallback():void; + beforeSelectionChangeCallback():void; + } + + export interface IRenderedRange { + new(top:number, bottom:number):IRenderedRange; + bottomRow:number; + topRow:number; + } + + export interface IRowFactory { + aggCache:any; + dataChanged:boolean; + groupedData:any; + numberOfAggregates:number; + parentCache:any[]; + parsedData:any[]; + renderedRange:IRenderedRange; + rowConfig:IRowConfig; + rowHeight:number; + selectionProvider:ISelectionProvider; + + UpdateViewableRange(newRange:IRenderedRange):void; + buildAggregateRow(aggEntity:any, rowIndex:number):IAggregate; + buildEntityRow(entity:any, rowIndex:number):IRow; + filteredRowsChanged():void; + fixRowCache():void; + getGrouping(groups:any):void; + parseGroupData(groupData:any):void; + renderedChange():void; + renderedChangeNoGroups():void; + } + + export interface IDimension { + new(options:any):IDimension; + outerHeight?:number; + outerWidth?:number; + autoFitHeight?:boolean; + } + + export interface IElementDimension { + rootMaxH?:number; + rootMaxW?:number; + rowIndexCellW?:number; + rowSelectedCellW?:number; + scrollH?:number; + scrollW?:number; + } + + export interface IRow { + new(entity:any, config:IRowConfig, selectionProvider:ISelectionProvider, rowIndex:number, $utils:any):IRow; + entity:any; + config:IRowConfig; + selectionProvider:ISelectionProvider; + rowIndex:number; + utils:any; + selected:boolean; + cursor:string; + offsetTop:number; + rowDisplayIndex:number; + afterSelectionChange():void; + beforeSelectionChange():void; + setSelection(isSelected:boolean):void; + continueSelection(event:any):void; + ensureEntity(expected:any):void; + toggleSelected(event:any):boolean; + alternatingRowClass():void; + getProperty(path:string):any; + copy():IRow; + setVars(fromRow:IRow):void; + } + + export interface IColumn { + new(config:IGridOptions, $scope:IGridScope, grid:IGridInstance, domUtilityService:any, $templateCache:ng.ITemplateCacheService, $utils:any):IColumn; + colDef:IColumnDef; + width:number; + groupIndex:number; + isGroupedBy:boolean; + minWidth:number; + maxWidth:number; + enableCellEdit:boolean; + cellEditableCondition:any; + headerRowHeight:number; + displayName:string; + index:number; + isAggCol:boolean; + cellClass:string; + sortPriority:number; + cellFilter:any; + field:string; + aggLabelFilter:any; + visible:boolean; + sortable:boolean; + resizable:boolean; + pinnable:boolean; + pinned:boolean; + originalIndex:number; + groupable:boolean; + sortDirection:string; + sortingAlgorithm:Function; + headerClass:string; + cursor:string; + headerCellTemplate:string; + cellTemplate:string; + groupedByClass():string; + toggleVisible():void; + showSortButtonUp():boolean; + showSortButtonDown():boolean; + noSortVisible():boolean; + sort(event:any):boolean; + gripClick():any; + gripOnMouseDown(event:any):any; + onMouseMove(event:any):void; + gripOnMouseUp(event:any):void; + copy():IColumn; + setVars(fromCol:IColumn):void; + } + + export interface IGridScope extends ng.IScope { + elementsNeedMeasuring:boolean; + columns:any[]; + renderedRows:any[]; + renderedColumns:any[]; + headerRow:any; + rowHeight:number; + jqueryUITheme:any; + showSelectionCheckbox:boolean; + enableCellSelection:boolean; + enableCellEditOnFocus:boolean; + footer:IFooter; + selectedItems:any[]; + multiSelect:boolean; + showFooter:boolean; + footerRowHeight:number; + showColumnMenu:boolean; + forceSyncScrolling:boolean; + showMenu:boolean; + configGroups:any[]; + gridId:string; + enablePaging:boolean; + pagingOptions:IPagingOptions; + i18n:any; + selectionProvider:ISelectionProvider; + adjustScrollLeft(scrollLeft:number):void; + adjustScrollTop(scrollTop:number, force:boolean):void; + toggleShowMenu():void; + toggleSelectAll():void; + totalFilteredItemsLength():number; + showGroupPanel():any; + topPanelHeight():number; + viewportDimHeight():number; + groupBy(col:IColumn):void; + removeGroup(index:number):void; + togglePin(col:IColumn):void; + totalRowWidth():number; + headerScrollerDim():any; + } + + export interface IGridInstance { + $canvas:ng.IAugmentedJQuery; + $viewport:ng.IAugmentedJQuery; + $groupPanel:ng.IAugmentedJQuery; + $footerPanel:ng.IAugmentedJQuery; + $headerScroller:ng.IAugmentedJQuery; + $headerContainer:ng.IAugmentedJQuery; + $headers:ng.IAugmentedJQuery; + $topPanel:ng.IAugmentedJQuery; + $root:ng.IAugmentedJQuery; + config:IGridOptions; + data:any; + elementDims:IElementDimension; + eventProvider:IEventProvider; + filteredRows:IRow[]; + footerController:any; + gridId:string; + lastSortedColumns:IColumn[]; + lateBindColumns:boolean; + maxCanvasHt:number; + prevScrollIndex:number; + prevScrollTop:number; + rootDim:IDimension; + rowCache:IRow[]; + rowFactory:IRowFactory; + rowMap:IRow[]; + searchProvider:ISearchProvider; + styleProvider:IStyleProvider; + + buildColumnDefsFromData():void; + buildColumns():void; + calcMaxCanvasHeight():void; + clearSortingData():void; + configureColumnWidths():void; + fixColumnIndexes():void; + fixGroupIndexes():void; + getTemplate(key:string):ng.IPromise; + init():ng.IPromise; + initTemplates():ng.IPromise; + minRowsToRender():void; + refreshDomSizes():void; + resizeOnData(col:IColumn):void; + setRenderedRows(newRows:IRow[]):void; + sortActual():void; + sortColumnsInit():void; + sortData(col:IColumn, event:any):void; + } + + export interface IFooter { + new($scope:IGridScope, grid:IGridInstance):IFooter; + } + export interface IGridOptions { /** Define an aggregate template to customize the rows when grouped. See github wiki for more details. */ aggregateTemplate?: string; /** Callback for when you want to validate something after selection. */ - afterSelectionChange?: (rowItem?: any, event?: any) => void ; + afterSelectionChange?: (rowItem?: IRow, event?: any) => void ; /** Callback if you want to inspect something before selection, return false if you want to cancel the selection. return true otherwise. @@ -25,7 +320,7 @@ declare module ngGrid { use rowItem.changeSelection(event) method after returning false initially. Note: when shift+ Selecting multiple items in the grid this will only get called once and the rowItem will be an array of items that are queued to be selected. */ - beforeSelectionChange?: (rowItem?: any, event?: any) => boolean ; + beforeSelectionChange?: (rowItem?: IRow, event?: any) => boolean ; /** checkbox templates. */ checkboxCellTemplate?: string; @@ -176,11 +471,68 @@ declare module ngGrid { } export interface IColumnDef { + /** + * This can be an absolute numberor it can also be defined in percentages (20%, 30%), + * in weighted *s, or "auto" (which sizes the column based on data length) + * (much like WPF/Silverlight)/ note: "auto" only works in single page apps currently because the re-size + * happens on "document.ready + */ + width?: any; + + /** The minum width the column is allowed to be. See width for the different options */ + minWidth?: any; + + /** Set the default visiblity of the column */ + visible?: boolean; + + /** Can also be a property path on your data model. "foo.bar.myField", "Name.First", etc..*/ field?: string; - width?: any; //**this can be a string containing a relatively, absolute size units or a number: '30%','54px',45 /* + + /** What to display in the column header */ displayName?: string; - cellTemplate?: string; + + /** Restrict or allow the column to be sorted */ + sortable?: boolean; + + /** Restrict or allow the column to be resized */ + resizable?: boolean; + + /** Allows the column to be grouped with drag and drop, but has no effect on gridOptions.groups */ + groupable?: boolean; + + /** Allows the column to be pinned when enablePinning is set to true */ + pinnable?: boolean; + + /** The template to use while editing */ + editableCellTemplate?: string; + + /** Allows the cell to use an edit template when focused (grid option enableCellSelection must be enabled)*/ enableCellEdit?: boolean; + + /** Controls when to use the edit template on per-row basis using an angular expression (enableCellEdit must also be true for editing)*/ + cellEditableCondition?: string; + + /** The funtion to use when filtering values in this column */ + sortFn?: (a: any, b: any) => number; + + /** Html template used to render the cell */ + cellTemplate?: string; + + /** User defined CSS class name */ + cellClass?: string; + + /** User defined CSS class name for the header cell */ + headerClass?: string; + + /** Html template used to render the header cell */ + headerCellTemplate?: string; + + /** string name for filter to use on the cell ('currency', 'date', etc..) */ + cellFilter?: string; + + /** String name for filter to use on the aggregate label ('currency', 'date', etc..) defaults to cellFilter if not set. */ + aggLabelFilter?: string; + pinned?: boolean; } @@ -199,4 +551,60 @@ declare module ngGrid { /** currentPage: the uhm... current page. */ currentPage?: number; } + + export interface IPlugin { + init(childScope:IGridScope, gridInstance:IGridInstance, services:any):void; + } + + export module service { + + export interface IDomUtilityService { + eventStorage:any; + numberOfGrids:number; + immediate:number; + AssignGridContainers($scope:IGridScope, rootel:ng.IAugmentedJQuery, grid:IGridInstance):void; + getRealWidth(obj:IDimension):number; + UpdateGridLayout($scope:IGridScope, grid:IGridInstance):void; + setStyleText(grid:IGridInstance, css:string):void; + BuildStyles($scope:IGridScope, grid:IGridInstance, digest:boolean):void; + setColLeft(col:IColumn, colLeft:number, grid:IGridInstance):void; + RebuildGrid($scope:IGridScope, grid:IGridInstance):void; + digest($scope:IGridScope):void; + ScrollH:number; + ScrollW:number; + LetterW:number; + } + + export interface ISortInfo { + fields:string[]; + } + + export interface ISortService { + colSortFnCache:any; + isCustomSort:boolean; + isSorting:boolean; + guessSortFn(item:any):(a:any, b:any)=>number; + basicSort(a:any, b:any):number; + sortNumber(a:number, b:number):number; + sortNumberStr(a:string, b:string):number; + sortAlpha(a:string, b:string):number; + sortDate(a:Date, b:Date):number; + sortBool(a:boolean, b:boolean):number; + sortData(sortInfo:ISortInfo, data:any):void; + Sort(sortInfo:ISortInfo, data:any):void; + getSortFn(col:IColumn, data:any):(a:any, b:any)=>number; + } + + export interface IUtilityService { + visualLength(node:any):number; + forIn(obj:any, action:(value:any, property:string)=>{}):void; + evalProperty(entity:any, path:string):any; + endsWith(str:string, suffix:string):boolean; + isNullOrUndefined(obj:any):boolean; + getElementsByClassName(cl:string):any[]; + newId():string; + seti18n($scope:IGridScope, language:string):void; + getInstanceType(o:any):string; + } + } } From 0a86e768900ecc778df194303167266d28e08e56 Mon Sep 17 00:00:00 2001 From: Horiuchi_H Date: Thu, 1 May 2014 19:41:46 +0900 Subject: [PATCH 16/49] add mongoose type file --- mongoose/mongoose-tests.ts | 366 ++++++++++++++++++++++++++++++ mongoose/mongoose.d.ts | 453 +++++++++++++++++++++++++++++++++++++ 2 files changed, 819 insertions(+) create mode 100644 mongoose/mongoose-tests.ts create mode 100644 mongoose/mongoose.d.ts diff --git a/mongoose/mongoose-tests.ts b/mongoose/mongoose-tests.ts new file mode 100644 index 0000000000..38c469ca15 --- /dev/null +++ b/mongoose/mongoose-tests.ts @@ -0,0 +1,366 @@ +/// + +var fs = require('fs'); +import mongoose = require('mongoose'); + +var createInstance = new mongoose.Mongoose(); + +var Schema = mongoose.Schema; +var CreateSchema = new Schema({}); + +mongoose.connect('mongodb://user:pass@localhost:port/database'); +mongoose.connect('mongodb://hostA:27501,hostB:27501', { mongos: true }); + +var conn: mongoose.Connection = mongoose.createConnection('mongodb://user:pass@localhost:port/database'); +conn = mongoose.createConnection('mongodb://user:pass@localhost:port/database,mongodb://anotherhost:port,mongodb://yetanother:port', { replset: { strategy: 'ping', rs_name: 'testSet' }}); +conn = mongoose.createConnection('localhost', 'database', 27014); +conn = mongoose.createConnection('localhost', 'database', 27014, { server: { auto_reconnect: false }, user: 'username', pass: 'mypassword' }); +conn = mongoose.createConnection(); +conn.open('localhost', 'database', 27014, {}); + +var db = mongoose.createConnection(); +db.openSet("mongodb://user:pwd@localhost:27020/testing,mongodb://example.com:27020,mongodb://localhost:27019"); +db.openSet('mongodb://mongosA:27501,mongosB:27501', 'db', { mongos: true }, (err: any) => {}); +db.close(); + +var collection = db.collection('collection1'); + +mongoose.connection.on('error', (err: any) => {}); +mongoose.disconnect(); + +mongoose.set('test', 1234567890); +var value = mongoose.get('test'); +mongoose.set('debug', true); + +interface IActor extends mongoose.Document { + name: string; +} +mongoose.model('Actor', new Schema({ name: String })); +db.model('Actor', new Schema({ name: String })); +var schema: mongoose.Schema = new Schema({ name: String }, { collection: 'actor' }); +schema.set('collection', 'actor'); +var Model = mongoose.model('Actor', schema, 'actor'); + +var names: string[] = mongoose.modelNames(); +var names: string[] = db.modelNames(); +mongoose.plugin((schema: mongoose.Schema) => { +}, { index: true }); + + +var aggregate = new mongoose.Aggregate(); +var aggregate = new mongoose.Aggregate({ $project: { a: 1, b: 1 } }); +var aggregate = new mongoose.Aggregate({ $project: { a: 1, b: 1 } }, { $skip: 5 }); +var aggregate = new mongoose.Aggregate([{ $project: { a: 1, b: 1 } }, { $skip: 5 }]); +aggregate.append({ $project: { field: 1 }}, { $limit: 2 }); +aggregate.append([{ $match: { daw: 'Logic Audio X' }} ]); +aggregate.group({ _id: "$department" }); +aggregate.skip(10); +aggregate.limit(10); +aggregate.match({ department: { $in: [ "sales", "engineering" ] } }); +aggregate.near({ + near: [40.724, -73.997], + distanceField: "dist.calculated", // required + maxDistance: 0.008, + query: { type: "public" }, + includeLocs: "dist.location", + uniqueDocs: true, + num: 5 +}); +aggregate.project("a b -_id"); +aggregate.project({a: 1, b: 1, _id: 0}); +aggregate.project({ + newField: '$b.nested', + plusTen: { $add: ['$val', 10]}, + sub: { + name: '$a' + } +}); +aggregate.project({ salary_k: { $divide: [ "$salary", 1000 ] } }); +aggregate.sort({ field: 'asc', test: -1 }); +aggregate.sort('field -test'); +aggregate.unwind("tags"); +aggregate.unwind("a", "b", "c"); +var p = aggregate.exec(); +aggregate.read('primaryPreferred').exec((err: any, result: {}) => {}); + + +var p = new mongoose.Promise; +var p2 = p.then(function() { throw new Error('shucks') }).end(); +setTimeout(function() { + p.fulfill({}); +}, 10); +var promise = new mongoose.Promise(); +promise.then(function (meetups: number) { + return new mongoose.Promise(); +}).then(function (people: string[]) { + if (people.length < 10000) { + throw new Error('Too few people!!!'); + } else { + throw new Error('Still need more people!!!'); + } +}).then(null, function (err: Error) { +}).end(); + + +Model.findOne({ name: 'john' }, (err: any, doc: mongoose.Document) => { + doc.invalidate('size', 'must be less than 20', 14); + doc.validate((err: any) => { }); + + doc.set('documents.0.title', 'changed'); + doc.get('documents.0'); + doc.set({ + 'path' : 1, + 'path2' : { + 'path' : 2 + } + }); + doc.set('path', 'value', { strict: false }); + doc.set('path3', '1', Number); + doc.get('path3', Number); + doc.id; + doc._id; + + doc.isModified(); + doc.isModified('documents'); + doc.isModified('documents.0.title'); + doc.isDirectModified('documents.0.title'); + doc.isDirectModified('documents'); + doc.isSelected('name'); + + doc.markModified('mixed.type'); + doc.populate('user'); + doc.populate('other', (err: any, doc: mongoose.Document) => {}); + doc.populated('author'); + doc.save(); + + doc.toJSON({ getters: true, virtuals: false }); + var data: any = doc.toObject(); + delete data['age']; + delete data['weight']; + data['isAwesome'] = true; +}); + +Model.model('User').findById('id', (err: any, res: IActor) => {}); +Model.count({ type: 'jungle' }, (err: any, count: number) => {}); +Model.remove((err: any, res: IActor[]) => {}); +Model.save((err: any, res: IActor, numberAffected: number) => {}); +Model.create({ type: 'jelly bean' }, { type: 'snickers' }, (err: any, res1: IActor, res2: IActor) => {}); +Model.create({ type: 'jawbreaker' }); +Model.distinct('url', { clicks: {$gt: 100}}, (err: any, result: IActor[]) => {}); +Model.distinct('url'); + +Model.aggregate( + { $group: { _id: null, maxBalance: { $max: '$balance' }}}, + { $project: { _id: 0, maxBalance: 1 }}, + (err: any, res: IActor[]) => {}); +Model.aggregate() + .group({ _id: null, maxBalance: { $max: '$balance' } }) + .select('-id maxBalance') + .exec((err: any, res: IActor[]) => {}); +Model.ensureIndexes((err) => {}); + +Model.find({ name: 'john', age: { $gte: 18 }}); +Model.find({ name: 'john', age: { $gte: 18 }}, (err: any, docs: IActor[]) => {}); +Model.find({ name: /john/i }, 'name friends', (err: any, docs: IActor[]) => {}); +Model.find({ name: /john/i }, null, { skip: 10 }); +Model.find({ name: /john/i }, null, { skip: 10 }, (err: any, docs: IActor[]) => {}); +Model.find({ name: /john/i }, null, { skip: 10 }).exec((err: any, docs: IActor[]) => {}); +var query = Model.find({ name: /john/i }, null, { skip: 10 }); +var promise1 = query.exec(); +promise1.addBack((err: any, docs: IActor[]) => {}); + +Model.findById('id', (err: any, res: IActor) => {}); +Model.findById('id').exec((err: any, res: IActor) => {}); +Model.findById('id', 'name length', (err: any, res: IActor) => {}); +Model.findById('id', '-length').exec((err: any, res: IActor) => {}); +Model.findById('id', 'name', { lean: true }, (err: any, res: IActor) => {}); +Model.findById('id', 'name').lean().exec((err: any, res: IActor) => {}); +Model.findByIdAndRemove('id1', { select: 'name' }, (err: any, res: IActor) => {}); +Model.findByIdAndRemove('id1', { select: 'name' }).exec((err: any, res: IActor) => {}); +Model.findByIdAndRemove('id1', (err: any, res: IActor) => {}); +Model.findByIdAndRemove('id1').exec((err: any, res: IActor) => {}); +Model.findByIdAndUpdate('id2', { $set: { name: 'jason borne' }}, { upsert: true }, (err: any, res: IActor) => {}); + +Model.findOne({ type: 'iphone' }, (err: any, res: IActor) => {}); +Model.findOne({ type: 'iphone' }).exec((err: any, res: IActor) => {}); +Model.findOne({ type: 'iphone' }, 'name', (err: any, res: IActor) => {}); +Model.findOne({ type: 'iphone' }, 'name').exec((err: any, res: IActor) => {}); +Model.findOne({ type: 'iphone' }, 'name', { lean: true }, (err: any, res: IActor) => {}); +Model.findOne({ type: 'iphone' }, 'name', { lean: true }).exec((err: any, res: IActor) => {}); +Model.findOne({ type: 'iphone' }).select('name').lean().exec((err: any, res: IActor) => {}); +Model.findOneAndRemove({ type: 'iphone' }, { select: 'name' }, (err: any, res: IActor) => {}); +Model.findOneAndRemove({ type: 'iphone' }, { select: 'name' }).exec((err: any, res: IActor) => {}); +Model.findOneAndUpdate({ type: 'iphone' }, { $set: { name: 'jason borne' }}, { upsert: true }, (err: any, res: IActor) => {}); + +Model.geoNear([1, 3], { maxDistance : 5, spherical : true }, (err: any, res: IActor[]) => {}); +Model.geoNear({ type : "Point", coordinates : [9,9] }, { maxDistance : 5, spherical : true }, (err: any, res: IActor[]) => {}); +Model.geoSearch({ type : "house" }, { near: [10, 10], maxDistance: 5 }, (err: any, res: IActor[]) => {}); + +var o = { + map: function () { this.emit(this.name, 1) }, + reduce: function (k: string, vals: IActor[]) { return vals.length }, +}; +Model.mapReduce(o, (err: any, res: any[]) => {}); + +Model.findById('id', (err: any, res: IActor) => { + var opts = [ + { path: 'company', match: { x: 1 }, select: 'name' }, + { path: 'notes', options: { limit: 10 }, model: 'override' } + ]; + Model.populate(res, opts, (err: any, res: IActor) => {}); +}); +Model.find({ type: 'iphone' }, (err: any, res: IActor[]) => { + var opts = [{ path: 'company', match: { x: 1 }, select: 'name' }]; + var promise = Model.populate(res, opts); + promise.then(console.log).end(); +}); +Model.populate({ name: 'Test A' }, { path: 'weapon', model: 'Weapon' }, (err: any, user: IActor) => {}); +Model.populate([ + { name: 'User hoge' }, + { name: 'User fuga' }, +], { path: 'weapon' }, (err: any, users: IActor[]) => {}); + +Model.remove({ title: 'baby born from alien father' }, (err: any) => {}); +var query2 = Model.remove({ _id: 'id' }); +query2.exec(); +Model.update({ age: { $gt: 18 } }, { oldEnough: true }, (err: any, numberAffected: number, raw: any) => {}); +Model.update({ name: 'Tobi' }, { ferret: true }, { multi: true }, (err: any, numberAffected: number, raw: any) => {}); +Model.update({ _id: 'id' }, { $set: { text: 'changed' }}).exec(); + +Model.where('age').gte(21).lte(65).exec((err: any, res: IActor[]) => {}); +var query3 =Model + .where('age').gt(21).lt(65) + .where('name', /^b/i).all('type', 1); +query3.all(25); +query3.and([{ color: 'green' }, { status: 'ok' }]); +query3.batchSize(100); +query3.where('loc').within().box([40.73083, -73.99756], [40.741404, -73.988135]); +query3.where('loc').within().circle({ center: [50, 50], radius: 10, unique: true }); +query3.circle('loc', { center: [50, 50], radius: 10, unique: true }); +query3.comment('login query'); +query3.where({ 'color': 'black' }).count(); +query3.count({ color: 'black' }).count((err: any, count: number) => {}); +query3.count({ color: 'black' }, (err: any, count: number) => {}); +query3.where({ color: 'black' }).count((err: any, count: number) => {}); +query3.elemMatch('comment', { author: 'autobot', votes: {$gte: 5}}); +query3.where('comment').elemMatch({ author: 'autobot', votes: {$gte: 5}}); +query.elemMatch('comment', (elem: mongoose.Query) => { + elem.where('author').equals('autobot'); + elem.where('votes').gte(5); +}); +query3.where('age').equals(49); +query3.where('age', 49); +query3.exec(); +query3.exec('update'); +query3.where('name').exists(); +query3.where('name').exists(true); +query3.find().exists('name'); +query3.where('name').exists(false); +query3.find().exists('name', false); +query3.find({ name: 'Los Pollos Hermanos' }).find((err: any, res: IActor[]) => {}); +query3.where('loc').within().geometry({ type: 'Polygon', coordinates: [[[ 10, 20 ], [ 10, 40 ], [ 30, 40 ], [ 30, 20 ]]] }); +query3.find().where('age').gt(21); +query3.find().gt('age', 21); +query3.hint({ indexA: 1, indexB: -1}); +query3.where('path').intersects().geometry({ type: 'LineString', coordinates: [[180.0, 11.0], [180, 9.0]] }); +query3.where('path').intersects({ type: 'LineString', coordinates: [[180.0, 11.0], [180, 9.0]] }); +query3.maxScan(100); +query3.where('loc').near({ center: [10, 10] }); +query3.where('loc').near({ center: [10, 10], maxDistance: 5 }); +query3.where('loc').near({ center: [10, 10], maxDistance: 5, spherical: true }); +query3.near('loc', { center: [10, 10], maxDistance: 5 }); +query3.where('loc').nearSphere({ center: [10, 10], maxDistance: 5 }); +query3.nor([{ color: 'green' }, { status: 'ok' }]); +query3.or([{ color: 'red' }, { status: 'emergency' }]); +query3.where('loc').within().polygon([10,20], [13, 25], [7,15]); +query3.polygon('loc', [10,20], [13, 25], [7,15]); + +query3.findOne().populate('owner').exec((err: any, res: IActor[]) => {}); +query3.find().populate({ + path: 'owner', + select: 'name', + match: { color: 'black' }, + options: { sort: { name: -1 }} +}).exec((err: any, res: IActor[]) => {}); +query3.find().populate('owner', 'name', null, {sort: { name: -1 }}).exec((err: any, res: IActor[]) => {}); + +query3.read('primary'); +query3.read('p'); +query3.read('primaryPreferred'); +query3.read('pp'); +query3.read('secondary'); +query3.read('s'); +query3.read('secondaryPreferred'); +query3.read('sp'); +query3.read('nearest'); +query3.read('n'); +query3.read('s', [{ dc:'sf', s: 1 },{ dc:'ma', s: 2 }]); +query3.remove({ artist: 'Anne Murray' }, (err: any, res: IActor[]) => {}); +query3.select('a b -c'); +query3.select({a: 1, b: 1, c: 0}); +query3.select('+path'); +query3.where('tags').size(0); +query3.skip(100).limit(20); +query3.slaveOk(); +query3.slaveOk(true); +query3.slaveOk(false); +query3.slice('comments', -5); +query3.slice('comments', [10, 5]) +query3.where('comments').slice(5); +query3.where('comments').slice([-10, 5]); +query3.snapshot(); +query3.snapshot(true); +query3.snapshot(false); +query3.sort({ field: 'asc', test: -1 }); +query3.sort('field -test'); +Model.find({ name: /^hello/ }).stream({ transform: JSON.stringify }).pipe(fs.createWriteStream('./test.json')); +var stream = Model.find({ name: /^hello/ }).stream(); +stream + .on('data', (doc: IActor) => {}) + .on('error', (err: any) => {}) + .on('close', () => {}); + +query3.tailable(); +query3.tailable(false); +var AdvQuery = query3.toConstructor(); +query3.update({ title: 'words' }); +query3.update({ $set: { title: 'words' }}); +query3.update({ name: /^match/ }, { $set: { arr: [] }}, { multi: true }, (err: any, row: number, raw: any) => {}); + +query3.where('loc').within({ center: [50,50], radius: 10, unique: true, spherical: true }); +query3.where('loc').within({ box: [[40.73, -73.9], [40.7, -73.988]] }); +query3.where('loc').within({ polygon: [[],[],[],[]] }); +query3.where('loc').within([], [], []); // polygon +query3.where('loc').within([], []); // box +query3.where('loc').within({ type: 'LineString', coordinates: [] }); // geometry + +mongoose.Query.use$geoWithin = false; + + +var ToySchema = new Schema({}); +ToySchema.add({ name: 'string', color: 'string', price: 'number' }); +schema.eachPath(function(path: string, value: any) {}); +schema.index({ first: 1, last: -1 }); +schema.indexes(); +schema.method('meow', function() { + console.log('meeeeeoooooooooooow'); +}); +var Kitty = mongoose.model('Kitty', schema); +var fizz: any = new Kitty({ name: 'kitty' }); +fizz.meow(); +schema.method({ + purr: function() {}, + scratch: function() {}, +}); +schema.path('name'); +schema.path('name', Number); +schema.pathType('name'); +schema.plugin(function() {}); +schema.post('save', function(doc: IActor) {}); +schema.pre('save', function(next: () => void) {}); +schema.requiredPaths(); +schema.static('findByName', function(name: string, callback: () => void) {}); +schema.virtual('display_name') + .get(function(): string { return this.name; }) + .set((value: string): void => {}); + diff --git a/mongoose/mongoose.d.ts b/mongoose/mongoose.d.ts new file mode 100644 index 0000000000..e9057abc7a --- /dev/null +++ b/mongoose/mongoose.d.ts @@ -0,0 +1,453 @@ +// Type definitions for Mongoose 3.8.5 +// Project: http://mongoosejs.com/ +// Definitions by: horiuchi +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "mongoose" { + function connect(uri: string, options?: ConnectionOption, callback?: (err: any) => void): Mongoose; + function createConnection(): Connection; + function createConnection(uri: string, options?: ConnectionOption): Connection; + function createConnection(host: string, database_name: string, port?: number, options?: ConnectionOption): Connection; + function disconnect(callback?: (err?: any) => void): Mongoose; + + function model(name: string, schema: Schema, collection?: string, skipInit?: boolean): Model; + function modelNames(): string[]; + function plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Mongoose; + + function get(key: string): any; + function set(key: string, value: any): void; + + var mongo: any; + var mquery: any; + var version: string; + var connection: Connection; + + export class Mongoose { + connect(uri: string, options?: ConnectionOption, callback?: (err: any) => void): Mongoose; + createConnection(): Connection; + createConnection(uri: string, options?: Object): Connection; + createConnection(host: string, database_name: string, port?: number, options?: ConnectionOption): Connection; + disconnect(callback?: (err?: any) => void): Mongoose; + get(key: string): any; + model(name: string, schema: Schema, collection?: string, skipInit?: boolean): Model; + modelNames(): string[]; + plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Mongoose; + set(key: string, value: any): void; + + mongo: any; + mquery: any; + version: string; + connection: Connection; + } + + export interface Connection extends NodeJS.EventEmitter { + constructor(base: Mongoose): Connection; + + close(callback?: (err: any) => void): Connection; + collection(name: string, options?: Object): Collection; + model(name: string, schema: Schema, collection?: string): Model; + modelNames(): string[]; + open(host: string, database?: string, port?: number, options?: ConnectionOption, callback?: (err: any) => void): Connection; + openSet(uris: string, database?: string, options?: ConnectionSetOption, callback?: (err: any) => void): Connection; + + db: any; + collections: {[index: string]: Collection}; + readyState: number; + } + export interface ConnectionOption { + db?: any; + server?: any; + replset?: any; + user?: string; + pass?: string; + auth?: any; + } + export interface ConnectionSetOption extends ConnectionOption { + mongos?: boolean; + } + + export interface Collection { + } + + + export class SchemaType { } + export class VirtualType { + get(fn: Function): VirtualType; + set(fn: Function): VirtualType; + } + export module Types { + export class ObjectId {} + } + + export class Schema { + static Types: { + String: String; + ObjectId: Types.ObjectId; + OId: Types.ObjectId; + Mixed: any; + }; + constructor(schema?: Object, options?: Object); + + add(obj: Object, prefix?: string): void; + eachPath(fn: (path: string, type: any) => void): Schema; + get(key: string): any; + index(fields: Object, options?: Object): Schema; + indexes(): void; + method(name: string, fn: Function): Schema; + method(method: Object): Schema; + path(path: string): any; + path(path: string, constructor: any): Schema; + pathType(path: string): string; + plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Schema; + post(method: string, fn: Function): Schema; + pre(method: string, callback: Function): Schema; + requiredPaths(): string[]; + set(key: string, value: any): void; + static(name: string, fn: Function): Schema; + virtual(name: string, options?: Object): VirtualType; + virtualpath(name: string): VirtualType; + } + export interface SchemaOption { + autoIndex?: boolean; + bufferCommands?: boolean; + capped?: boolean; + collection?: string; + id?: boolean; + _id?: boolean; + minimize?: boolean; + read?: string; + safe?: boolean; + shardKey?: boolean; + strict?: boolean; + toJSON?: Object; + toObject?: Object; + versionKey?: boolean; + } + + export interface Model { + new(doc: Object): T; + + aggregate(...aggregations: Object[]): Aggregate; + aggregate(aggregation: Object, callback: (err: any, res: T[]) => void): Promise; + aggregate(aggregation1: Object, aggregation2: Object, callback: (err: any, res: T[]) => void): Promise; + aggregate(aggregation1: Object, aggregation2: Object, aggregation3: Object, callback: (err: any, res: T[]) => void): Promise; + count(conditions: Object, callback?: (err: any, count: number) => void): Query; + + create(doc: Object, fn?: (err: any, res: T) => void): Promise; + create(doc1: Object, doc2: Object, fn?: (err: any, res1: T, res2: T) => void): Promise; + create(doc1: Object, doc2: Object, doc3: Object, fn?: (err: any, res1: T, res2: T, res3: T) => void): Promise; + discriminator(name: string, schema: Schema): Model; + distinct(field: string, callback?: (err: any, res: T[]) => void): Query; + distinct(field: string, conditions: Object, callback?: (err: any, res: T[]) => void): Query; + ensureIndexes(callback: (err: any) => void): Promise; + + find(cond: Object, callback?: (err: any, res: T[]) => void): Query; + find(cond: Object, fields: Object, callback?: (err: any, res: T[]) => void): Query; + find(cond: Object, fields: Object, options: Object, callback?: (err: any, res: T[]) => void): Query; + findById(id: string, callback?: (err: any, res: T) => void): Query; + findById(id: string, fields: Object, callback?: (err: any, res: T) => void): Query; + findById(id: string, fields: Object, options: Object, callback?: (err: any, res: T) => void): Query; + findByIdAndRemove(id: string, callback?: (err: any, res: T) => void): Query; + findByIdAndRemove(id: string, options: Object, callback?: (err: any, res: T) => void): Query; + findByIdAndUpdate(id: string, update: Object, callback?: (err: any, res: T) => void): Query; + findByIdAndUpdate(id: string, update: Object, options: FindAndUpdateOption, callback?: (err: any, res: T) => void): Query; + findOne(cond: Object, callback?: (err: any, res: T) => void): Query; + findOne(cond: Object, fields: Object, callback?: (err: any, res: T) => void): Query; + findOne(cond: Object, fields: Object, options: Object, callback?: (err: any, res: T) => void): Query; + findOneAndRemove(cond: Object, callback?: (err: any, res: T) => void): Query; + findOneAndRemove(cond: Object, options: Object, callback?: (err: any, res: T) => void): Query; + findOneAndUpdate(cond: Object, update: Object, callback?: (err: any, res: T) => void): Query; + findOneAndUpdate(cond: Object, update: Object, options: FindAndUpdateOption, callback?: (err: any, res: T) => void): Query; + + geoNear(point: { type: string; coordinates: number[] }, options: Object, callback?: (err: any, res: T[]) => void): Query; + geoNear(point: number[], options: Object, callback?: (err: any, res: T[]) => void): Query; + geoSearch(cond: Object, options: GeoSearchOption, callback?: (err: any, res: T[]) => void): Query; + increment(): T; + mapReduce(options: MapReduceOption, callback?: (err: any, res: MapReduceResult[]) => void): Promise[]>; + mapReduce(options: MapReduceOption2, callback?: (err: any, res: MapReduceResult[]) => void): Promise[]>; + model(name: string): Model; + + populate(doc: U, options: Object, callback?: (err: any, res: U) => void): Promise; + populate(doc: U[], options: Object, callback?: (err: any, res: U[]) => void): Promise; + update(cond: Object, update: Object, callback?: (err: any, affectedRows: number, raw: any) => void): Query; + update(cond: Object, update: Object, options: Object, callback?: (err: any, affectedRows: number, raw: any) => void): Query; + remove(cond: Object, callback?: (err: any) => void): Query<{}>; + save(callback?: (err: any, result: T, numberAffected: number) => void): Query; + where(path: string, val?: Object): Query; + + $where(argument: string): Query; + $where(argument: Function): Query; + + base: Mongoose; + collection: Collection; + db: any; + discriminators: any; + modelName: string; + schema: Schema; + } + export interface FindAndUpdateOption { + new?: boolean; + upsert?: boolean; + sort?: Object; + select?: Object; + } + export interface GeoSearchOption { + near: number[]; + maxDistance: number; + limit?: number; + lean?: boolean; + } + export interface MapReduceOption { + map: () => void; + reduce: (key: Key, vals: T[]) => Val; + query?: Object; + limit?: number; + keeptemp?: boolean; + finalize?: (key: Key, val: Val) => Val; + scope?: Object; + jsMode?: boolean; + verbose?: boolean; + out?: { + inline?: number; + replace?: string; + reduce?: string; + merge?: string; + }; + } + export interface MapReduceOption2 { + map: string; + reduce: (key: Key, vals: T[]) => Val; + query?: Object; + limit?: number; + keeptemp?: boolean; + finalize?: (key: Key, val: Val) => Val; + scope?: Object; + jsMode?: boolean; + verbose?: boolean; + out?: { + inline?: number; + replace?: string; + reduce?: string; + merge?: string; + }; + } + export interface MapReduceResult { + _id: Key; + value: Val; + } + + export class Query { + exec(callback?: (err: any, res: T) => void): Promise; + exec(operation: string, callback?: (err: any, res: T) => void): Promise; + exec(operation: Function, callback?: (err: any, res: T) => void): Promise; + + all(val: number): Query; + all(path: string, val: number): Query; + and(array: Object[]): Query; + box(val: Object): Query; + box(a: number[], b: number[]): Query; + batchSize(val: number): Query; + cast(model: Model, obj: Object): U; + //center(): Query; + //centerSphere(path: string, val: Object): Query; + circle(area: Object): Query; + circle(path: string, area: Object): Query; + comment(val: any): Query; + count(callback?: (err: any, count: number) => void): Query; + count(criteria: Object, callback?: (err: any, count: number) => void): Query; + distinct(callback?: (err: any, res: T) => void): Query; + distinct(field: string, callback?: (err: any, res: T) => void): Query; + distinct(criteria: Object, field: string, callback?: (err: any, res: T) => void): Query; + distinct(criteria: Query, field: string, callback?: (err: any, res: T) => void): Query; + elemMatch(criteria: Object): Query; + elemMatch(criteria: (elem: Query) => void): Query; + elemMatch(path: string, criteria: Object): Query; + elemMatch(path: string, criteria: (elem: Query) => void): Query; + equals(val: Object): Query; + exists(val?: boolean): Query; + exists(path: string, val?: boolean): Query; + find(callback?: (err: any, res: T) => void): Query; + find(criteria: Object, callback?: (err: any, res: T) => void): Query; + findOne(callback?: (err: any, res: T) => void): Query; + findOne(criteria: Object, callback?: (err: any, res: T) => void): Query; + findOneAndRemove(callback?: (err: any, res: T) => void): Query; + findOneAndRemove(cond: Object, callback?: (err: any, res: T) => void): Query; + findOneAndRemove(cond: Object, options: Object, callback?: (err: any, res: T) => void): Query; + findOneAndUpdate(callback?: (err: any, res: T) => void): Query; + findOneAndUpdate(update: Object, callback?: (err: any, res: T) => void): Query; + findOneAndUpdate(cond: Object, update: Object, callback?: (err: any, res: T) => void): Query; + findOneAndUpdate(cond: Object, update: Object, options: FindAndUpdateOption, callback?: (err: any, res: T) => void): Query; + geometry(object: Object): Query; + gt(val: number): Query; + gt(path: string, val: number): Query; + gte(val: number): Query; + gte(path: string, val: number): Query; + hint(val: Object): Query; + in(val: any[]): Query; + in(path: string, val: any[]): Query; + intersects(arg?: Object): Query; + lean(bool?: boolean): Query; + limit(val: number): Query; + lt(val: number): Query; + lt(path: string, val: number): Query; + lte(val: number): Query; + lte(path: string, val: number): Query; + maxDistance(val: number): Query; + maxDistance(path: string, val: number): Query; + maxScan(val: number): Query; + merge(source: Query): Query; + merge(source: Object): Query; + mod(val: number[]): Query; + mod(path: string, val: number[]): Query; + ne(val: any): Query; + ne(path: string, val: any): Query; + near(val: Object): Query; + near(path: string, val: Object): Query; + nearSphere(val: Object): Query; + nearSphere(path: string, val: Object): Query; + nin(val: any[]): Query; + nin(path: string, val: any[]): Query; + nor(array: Object[]): Query; + or(array: Object[]): Query; + polygon(...coordinatePairs: number[][]): Query; + polygon(path: string, ...coordinatePairs: number[][]): Query; + populate(path: string, select?: string, match?: Object, options?: Object): Query; + populate(path: string, select: string, model: string, match?: Object, options?: Object): Query; + populate(opt: PopulateOption): Query; + read(pref: string, tags?: Object[]): Query; + regex(val: RegExp): Query; + regex(path: string, val: RegExp): Query; + remove(callback?: (err: any, res: T) => void): Query; + remove(criteria: Object, callback?: (err: any, res: T) => void): Query; + select(arg: string): Query; + select(arg: Object): Query; + setOptions(options: Object): Query; + size(val: number): Query; + size(path: string, val: number): Query; + skip(val: number): Query; + slaveOk(v?: boolean): Query; + slice(val: number): Query; + slice(val: number[]): Query; + slice(path: string, val: number): Query; + slice(path: string, val: number[]): Query; + snapshot(v?: boolean): Query; + sort(arg: Object): Query; + sort(arg: string): Query; + stream(options?: { transform?: Function; }): QueryStream; + tailable(v?: boolean): Query; + toConstructor(): Query; + update(callback?: (err: any, affectedRows: number, doc: T) => void): Query; + update(doc: Object, callback?: (err: any, affectedRows: number, doc: T) => void): Query; + update(criteria: Object, doc: Object, callback?: (err: any, affectedRows: number, doc: T) => void): Query; + update(criteria: Object, doc: Object, options: Object, callback?: (err: any, affectedRows: number, doc: T) => void): Query; + where(path?: string, val?: any): Query; + where(path?: Object, val?: any): Query; + within(val?: Object): Query; + within(coordinate: number[], ...coordinatePairs: number[][]): Query; + + $where(argument: string): Query; + $where(argument: Function): Query; + + static use$geoWithin: boolean; + } + + export interface PopulateOption { + path: string; + select?: string; + model?: string; + match?: Object; + options?: Object; + } + + export interface QueryStream extends NodeJS.EventEmitter { + destory(err?: any): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + paused: number; + readable: boolean; + } + + export interface Document { + id?: string; + _id: string; + + equals(doc: Document): boolean; + get(path: string, type?: new(...args: any[]) => any): any; + inspect(options?: Object): string; + invalidate(path: string, errorMsg: string, value: any): void; + invalidate(path: string, error: Error, value: any): void; + isDirectModified(path: string): boolean; + isInit(path: string): boolean; + isModified(path?: string): boolean; + isSelected(path: string): boolean; + markModified(path: string): void; + modifiedPaths(): string[]; + populate(callback?: (err: any, res: T) => void): Document; + populate(path?: string, callback?: (err: any, res: T) => void): Document; + populate(opt: PopulateOption, callback?: (err: any, res: T) => void): Document; + populated(path: string): any; + remove(callback?: (err: any) => void): Query; + save(callback?: (err: any, res: T) => void): void; + set(path: string, val: any, type?: new(...args: any[]) => any, options?: Object): void; + set(path: string, val: any, options?: Object): void; + set(value: Object): void; + toJSON(options?: Object): Object; + toObject(options?: Object): Object; + toString(): string; + update(doc: Object, options: Object, callback: (err: any, affectedRows: number, raw: any) => void): Query; + validate(cb: (err: any) => void): void; + + isNew: boolean; + errors: Object; + schema: Object; + } + + + export class Aggregate { + constructor(...options: Object[]); + + append(...options: Object[]): Aggregate; + group(arg: Object): Aggregate; + limit(num: number): Aggregate; + match(arg: Object): Aggregate; + near(parameters: Object): Aggregate; + project(arg: string): Aggregate; + project(arg: Object): Aggregate; + select(filter: string): Aggregate; + skip(num: number): Aggregate; + sort(arg: string): Aggregate; + sort(arg: Object): Aggregate; + unwind(fiels: string, ...rest: string[]): Aggregate; + + exec(callback?: (err: any, result: T) => void): Promise; + read(pref: string, ...tags: Object[]): Aggregate; + } + + export class Promise { + constructor(fn?: (err: any, result: T) => void); + + then(onFulFill: (result: T) => void, onReject?: (err: any) => void): Promise; + end(): void; + + fulfill(result: T): Promise; + reject(err: any): Promise; + resolve(err: any, result: T): Promise; + + onFulfill(listener: (result: T) => void): Promise; + onReject(listener: (err: any) => void): Promise; + onResolve(listener: (err: any, result: T) => void): Promise; + on(event: string, listener: Function): Promise; + + // Deprecated methods. + addBack(listener: (err: any, result: T) => void): Promise; + addCallback(listener: (result: T) => void): Promise; + addErrback(listener: (err: any) => void): Promise; + complete(result: T): Promise; + error(err: any): Promise; + } + +} + From 3d92fa2caf870c60d50956762845e3a6abe79826 Mon Sep 17 00:00:00 2001 From: Horiuchi_H Date: Thu, 1 May 2014 19:42:33 +0900 Subject: [PATCH 17/49] add mongoose in CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 01b5025d20..c8368f022b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -205,6 +205,7 @@ All definitions files include a header with the author and editors, so at some p * [Modernizr](http://modernizr.com/) (by [Boris Yankov](https://github.com/borisyankov) and [Theodore Brown](https://github.com/theodorejb/)) * [Moment.js](https://github.com/timrwood/moment) (by [Michael Lakerveld](https://github.com/Lakerfield)) * [MongoDB](http://mongodb.github.io/node-mongodb-native/) (from TypeScript samples, updated by [Niklas Mollenhauer](https://github.com/nikeee)) +* [mongoose](http://mongoosejs.com/) (by [Hiroki Horiuchi](https://github.com/horiuchi/)) * [Mousetrap](http://craig.is/killing/mice) (by [Dániel Tar](https://github.com/qcz)) * [msgpack.js](https://github.com/uupaa/msgpack.js) (by [Shinya Mochizuki](https://github.com/enrapt-mochizuki)) * [Mustache.js](https://github.com/janl/mustache.js) (by [Boris Yankov](https://github.com/borisyankov)) From 648511f6c4ba6036fd8ec0462291bc6fd2c7446b Mon Sep 17 00:00:00 2001 From: teppeis Date: Thu, 1 May 2014 22:19:36 +0900 Subject: [PATCH 18/49] Add Esprima --- CONTRIBUTORS.md | 1 + esprima/esprima-tests.ts | 163 +++++++++++++++++++++++ esprima/esprima.d.ts | 274 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 438 insertions(+) create mode 100644 esprima/esprima-tests.ts create mode 100644 esprima/esprima.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 01b5025d20..f3fcff1ea1 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -63,6 +63,7 @@ All definitions files include a header with the author and editors, so at some p * [emissary](https://github.com/atom/emissary) (by [vvakame](https://github.com/vvakame)) * [EpicEditor](http://epiceditor.com/) (by [Boris Yankov](https://github.com/borisyankov)) * [ES6-Promises](https://github.com/jakearchibald/ES6-Promises) (by [François de Campredon](https://github.com/fdecampredon/)) +* [Esprima](http://esprima.org/) (by [Teppei Sato](https://github.com/teppeis)) * [expect.js](https://github.com/LearnBoost/expect.js) (by [Teppei Sato](https://github.com/teppeis)) * [expectations](https://github.com/spmason/expectations) (by [vvakame](https://github.com/vvakame)) * [Express](http://expressjs.com/) (by [Boris Yankov](https://github.com/borisyankov)) diff --git a/esprima/esprima-tests.ts b/esprima/esprima-tests.ts new file mode 100644 index 0000000000..9451e077d2 --- /dev/null +++ b/esprima/esprima-tests.ts @@ -0,0 +1,163 @@ +/// + +import esprima = require('esprima'); +import Syntax = esprima.Syntax; + +var token: esprima.Token; +var options: esprima.Options; +var comment: Syntax.Comment; +var program: Syntax.Program; +var statement: Syntax.SomeStatement; +var blockStatement: Syntax.BlockStatement; +var expression: Syntax.SomeExpression; +var property: Syntax.Property; +var identifier: Syntax.Identifier; +var literal: Syntax.Literal; +var switchCase: Syntax.SwitchCase; +var catchClause: Syntax.CatchClause; +var variableDeclaratorOrExpression: Syntax.VariableDeclaratorOrExpression; +var literalOrIdentifier: Syntax.LiteralOrIdentifier; +var blockStatementOrExpression: Syntax.BlockStatementOrExpression; +var identifierOrExpression: Syntax.IdentifierOrExpression; +var any: any; +var string: string; +var boolean: boolean; +var number: number; + +// esprima +string = esprima.version; +program = esprima.parse('code'); +program = esprima.parse('code', {range: true}); +token = esprima.tokenize('code')[0]; +token = esprima.tokenize('code', {range: true})[0]; + +// Token +string = token.type; +string = token.value; + +// Program +string = program.type; +statement = program.body[0]; +comment = program.comments[0] + +// Location +number = program.loc.start.line; +number = program.loc.start.column; +number = program.loc.end.line; +number = program.loc.end.column; +number = program.range[0]; + +// Comment +string = comment.value; + +// Statement +// BlockStatement +string = statement.type; +statement = statement.body[0]; +comment = statement.leadingComments[0] +comment = statement.trailingComments[0] + +// ExpressionStatement +expression = statement.expression; + +// IfStatement +expression = statement.test; +statement = statement.consequent; +statement = statement.alternate; + +// LabeledStatement +identifier = statement.label; +statement = statement.body; + +// WithStatement +expression = statement.object; + +// SwitchStatement +expression = statement.discriminant; +switchCase = statement.cases[0]; +boolean = statement.lexical; + +// ReturnStatement +expression = statement.argument; + +// TryStatement +blockStatement = statement.block; +catchClause = statement.handler; +catchClause = statement.guardedHandlers[0]; +blockStatement = statement.finalizer; + +// ForStatement +variableDeclaratorOrExpression = statement.init; +expression = statement.update; + +// ForInStatement +variableDeclaratorOrExpression = statement.left; +expression = statement.right; +boolean = statement.each; + +// Expression +// ArrayExpression +string = expression.type; +expression = expression.elements[0]; + +// ObjectExpression +property = expression.properties[0]; +string = property.type; +literalOrIdentifier = property.key; +expression = property.value; +string = property.kind; + +// FunctionExpression +identifier = expression.id; +identifier = expression.params[0]; +expression = expression.defaults[0]; +identifier = expression.rest; +blockStatementOrExpression = expression.body; +boolean = expression.generator; +boolean = expression.expression; + +// SequenceExpression +expression = expression.expressions[0] + +// UnaryExpression +string = expression.operator; +boolean = expression.prefix; + +// BinaryExpression +expression = expression.left; +expression = expression.right; + +// ConditionalExpression +expression = expression.test; +expression = expression.alternate; +expression = expression.consequent; + +// ConditionalExpression +expression = expression.callee; +expression = expression.arguments[0]; + +// MemberExpression +expression = expression.object; +identifierOrExpression = expression.property; +boolean = expression.computed; + +// Clauses +// SwitchCase +string = switchCase.type; +expression = switchCase.test; +statement = switchCase.consequent[0]; + +// CatchClause +string = catchClause.type; +identifier = catchClause.param; +expression = catchClause.guard; +blockStatement = catchClause.body; + +// Misc +// Identifier +string = identifier.type; +string = identifier.name; + +// Literal +string = literal.type; +any = literal.value; diff --git a/esprima/esprima.d.ts b/esprima/esprima.d.ts new file mode 100644 index 0000000000..2b09e895ce --- /dev/null +++ b/esprima/esprima.d.ts @@ -0,0 +1,274 @@ +// Type definitions for Esprima v1.2.0 +// Project: http://esprima.org +// Definitions by: teppeis +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module esprima { + var version: string; + function parse(code: string, options?: Options): Syntax.Program; + function tokenize(code: string, options?: Options): Array; + + interface Token { + type: string + value: string + } + + interface Options { + loc?: boolean + range?: boolean + raw?: boolean + tokens?: boolean + comment?: boolean + attachComment?: boolean + tolerant?: boolean + source?: boolean + } + + module Syntax { + // Node + interface Node { + type: string + loc?: LineLocation + range?: number[] + leadingComments?: Comment[] + trailingComments?: Comment[] + } + interface LineLocation { + start: Position + end: Position + } + interface Position { + line: number + column: number + } + + // Comment + interface Comment extends Node { + value: string + } + + // Program + interface Program extends Node { + body: SomeStatement[] + comments?: Comment[] + } + + // Function + interface Function extends Node { + id: Identifier // | null + params: Identifier[] + defaults: SomeExpression[] + rest: Identifier // | null + body: BlockStatementOrExpression + generator: boolean + expression: boolean + } + interface BlockStatementOrExpression extends Array, BlockStatement, SomeExpression { + body: BlockStatementOrExpression + } + + // Statement + interface Statement extends Node { + } + interface EmptyStatement extends Statement { + } + interface BlockStatement extends Statement { + body: SomeStatement[] + } + interface ExpressionStatement extends Statement { + expression: SomeExpression + } + interface IfStatement extends Statement { + test: SomeExpression + consequent: SomeStatement + alternate: SomeStatement + } + interface LabeledStatement extends Statement { + label: Identifier + body: SomeStatement + } + interface BreakStatement extends Statement { + label: Identifier // | null + } + interface ContinueStatement extends Statement { + label: Identifier // | null + } + interface WithStatement extends Statement { + object: SomeExpression + body: SomeStatement + } + interface SwitchStatement extends Statement { + discriminant: SomeExpression + cases: SwitchCase[] + lexical: boolean + } + interface ReturnStatement extends Statement { + argument: SomeExpression // | null + } + interface ThrowStatement extends Statement { + argument: SomeExpression + } + interface TryStatement extends Statement { + block: BlockStatement + handler: CatchClause // | null + guardedHandlers: CatchClause[] + finalizer: BlockStatement // | null + } + interface WhileStatement extends Statement { + test: SomeExpression + body: SomeStatement + } + interface DoWhileStatement extends Statement { + body: SomeStatement + test: SomeExpression + } + interface ForStatement extends Statement { + init: VariableDeclaratorOrExpression // | null + test: SomeExpression // | null + update: SomeExpression // | null + body: SomeStatement + } + interface ForInStatement extends Statement { + left: VariableDeclaratorOrExpression + right: SomeExpression + body: SomeStatement + each: boolean + } + interface VariableDeclaratorOrExpression extends VariableDeclarator, SomeExpression { + } + interface DebuggerStatement extends Statement { + } + interface SomeStatement extends + EmptyStatement, ExpressionStatement, BlockStatement, IfStatement, + LabeledStatement, BreakStatement, ContinueStatement, WithStatement, + SwitchStatement, ReturnStatement, ThrowStatement, TryStatement, + WhileStatement, DoWhileStatement, ForStatement, ForInStatement, DebuggerStatement { + body: SomeStatementOrList + } + interface SomeStatementOrList extends Array, SomeStatement { + } + + // Declration + interface Declration extends Statement { + } + interface FunctionDeclration extends Declration { + id: Identifier + params: Identifier[] // Pattern + defaults: SomeExpression[] + rest: Identifier + body: BlockStatementOrExpression + generator: boolean + expression: boolean + } + interface VariableDeclaration extends Declration { + declarations: VariableDeclarator[] + kind: string // "var" | "let" | "const" + } + interface VariableDeclarator extends Node { + id: Identifier // Pattern + init: SomeExpression + } + + // Expression + interface Expression extends Node { // | Pattern + } + interface SomeExpression extends + ThisExpression, ArrayExpression, ObjectExpression, FunctionExpression, + ArrowFunctionExpression, SequenceExpression, UnaryExpression, BinaryExpression, + AssignmentExpression, UpdateExpression, LogicalExpression, ConditionalExpression, + NewExpression, CallExpression, MemberExpression { + } + interface ThisExpression extends Expression { + } + interface ArrayExpression extends Expression { + elements: SomeExpression[] // [ Expression | null ] + } + interface ObjectExpression extends Expression { + properties: Property[] + } + interface Property extends Node { + key: LiteralOrIdentifier // Literal | Identifier + value: SomeExpression + kind: string // "init" | "get" | "set" + } + interface LiteralOrIdentifier extends Literal, Identifier { + } + interface FunctionExpression extends Function, Expression { + } + interface ArrowFunctionExpression extends Function, Expression { + } + interface SequenceExpression extends Expression { + expressions: SomeExpression[] + } + interface UnaryExpression extends Expression { + operator: string // UnaryOperator + prefix: boolean + argument: SomeExpression + } + interface BinaryExpression extends Expression { + operator: string // BinaryOperator + left: SomeExpression + right: SomeExpression + } + interface AssignmentExpression extends Expression { + operator: string // AssignmentOperator + left: SomeExpression + right: SomeExpression + } + interface UpdateExpression extends Expression { + operator: string // UpdateOperator + argument: SomeExpression + prefix: boolean + } + interface LogicalExpression extends Expression { + operator: string // LogicalOperator + left: SomeExpression + right: SomeExpression + } + interface ConditionalExpression extends Expression { + test: SomeExpression + alternate: SomeExpression + consequent: SomeExpression + } + interface NewExpression extends Expression { + callee: SomeExpression + arguments: SomeExpression[] + } + interface CallExpression extends Expression { + callee: SomeExpression + arguments: SomeExpression[] + } + interface MemberExpression extends Expression { + object: SomeExpression + property: IdentifierOrExpression // Identifier | Expression + computed: boolean + } + interface IdentifierOrExpression extends Identifier, SomeExpression { + } + + // Pattern + // interface Pattern extends Node { + // } + + // Clauses + interface SwitchCase extends Node { + test: SomeExpression + consequent: SomeStatement[] + } + interface CatchClause extends Node { + param: Identifier // Pattern + guard: SomeExpression + body: BlockStatement + } + + // Misc + interface Identifier extends Node, Expression { // | Pattern + name: string + } + interface Literal extends Node, Expression { + value: any // string | boolean | null | number | RegExp + } + } +} + +export = esprima From 7fc10a1c7c2010899b5812e520abfbd5e0a20f9c Mon Sep 17 00:00:00 2001 From: teppeis Date: Fri, 2 May 2014 20:28:45 +0900 Subject: [PATCH 19/49] Wrap "export = esprima" up in an external module --- esprima/esprima.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esprima/esprima.d.ts b/esprima/esprima.d.ts index 2b09e895ce..1e603ee255 100644 --- a/esprima/esprima.d.ts +++ b/esprima/esprima.d.ts @@ -271,4 +271,6 @@ declare module esprima { } } -export = esprima +declare module "esprima" { + export = esprima +} From edd089a240ebb16958587940b47880de73276d3d Mon Sep 17 00:00:00 2001 From: Basarat Ali Syed Date: Fri, 2 May 2014 23:00:30 +1000 Subject: [PATCH 20/49] Update chai-datetime.d.ts --- chai-datetime/chai-datetime.d.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/chai-datetime/chai-datetime.d.ts b/chai-datetime/chai-datetime.d.ts index 432f6bb247..263034361f 100644 --- a/chai-datetime/chai-datetime.d.ts +++ b/chai-datetime/chai-datetime.d.ts @@ -18,13 +18,19 @@ declare module chai { } interface Assert { - afterDate(leftDate: Date, rightDate: Date): boolean; - beforeDate(leftDate: Date, rightDate: Date): boolean; - equalDate(leftDate: Date, rightDate: Date): boolean; - - afterTime(leftDate: Date, rightDate: Date): boolean; - beforeTime(leftDate: Date, rightDate: Date): boolean; - equalTime(leftDate: Date, rightDate: Date): boolean; + equalTime(val: Date, exp: Date, msg?: string): boolean; + notEqualTime(val: Date, exp: Date, msg?: string): boolean; + beforeTime(val: Date, exp: Date, msg?: string): boolean; + notBeforeTime(val: Date, exp: Date, msg?: string): boolean; + afterTime(val: Date, exp: Date, msg?: string): boolean; + notAfterTime(val: Date, exp: Date, msg?: string): boolean; + + equalDate(val: Date, exp: Date, msg?: string): boolean; + notEqualDate(val: Date, exp: Date, msg?: string): boolean; + beforeDate(val: Date, exp: Date, msg?: string): boolean; + notBeforeDate(val: Date, exp: Date, msg?: string): boolean; + afterDate(val: Date, exp: Date, msg?: string): boolean; + notAfterDate(val: Date, exp: Date, msg?: string): boolean; } } From 3ceb61d01e4c39d7de1df4241b0c0b7c5939996f Mon Sep 17 00:00:00 2001 From: Seon-Wook Park Date: Fri, 2 May 2014 16:45:24 +0200 Subject: [PATCH 21/49] node-uuid: Let require("node-uuid") work in nodejs --- node-uuid/node-uuid.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node-uuid/node-uuid.d.ts b/node-uuid/node-uuid.d.ts index 48a3422049..d4857cf310 100644 --- a/node-uuid/node-uuid.d.ts +++ b/node-uuid/node-uuid.d.ts @@ -46,7 +46,7 @@ interface UUID { v4(options?: UUIDOptions, buffer?: Buffer, offset?: number): string } -declare module 'uuid' { +declare module "node-uuid" { var uuid: UUID; export = uuid; } From fe6c5d8ef7fb818b6102f3f70925614bb154b272 Mon Sep 17 00:00:00 2001 From: vvakame Date: Sun, 4 May 2014 01:47:48 +0900 Subject: [PATCH 22/49] added EditorView declaration to atom/atom.d.ts --- atom/atom.d.ts | 644 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 478 insertions(+), 166 deletions(-) diff --git a/atom/atom.d.ts b/atom/atom.d.ts index 14a8dbebae..3791a11cf8 100644 --- a/atom/atom.d.ts +++ b/atom/atom.d.ts @@ -4,6 +4,7 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// +/// /// /// @@ -108,214 +109,214 @@ declare module AtomCore { getLongTitle():string; setVisible(visible:boolean):void; setScrollTop(scrollTop:any):void; - getScrollTop():any; + getScrollTop():number; setScrollLeft(scrollLeft:any):void; - getScrollLeft():any; + getScrollLeft():number; setEditorWidthInChars(editorWidthInChars:any):void; - getSoftWrapColumn():any; + getSoftWrapColumn():number; getSoftTabs():boolean; setSoftTabs(softTabs:boolean):void; - getSoftWrap():any; + getSoftWrap():boolean; setSoftWrap(softWrap:any):void; - getTabText():any; - getTabLength():any; + getTabText():string; + getTabLength():number; setTabLength(tabLength:any):void; clipBufferPosition(bufferPosition:any):void; clipBufferRange(range:any):void; indentationForBufferRow(bufferRow:any):void; setIndentationForBufferRow(bufferRow:any, newLevel:any, _arg:any):void; indentLevelForLine(line:any):number; - buildIndentString(number:any):any; + buildIndentString(number:any):string; save():void; saveAs(filePath:any):void; - getPath():any; - getText():any; + getPath():string; + getText():string; setText(text:any):void; getTextInRange(range:any):any; - getLineCount():any; - getBuffer():any; - getUri():any; - isBufferRowBlank(bufferRow:any):void; + getLineCount():number; + getBuffer():ITextBuffer; + getUri():string; + isBufferRowBlank(bufferRow:any):boolean; isBufferRowCommented(bufferRow:any):void; nextNonBlankBufferRow(bufferRow:any):void; - getEofBufferPosition():any; - getLastBufferRow():any; - bufferRangeForBufferRow(row:any, options:any):any; - lineForBufferRow(row:any):any; - lineLengthForBufferRow(row:any):any; + getEofBufferPosition():IPoint; + getLastBufferRow():number; + bufferRangeForBufferRow(row:any, options:any):IRange; + lineForBufferRow(row:number):string; + lineLengthForBufferRow(row:number):number; scan():any; scanInBufferRange():any; backwardsScanInBufferRange():any; - isModified():any; - shouldPromptToSave():any; - screenPositionForBufferPosition(bufferPosition:any, options:any):any; - bufferPositionForScreenPosition(screenPosition:any, options:any):any; - screenRangeForBufferRange(bufferRange:any):any; - bufferRangeForScreenRange(screenRange:any):any; - clipScreenPosition(screenPosition:any, options:any):any; - lineForScreenRow(row:any):any; - linesForScreenRows(start:any, end:any):any; - getScreenLineCount():any; - getMaxScreenLineLength():any; - getLastScreenRow():any; - bufferRowsForScreenRows(startRow:any, endRow:any):any; - bufferRowForScreenRow(row:any):any; - scopesForBufferPosition(bufferPosition:any):any; - bufferRangeForScopeAtCursor(selector:any):any; - tokenForBufferPosition(bufferPosition:any):any; - getCursorScopes():any; - insertText(text:any, options:any):any; - insertNewline():any; - insertNewlineBelow():any; + isModified():boolean; + shouldPromptToSave():boolean; + screenPositionForBufferPosition(bufferPosition:any, options?:any):IPoint; + bufferPositionForScreenPosition(screenPosition:any, options?:any):IPoint; + screenRangeForBufferRange(bufferRange:any):IRange; + bufferRangeForScreenRange(screenRange:any):IRange; + clipScreenPosition(screenPosition:any, options:any):IRange; + lineForScreenRow(row:any):ITokenizedLine; + linesForScreenRows(start?:any, end?:any):ITokenizedLine[]; + getScreenLineCount():number; + getMaxScreenLineLength():number; + getLastScreenRow():number; + bufferRowsForScreenRows(startRow:any, endRow:any):any[]; + bufferRowForScreenRow(row:any):number; + scopesForBufferPosition(bufferPosition:any):string[]; + bufferRangeForScopeAtCursor(selector:string):any; + tokenForBufferPosition(bufferPosition:any):IToken; + getCursorScopes():string[]; + insertText(text:string, options?:any):IRange[]; + insertNewline():IRange[]; + insertNewlineBelow():IRange[]; insertNewlineAbove():any; indent(options?:any):any; - backspace():any; - backspaceToBeginningOfWord():any; - backspaceToBeginningOfLine():any; - delete():any; - deleteToEndOfWord():any; - deleteLine():any; - indentSelectedRows():any; - outdentSelectedRows():any; - toggleLineCommentsInSelection():any; - autoIndentSelectedRows():any; + backspace():any[]; + backspaceToBeginningOfWord():any[]; + backspaceToBeginningOfLine():any[]; + delete():any[]; + deleteToEndOfWord():any[]; + deleteLine():IRange[]; + indentSelectedRows():IRange[][]; + outdentSelectedRows():IRange[][]; + toggleLineCommentsInSelection():IRange[]; + autoIndentSelectedRows():IRange[][]; normalizeTabsInBufferRange(bufferRange:any):any; - cutToEndOfLine():any; - cutSelectedText():any; - copySelectedText():any; - pasteText(options?:any):any; - undo():any; - redo():any; + cutToEndOfLine():boolean[]; + cutSelectedText():boolean[]; + copySelectedText():boolean[]; + pasteText(options?:any):IRange[]; + undo():any[]; + redo():any[]; foldCurrentRow():any; - unfoldCurrentRow():any; - foldSelectedLines():any; - foldAll():any; - unfoldAll():any; + unfoldCurrentRow():any[]; + foldSelectedLines():any[]; + foldAll():any[]; + unfoldAll():any[]; foldAllAtIndentLevel(level:any):any; foldBufferRow(bufferRow:any):any; unfoldBufferRow(bufferRow:any):any; - isFoldableAtBufferRow(bufferRow:any):any; - createFold(startRow:any, endRow:any):any; + isFoldableAtBufferRow(bufferRow:any):boolean; + createFold(startRow:any, endRow:any):IFold; destroyFoldWithId(id:any):any; destroyFoldsIntersectingBufferRange(bufferRange:any):any; toggleFoldAtBufferRow(bufferRow:any):any; - isFoldedAtCursorRow():any; - isFoldedAtBufferRow(bufferRow:any):any; - isFoldedAtScreenRow(screenRow:any):any; - largestFoldContainingBufferRow(bufferRow:any):any; + isFoldedAtCursorRow():boolean; + isFoldedAtBufferRow(bufferRow:any):boolean; + isFoldedAtScreenRow(screenRow:any):boolean; + largestFoldContainingBufferRow(bufferRow:any):boolean; largestFoldStartingAtScreenRow(screenRow:any):any; - outermostFoldsInBufferRowRange(startRow:any, endRow:any):any; - moveLineUp():any; - moveLineDown():any; - duplicateLines():any; - duplicateLine():any; - mutateSelectedText(fn:Function):any; - replaceSelectedText(options:any, fn:Function):any; - getMarker(id:any):any; - getMarkers():any; - findMarkers(properties:any):any; - markScreenRange():any; - markBufferRange():any; - markScreenPosition():any; - markBufferPosition():any; - destroyMarker():any; - getMarkerCount():any; - hasMultipleCursors():any; - getCursors():any; - getCursor():any; - addCursorAtScreenPosition(screenPosition:any):any; - addCursorAtBufferPosition(bufferPosition:any):any; - addCursor(marker:any):any; - removeCursor(cursor:any):any; - addSelection(marker:any, options:any):any; - addSelectionForBufferRange(bufferRange:any, options:any):any; + outermostFoldsInBufferRowRange(startRow:any, endRow:any):any[]; + moveLineUp():ISelection[]; + moveLineDown():ISelection[]; + duplicateLines():any[][]; + duplicateLine():any[][]; + mutateSelectedText(fn:(selection:ISelection)=>any):any; + replaceSelectedText(options:any, fn:(selection:string)=>any):any; + getMarker(id:number):IDisplayBufferMarker; + getMarkers():IDisplayBufferMarker[]; + findMarkers(properties:any):IDisplayBufferMarker[]; + markScreenRange(value:number):IDisplayBufferMarker; + markBufferRange(value:number):IDisplayBufferMarker; + markScreenPosition(value:number):IDisplayBufferMarker; + markBufferPosition():IDisplayBufferMarker; + destroyMarker():boolean; + getMarkerCount():number; + hasMultipleCursors():boolean; + getCursors():ICursor[]; + getCursor():ICursor; + addCursorAtScreenPosition(screenPosition:any):ICursor; + addCursorAtBufferPosition(bufferPosition:any):ICursor; + addCursor(marker:any):ICursor; + removeCursor(cursor:any):ICursor[]; + addSelection(marker:any, options:any):ISelection; + addSelectionForBufferRange(bufferRange:any, options:any):ISelection; setSelectedBufferRange(bufferRange:any, options:any):any; setSelectedBufferRanges(bufferRanges:any, options:any):any; - removeSelection(selection:any):any; - clearSelections():any; - consolidateSelections():any; - getSelections():any; - getSelection(index:any):any; - getLastSelection():any; - getSelectionsOrderedByBufferPosition():any; - getLastSelectionInBuffer():any; + removeSelection(selection:ISelection):any; + clearSelections():boolean; + consolidateSelections():boolean; + getSelections():ISelection[]; + getSelection(index?:number):ISelection; + getLastSelection():ISelection; + getSelectionsOrderedByBufferPosition():ISelection[]; + getLastSelectionInBuffer():ISelection; selectionIntersectsBufferRange(bufferRange:any):any; setCursorScreenPosition(position:any, options:any):any; - getCursorScreenPosition():any; - getCursorScreenRow():any; + getCursorScreenPosition():IPoint; + getCursorScreenRow():number; setCursorBufferPosition(position:any, options:any):any; - getCursorBufferPosition():any; - getSelectedScreenRange():any; - getSelectedBufferRange():any; - getSelectedBufferRanges():any; - getSelectedText():any; - getTextInBufferRange(range:any):any; - setTextInBufferRange(range:any, text:any):any; - getCurrentParagraphBufferRange():any; - getWordUnderCursor(options:any):any; - moveCursorUp(lineCount:any):any; - moveCursorDown(lineCount:any):any; - moveCursorLeft():any; - moveCursorRight():any; - moveCursorToTop():any; - moveCursorToBottom():any; - moveCursorToBeginningOfScreenLine():any; - moveCursorToBeginningOfLine():any; - moveCursorToFirstCharacterOfLine():any; - moveCursorToEndOfScreenLine():any; - moveCursorToEndOfLine():any; - moveCursorToBeginningOfWord():any; - moveCursorToEndOfWord():any; - moveCursorToBeginningOfNextWord():any; - moveCursorToPreviousWordBoundary():any; - moveCursorToNextWordBoundary():any; - moveCursors(fn:Function):any; - selectToScreenPosition(position:any):any; - selectRight():any; - selectLeft():any; - selectUp(rowCount:any):any; - selectDown(rowCount:any):any; - selectToTop():any; - selectAll():any; - selectToBottom():any; - selectToBeginningOfLine():any; - selectToFirstCharacterOfLine():any; - selectToEndOfLine():any; - selectToPreviousWordBoundary():any; - selectToNextWordBoundary():any; - selectLine():any; - addSelectionBelow():any; - addSelectionAbove():any; - splitSelectionsIntoLines():any; - transpose():any; - upperCase():any; - lowerCase():any; - joinLines():any; - selectToBeginningOfWord():any; - selectToEndOfWord():any; - selectToBeginningOfNextWord():any; - selectWord():any; + getCursorBufferPosition():IPoint; + getSelectedScreenRange():IRange; + getSelectedBufferRange():IRange; + getSelectedBufferRanges():IRange[]; + getSelectedText():string; + getTextInBufferRange(range:IRange):string; + setTextInBufferRange(range:IRange, text:string):any; + getCurrentParagraphBufferRange():IRange; + getWordUnderCursor(options?:any):string; + moveCursorUp(lineCount?:number):void; + moveCursorDown(lineCount?:number):void; + moveCursorLeft():void; + moveCursorRight():void; + moveCursorToTop():void; + moveCursorToBottom():void; + moveCursorToBeginningOfScreenLine():void; + moveCursorToBeginningOfLine():void; + moveCursorToFirstCharacterOfLine():void; + moveCursorToEndOfScreenLine():void; + moveCursorToEndOfLine():void; + moveCursorToBeginningOfWord():void; + moveCursorToEndOfWord():void; + moveCursorToBeginningOfNextWord():void; + moveCursorToPreviousWordBoundary():void; + moveCursorToNextWordBoundary():void; + moveCursors(fn:(cursor:ICursor)=>any):any; + selectToScreenPosition(position:IPoint):any; + selectRight():ISelection[]; + selectLeft():ISelection[]; + selectUp(rowCount?:number):ISelection[]; + selectDown(rowCount?:number):ISelection[]; + selectToTop():ISelection[]; + selectAll():ISelection[]; + selectToBottom():ISelection[]; + selectToBeginningOfLine():ISelection[]; + selectToFirstCharacterOfLine():ISelection[]; + selectToEndOfLine():ISelection[]; + selectToPreviousWordBoundary():ISelection[]; + selectToNextWordBoundary():ISelection[]; + selectLine():ISelection[]; + addSelectionBelow():ISelection[]; + addSelectionAbove():ISelection[]; + splitSelectionsIntoLines():any[]; + transpose():IRange[]; + upperCase():boolean[]; + lowerCase():boolean[]; + joinLines():any[]; + selectToBeginningOfWord():ISelection[]; + selectToEndOfWord():ISelection[]; + selectToBeginningOfNextWord():ISelection[]; + selectWord():ISelection[]; selectMarker(marker:any):any; - mergeCursors():any; + mergeCursors():number[]; expandSelectionsForward():any; - expandSelectionsBackward(fn:Function):any; - finalizeSelections():any; + expandSelectionsBackward(fn:(selection:ISelection)=>any):ISelection[]; + finalizeSelections():boolean[]; mergeIntersectingSelections():any; - preserveCursorPositionOnBufferReload():any; + preserveCursorPositionOnBufferReload():ISubscription; getGrammar(): IGrammar; setGrammar(grammer:IGrammar):void; reloadGrammar():any; - shouldAutoIndent():any; + shouldAutoIndent():boolean; transact(fn:Function):any; - beginTransaction():any; + beginTransaction():ITransaction; commitTransaction():any; - abortTransaction():any; - inspect():any; - logScreenLines(start:any, end:any):any; - handleGrammarChange():any; + abortTransaction():any[]; + inspect():string; + logScreenLines(start:number, end:number):any[]; + handleGrammarChange():void; handleMarkerCreated(marker:any):any; - getSelectionMarkerAttributes():any; - joinLine():any; + getSelectionMarkerAttributes():{type: string; editorId: number; invalidate: string; }; + // joinLine():any; // deprecated } interface IGrammar { @@ -686,6 +687,26 @@ declare module AtomCore { // TBD } + interface ITokenizedLine { + // TBD + } + + interface IToken { + // TBD + } + + interface IFold { + // TBD + } + + interface IDisplayBufferMarker { + // TBD + } + + interface ITransaction { + // TBD + } + interface ITaskStatic { new(taskPath:any):ITask; } @@ -705,7 +726,6 @@ declare module "atom" { var BufferedNodeProcess:AtomCore.IBufferedNodeProcessStatic; var BufferedProcess:AtomCore.IBufferedProcessStatic; - var EditorView:any; var Git:AtomCore.IGitStatic; var Point:AtomCore.IPointStatic; var Range:AtomCore.IRangeStatic; @@ -725,12 +745,304 @@ declare module "atom" { unsubscribe(object?:any):any; } + class EditorView extends View { + static characterWidthCache:any; + static configDefaults:any; + static nextEditorId:number; + + static content(params:any):void; + + static classes(_arg?:{mini?:any}):string; + + vScrollMargin:number; + hScrollMargin:number; + lineHeight:any; + charWidth:any; + charHeight:any; + cursorViews:any[]; + selectionViews:any[]; + lineCache:any[]; + isFocused:any; + editor:AtomCore.IEditor; + attached:any; + lineOverdraw:number; + pendingChanges:any[]; + newCursors:any[]; + newSelections:any[]; + redrawOnReattach:any; + bottomPaddingInLines:number; + + id:number; + + + initialize(editorOrOptions:AtomCore.IEditor):void; // return type are same as editor method. + initialize(editorOrOptions?:{editor: AtomCore.IEditor; mini:any; placeholderText:any}):void; + + initialize(editorOrOptions:{}):void; // compatible for spacePen.View + + bindKeys():void; + + getEditor():AtomCore.IEditor; + + getText():string; + + setText(text:string):void; + + insertText(text:string, options?:any):AtomCore.IRange[]; + + setHeightInLines(heightInLines:number):number; + + setWidthInChars(widthInChars:number):number; + + pageDown():void; + + pageUp():void; + + getPageRows():number; + + setShowInvisibles(showInvisibles:boolean):void; + + setInvisibles(invisibles:{ eol:string; space: string; tab: string; cr: string; }):void; + + setShowIndentGuide(showIndentGuide:boolean):void; + + setPlaceholderText(placeholderText:string):void; + + getPlaceholderText():string; + + checkoutHead():boolean; + + configure():AtomCore.ISubscription; + + handleEvents():void; + + handleInputEvents():void; + + bringHiddenInputIntoView():JQuery; + + selectOnMousemoveUntilMouseup():any; + + afterAttach(onDom:any):any; + + edit(editor:AtomCore.IEditor):any; + + getModel():AtomCore.IEditor; + + setModel(editor:AtomCore.IEditor):any; + + showBufferConflictAlert(editor:AtomCore.IEditor):any; + + scrollTop(scrollTop:number, options?:any):any; + + scrollBottom(scrollBottom?:number):any; + + scrollLeft(scrollLeft?:number):number; + + scrollRight(scrollRight?:number):any; + + scrollToBottom():any; + + scrollToCursorPosition():any; + + scrollToBufferPosition(bufferPosition:any, options:any):any; + + scrollToScreenPosition(screenPosition:any, options:any):any; + + scrollToPixelPosition(pixelPosition:any, options:any):any; + + highlightFoldsContainingBufferRange(bufferRange:any):any; + + saveScrollPositionForEditor():any; + + toggleSoftTabs():any; + + toggleSoftWrap():any; + + calculateWidthInChars():number; + + calculateHeightInLines():number; + + getScrollbarWidth():number; + + setSoftWrap(softWrap:boolean):any; + + setFontSize(fontSize:number):any; + + getFontSize():number; + + setFontFamily(fontFamily?:string):any; + + getFontFamily():string; + + setLineHeight(lineHeight:number):any; + + redraw():any; + + splitLeft():any; + + splitRight():any; + + splitUp():any; + + splitDown():any; + + getPane():any; // return type are PaneView + + remove(selector:any, keepData:any):any; + + beforeRemove():any; + + getCursorView(index?:number):any; // return type are CursorView + + getCursorViews():any[]; // return type are CursorView[] + + addCursorView(cursor:any, options:any):any; // return type are CursorView + + removeCursorView(cursorView:any):any; + + getSelectionView(index?:number):any; // return type are SelectionView + + getSelectionViews():any[]; // return type are SelectionView[] + + addSelectionView(selection:any):any; + + removeSelectionView(selectionView:any):any; + + removeAllCursorAndSelectionViews():any[]; + + appendToLinesView(view:any):any; + + scrollVertically(pixelPosition:any, _arg:any):any; + + scrollHorizontally(pixelPosition:any):any; + + calculateDimensions():number; + + recalculateDimensions():any; + + updateLayerDimensions():any; + + isHidden():boolean; + + clearRenderedLines():void; + + resetDisplay():any; + + requestDisplayUpdate():any; + + updateDisplay(options?:any):any; + + updateCursorViews():any; + + shouldUpdateCursor(cursorView:any):any; + + updateSelectionViews():any[]; + + shouldUpdateSelection(selectionView:any):any; + + syncCursorAnimations():any[]; + + autoscroll(suppressAutoscroll?:any):any[]; + + updatePlaceholderText():any; + + updateRenderedLines(scrollViewWidth:any):any; + + computeSurroundingEmptyLineChanges(change:any):any; + + computeIntactRanges(renderFrom:any, renderTo:any):any; + + truncateIntactRanges(intactRanges:any, renderFrom:any, renderTo:any):any; + + clearDirtyRanges(intactRanges:any):any; + + clearLine(lineElement:any):any; + + fillDirtyRanges(intactRanges:any, renderFrom:any, renderTo:any):any; + + updatePaddingOfRenderedLines():any; + + getFirstVisibleScreenRow():number; + + getLastVisibleScreenRow():number; + + isScreenRowVisible():boolean; + + handleScreenLinesChange(change:any):any; + + buildLineElementForScreenRow(screenRow:any):any; + + buildLineElementsForScreenRows(startRow:any, endRow:any):any; + + htmlForScreenRows(startRow:any, endRow:any):any; + + htmlForScreenLine(screenLine:any, screenRow:any):any; + + buildIndentation(screenRow:any, editor:any):any; + + buildHtmlEndOfLineInvisibles(screenLine:any):any; + + getEndOfLineInvisibles(screenLine:any):any; + + lineElementForScreenRow(screenRow:any):any; + + toggleLineCommentsInSelection():any; + + pixelPositionForBufferPosition(position:any):any; + + pixelPositionForScreenPosition(position:any):any; + + positionLeftForLineAndColumn(lineElement:any, screenRow:any, screenColumn:any):any; + + measureToColumn(lineElement:any, tokenizedLine:any, screenColumn:any):any; + + getCharacterWidthCache(scopes:any, char:any):any; + + setCharacterWidthCache(scopes:any, char:any, val:any):any; + + clearCharacterWidthCache():any; + + pixelOffsetForScreenPosition(position:any):any; + + screenPositionFromMouseEvent(e:any):any; + + highlightCursorLine():any; + + copyPathToClipboard():any; + + buildLineHtml(_arg:any):any; + + updateScopeStack(line:any, scopeStack:any, desiredScopes:any):any; + + pushScope(line:any, scopeStack:any, scope:any):any; + + popScope(line:any, scopeStack:any):any; + + buildEmptyLineHtml(showIndentGuide:any, eolInvisibles:any, htmlEolInvisibles:any, indentation:any, editor:any, mini:any):any; + + replaceSelectedText(replaceFn:(str:string)=>string):any; + + consolidateSelections(e:any):any; + + logCursorScope():any; + + logScreenLines(start:any, end:any):any; + + logRenderedLines():any; + } + class ScrollView extends View { // TBD } - var SelectListView:any; + class SelectListView extends View { + // TBD + } + + class WorkspaceView extends View { + // TBD + } + var Task:AtomCore.ITaskStatic; var Workspace:AtomCore.IWorkspaceStatic; - var WorkspaceView:any; // WorkspaceView extends View } From 9a8241a51e391b789e8949a26e1388aaf15e9597 Mon Sep 17 00:00:00 2001 From: vvakame Date: Sun, 4 May 2014 02:11:16 +0900 Subject: [PATCH 23/49] improve AtomCore.ISelection definition in atom/atom.d.ts --- atom/atom.d.ts | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/atom/atom.d.ts b/atom/atom.d.ts index 3791a11cf8..e976116d1a 100644 --- a/atom/atom.d.ts +++ b/atom/atom.d.ts @@ -40,7 +40,7 @@ declare module AtomCore { // TBD } - interface TreeView { + interface ITreeView { // TBD } @@ -65,8 +65,82 @@ declare module AtomCore { // TBD } - interface ISelection { - // TBD + interface ISelection /* extends Theorist.Model */ { + cursor:ICursor; + marker:IDisplayBufferMarker; + editor:IEditor; + initialScreenRange:any; + wordwise:boolean; + needsAutoscroll:boolean; + retainSelection:boolean; + subscriptionCounts:any; + + destroy():any; + finalize():any; + clearAutoscroll():any; + isEmpty():boolean; + isReversed():boolean; + isSingleScreenLine():boolean; + getScreenRange():IRange; + setScreenRange(screenRange:any, options:any):any; + getBufferRange():IRange; + setBufferRange(bufferRange:any, options:any):any; + getBufferRowRange():number[]; + autoscroll():void; + getText():string; + clear():boolean; + selectWord():IRange; + expandOverWord():any; + selectLine(row?:any):IRange; + expandOverLine():boolean; + selectToScreenPosition(position:any):any; + selectToBufferPosition(position:any):any; + selectRight():boolean; + selectLeft():boolean; + selectUp(rowCount?:any):boolean; + selectDown(rowCount?:any):boolean; + selectToTop():any; + selectToBottom():any; + selectAll():any; + selectToBeginningOfLine():any; + selectToFirstCharacterOfLine():any; + selectToEndOfLine():any; + selectToBeginningOfWord():any; + selectToEndOfWord():any; + selectToBeginningOfNextWord():any; + selectToPreviousWordBoundary():any; + selectToNextWordBoundary():any; + addSelectionBelow():any; + getGoalBufferRange():any; + addSelectionAbove():any[]; + insertText(text:string, options?:any):any; + normalizeIndents(text:string, indentBasis:number):any; + indent(_arg?:any):any; + indentSelectedRows():IRange[]; + setIndentationForLine(line:string, indentLevel:number):any; + backspace():any; + backspaceToBeginningOfWord():any; + backspaceToBeginningOfLine():any; + delete():any; + deleteToEndOfWord():any; + deleteSelectedText():any; + deleteLine():any; + joinLines():any; + outdentSelectedRows():any[]; + autoIndentSelectedRows():any; + toggleLineComments():any; + cutToEndOfLine(maintainClipboard:any):any; + cut(maintainClipboard:any):any; + copy(maintainClipboard:any):any; + fold():any; + modifySelection(fn:()=>any):any; + plantTail():any; + intersectsBufferRange(bufferRange:any):any; + intersectsWith(otherSelection:any):any; + merge(otherSelection:any, options:any):any; + compare(otherSelection:any):any; + getRegionRects():any[]; + screenRangeChanged():any; } interface ISubscription { From 3cdedd857ab258793f81d8715c062d387dc1991d Mon Sep 17 00:00:00 2001 From: vvakame Date: Sun, 4 May 2014 02:23:32 +0900 Subject: [PATCH 24/49] improve AtomCore.IPointStatic and AtomCore.IPoint definition in atom/atom.d.ts --- atom/atom.d.ts | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/atom/atom.d.ts b/atom/atom.d.ts index e976116d1a..42f1860063 100644 --- a/atom/atom.d.ts +++ b/atom/atom.d.ts @@ -746,11 +746,49 @@ declare module AtomCore { } interface IPointStatic { - new(row:any, column:any):IPoint; + new (row?:number, column?:number):IPoint; + + fromObject(point:IPoint, copy?:boolean):IPoint; + fromObject(object:number[]):IPoint; + fromObject(object:{row:number; col:number;}):IPoint; + + min(point1:IPoint, point2:IPoint):IPoint; + min(point1:number[], point2:IPoint):IPoint; + min(point1:{row:number; col:number;}, point2:IPoint):IPoint; + + min(point1:IPoint, point2:number[]):IPoint; + min(point1:number[], point2:number[]):IPoint; + min(point1:{row:number; col:number;}, point2:number[]):IPoint; + + min(point1:IPoint, point2:{row:number; col:number;}):IPoint; + min(point1:number[], point2:{row:number; col:number;}):IPoint; + min(point1:{row:number; col:number;}, point2:{row:number; col:number;}):IPoint; } interface IPoint { - // TBD + row:number; + column:number; + + copy():IPoint; + freeze():IPoint; + + translate(delta:IPoint):IPoint; + translate(delta:number[]):IPoint; + translate(delta:{row:number; col:number;}):IPoint; + + add(other:IPoint):IPoint; + add(other:number[]):IPoint; + add(other:{row:number; col:number;}):IPoint; + + splitAt(column:number):IPoint[]; + compare(other:IPoint):number; + isEqual(other:IPoint):boolean; + isLessThan(other:IPoint):boolean; + isLessThanOrEqual(other:IPoint):boolean; + isGreaterThan(other:IPoint):boolean; + isGreaterThanOrEqual(other:IPoint):boolean; + toArray():number[]; + serialize():number[]; } interface IRangeStatic { From 5801fa46c24fcb37036c83d639189dfd769f55fb Mon Sep 17 00:00:00 2001 From: vvakame Date: Sun, 4 May 2014 02:47:59 +0900 Subject: [PATCH 25/49] improve AtomCore.IRangeStatic and AtomCore.IRange in atom/atom.d.ts --- atom/atom.d.ts | 101 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/atom/atom.d.ts b/atom/atom.d.ts index 42f1860063..106c6f318e 100644 --- a/atom/atom.d.ts +++ b/atom/atom.d.ts @@ -766,6 +766,8 @@ declare module AtomCore { } interface IPoint { + constructor: IPointStatic; + row:number; column:number; @@ -792,11 +794,106 @@ declare module AtomCore { } interface IRangeStatic { - new(pointA:IPoint, pointB:IPoint):IRange; + deserialize(array:IPoint[]):IRange; + + fromObject(object:IPoint[]):IRange; + + fromObject(object:IRange, copy?:boolean):IRange; + + fromObject(object:{start: IPoint; end: IPoint}):IRange; + fromObject(object:{start: number[]; end: IPoint}):IRange; + fromObject(object:{start: {row:number; col:number;}; end: IPoint}):IRange; + + fromObject(object:{start: IPoint; end: number[]}):IRange; + fromObject(object:{start: number[]; end: number[]}):IRange; + fromObject(object:{start: {row:number; col:number;}; end: number[]}):IRange; + + fromObject(object:{start: IPoint; end: {row:number; col:number;}}):IRange; + fromObject(object:{start: number[]; end: {row:number; col:number;}}):IRange; + fromObject(object:{start: {row:number; col:number;}; end: {row:number; col:number;}}):IRange; + + fromText(point:IPoint, text:string):IRange; + fromText(point:number[], text:string):IRange; + fromText(point:{row:number; col:number;}, text:string):IRange; + fromText(text:string):IRange; + + fromPointWithDelta(startPoint:IPoint, rowDelta:number, columnDelta:number):IRange; + fromPointWithDelta(startPoint:number[], rowDelta:number, columnDelta:number):IRange; + fromPointWithDelta(startPoint:{row:number; col:number;}, rowDelta:number, columnDelta:number):IRange; + + new(point1:IPoint, point2:IPoint):IRange; + new(point1:number[], point2:IPoint):IRange; + new(point1:{row:number; col:number;}, point2:IPoint):IRange; + + new(point1:IPoint, point2:number[]):IRange; + new(point1:number[], point2:number[]):IRange; + new(point1:{row:number; col:number;}, point2:number[]):IRange; + + new(point1:IPoint, point2:{row:number; col:number;}):IRange; + new(point1:number[], point2:{row:number; col:number;}):IRange; + new(point1:{row:number; col:number;}, point2:{row:number; col:number;}):IRange; } interface IRange { - // TBD + constructor:IRangeStatic; + + start: IPoint; + end: IPoint; + + serialize():number[][]; + copy():IRange; + freeze():IRange; + isEqual(other:IRange):boolean; + isEqual(other:IPoint[]):boolean; + + compare(object:IPoint[]):number; + + compare(object:{start: IPoint; end: IPoint}):number; + compare(object:{start: number[]; end: IPoint}):number; + compare(object:{start: {row:number; col:number;}; end: IPoint}):number; + + compare(object:{start: IPoint; end: number[]}):number; + compare(object:{start: number[]; end: number[]}):number; + compare(object:{start: {row:number; col:number;}; end: number[]}):number; + + compare(object:{start: IPoint; end: {row:number; col:number;}}):number; + compare(object:{start: number[]; end: {row:number; col:number;}}):number; + compare(object:{start: {row:number; col:number;}; end: {row:number; col:number;}}):number; + + isSingleLine():boolean; + coversSameRows(other:IRange):boolean; + + add(object:IPoint[]):IRange; + + add(object:{start: IPoint; end: IPoint}):IRange; + add(object:{start: number[]; end: IPoint}):IRange; + add(object:{start: {row:number; col:number;}; end: IPoint}):IRange; + + add(object:{start: IPoint; end: number[]}):IRange; + add(object:{start: number[]; end: number[]}):IRange; + add(object:{start: {row:number; col:number;}; end: number[]}):IRange; + + add(object:{start: IPoint; end: {row:number; col:number;}}):IRange; + add(object:{start: number[]; end: {row:number; col:number;}}):IRange; + add(object:{start: {row:number; col:number;}; end: {row:number; col:number;}}):IRange; + + translate(startPoint:IPoint, endPoint:IPoint):IRange; + translate(startPoint:IPoint):IRange; + + intersectsWith(otherRange:IRange):boolean; + containsRange(otherRange:IRange, exclusive:boolean):boolean; + + containsPoint(point:IPoint, exclusive:boolean):boolean; + containsPoint(point:number[], exclusive:boolean):boolean; + containsPoint(point:{row:number; col:number;}, exclusive:boolean):boolean; + + intersectsRow(row:number):boolean; + intersectsRowRange(startRow:number, endRow:number):boolean; + union(otherRange:IRange):IRange; + isEmpty():boolean; + toDelta():IPoint; + getRowCount():number; + getRows():number[]; } interface ITokenizedLine { From f8b43ffd5c92a1e269f4ffa322eec247dc11608c Mon Sep 17 00:00:00 2001 From: vvakame Date: Sun, 4 May 2014 03:03:27 +0900 Subject: [PATCH 26/49] improve AtomCore.IDisplayBufferMarkerStatic and AtomCore.IDisplayBufferMarker in atom/atom.d.ts --- atom/atom.d.ts | 59 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/atom/atom.d.ts b/atom/atom.d.ts index 106c6f318e..cef13f81c6 100644 --- a/atom/atom.d.ts +++ b/atom/atom.d.ts @@ -908,14 +908,69 @@ declare module AtomCore { // TBD } - interface IDisplayBufferMarker { - // TBD + interface IDisplayBufferMarkerStatic { + new (_arg:{bufferMarker:IMarker; displayBuffer: IDisplayBuffer}):IDisplayBufferMarker; + } + + interface IDisplayBufferMarker extends Emissary.IEmitter, Emissary.ISubscriber { + constructor:IDisplayBufferMarkerStatic; + + id: number; + + bufferMarkerSubscription:any; + oldHeadBufferPosition:IPoint; + oldHeadScreenPosition:IPoint; + oldTailBufferPosition:IPoint; + oldTailScreenPosition:IPoint; + wasValid:boolean; + + bufferMarker: IMarker; + displayBuffer: IDisplayBuffer; + globalPauseCount:number; + globalQueuedEvents:any; + + subscriptions:ISubscription[]; + subscriptionsByObject:any; // WeakMap + + copy(attributes?:any /* maybe IMarker */):IDisplayBufferMarker; + getScreenRange():IRange; + setScreenRange(screenRange:any, options:any):any; + getBufferRange():IRange; + setBufferRange(bufferRange:any, options:any):any; + getPixelRange():any; + getHeadScreenPosition():IPoint; + setHeadScreenPosition(screenPosition:any, options:any):any; + getHeadBufferPosition():IPoint; + setHeadBufferPosition(bufferPosition:any):any; + getTailScreenPosition():IPoint; + setTailScreenPosition(screenPosition:any, options:any):any; + getTailBufferPosition():IPoint; + setTailBufferPosition(bufferPosition:any):any; + plantTail():boolean; + clearTail():boolean; + hasTail():boolean; + isReversed():boolean; + isValid():boolean; + isDestroyed():boolean; + getAttributes():any; + setAttributes(attributes:any):any; + matchesAttributes(attributes:any):any; + destroy():any; + isEqual(other:IDisplayBufferMarker):boolean; + compare(other:IDisplayBufferMarker):boolean; + inspect():string; + destroyed():any; + notifyObservers(_arg:any):any; } interface ITransaction { // TBD } + interface IMarker { + // TBD + } + interface ITaskStatic { new(taskPath:any):ITask; } From 8433ce18732b6627a85145592612433d81ab3d54 Mon Sep 17 00:00:00 2001 From: vvakame Date: Sun, 4 May 2014 04:11:02 +0900 Subject: [PATCH 27/49] improve AtomCore.IDisplayBufferStatic and AtomCore.IDisplayBuffer in atom/atom.d.ts --- atom/atom.d.ts | 214 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 211 insertions(+), 3 deletions(-) diff --git a/atom/atom.d.ts b/atom/atom.d.ts index cef13f81c6..1dd2694df3 100644 --- a/atom/atom.d.ts +++ b/atom/atom.d.ts @@ -52,9 +52,201 @@ declare module AtomCore { // TBD } - interface IDisplayBuffer { + interface IDisplayBufferStatic { + new(_arg?:any):IDisplayBuffer; + } + + interface IDisplayBuffer /* extends Theorist.Model */ { + // Serializable.includeInto(Editor); + + constructor:IDisplayBufferStatic; + + verticalScrollMargin:number; + horizontalScrollMargin:number; + + declaredPropertyValues:any; + tokenizedBuffer: ITokenizedBuffer; buffer: ITextBuffer; - // TBD + charWidthsByScope:any; + markers:{ [index:number]:IDisplayBufferMarker; }; + foldsByMarkerId:any; + maxLineLength:number; + screenLines:ITokenizedLine[]; + rowMap:any; // return type are RowMap + longestScreenRow:number; + subscriptions:ISubscription[]; + subscriptionsByObject:any; // return type are WeakMap + behaviors:any; + subscriptionCounts:any; + eventHandlersByEventName:any; + pendingChangeEvent:any; + + softWrap:boolean; + + serializeParams():{id:number; softWrap:boolean; editorWidthInChars: number; scrollTop: number; scrollLeft: number; tokenizedBuffer: any; }; + deserializeParams(params:any):any; + copy():IDisplayBuffer; + updateAllScreenLines():any; + emitChanged(eventProperties:any, refreshMarkers?:boolean):any; + updateWrappedScreenLines():any; + setVisible(visible:any):any; + getVerticalScrollMargin():number; + setVerticalScrollMargin(verticalScrollMargin:number):number; + getHorizontalScrollMargin():number; + setHorizontalScrollMargin(horizontalScrollMargin:number):number; + getHeight():any; + setHeight(height:any):any; + getWidth():any; + setWidth(newWidth:any):any; + getScrollTop():number; + setScrollTop(scrollTop:number):number; + getScrollBottom():number; + setScrollBottom(scrollBottom:number):number; + getScrollLeft():number; + setScrollLeft(scrollLeft:number):number; + getScrollRight():number; + setScrollRight(scrollRight:number):number; + getLineHeight():any; + setLineHeight(lineHeight:any):any; + getDefaultCharWidth():any; + setDefaultCharWidth(defaultCharWidth:any):any; + getScopedCharWidth(scopeNames:any, char:any):any; + getScopedCharWidths(scopeNames:any):any; + setScopedCharWidth(scopeNames:any, char:any, width:any):any; + setScopedCharWidths(scopeNames:any, charWidths:any):any; + clearScopedCharWidths():any; + getScrollHeight():number; + getScrollWidth():number; + getVisibleRowRange():number[]; + intersectsVisibleRowRange(startRow:any, endRow:any):any; + selectionIntersectsVisibleRowRange(selection:any):any; + scrollToScreenRange(screenRange:any):any; + scrollToScreenPosition(screenPosition:any):any; + scrollToBufferPosition(bufferPosition:any):any; + pixelRectForScreenRange(screenRange:IRange):any; + getTabLength():number; + setTabLength(tabLength:number):any; + setSoftWrap(softWrap:boolean):boolean; + getSoftWrap():boolean; + setEditorWidthInChars(editorWidthInChars:number):any; + getEditorWidthInChars():number; + getSoftWrapColumn():number; + lineForRow(row:number):any; + linesForRows(startRow:number, endRow:number):any; + getLines():any[]; + indentLevelForLine(line:any):any; + bufferRowsForScreenRows(startScreenRow:any, endScreenRow:any):any; + createFold(startRow:number, endRow:number):IFold; + isFoldedAtBufferRow(bufferRow:number):boolean; + isFoldedAtScreenRow(screenRow:number):boolean; + destroyFoldWithId(id:number):any; + unfoldBufferRow(bufferRow:number):any[]; + largestFoldStartingAtBufferRow(bufferRow:number):any; + foldsStartingAtBufferRow(bufferRow:number):any; + largestFoldStartingAtScreenRow(screenRow:any):any; + largestFoldContainingBufferRow(bufferRow:any):any; + outermostFoldsInBufferRowRange(startRow:any, endRow:any):any[]; + foldsContainingBufferRow(bufferRow:any):any[]; + screenRowForBufferRow(bufferRow:number):number; + lastScreenRowForBufferRow(bufferRow:number):number; + bufferRowForScreenRow(screenRow:number):number; + + screenRangeForBufferRange(bufferRange:IPoint[]):IRange; + + screenRangeForBufferRange(bufferRange:IRange):IRange; + + screenRangeForBufferRange(bufferRange:{start: IPoint; end: IPoint}):IRange; + screenRangeForBufferRange(bufferRange:{start: number[]; end: IPoint}):IRange; + screenRangeForBufferRange(bufferRange:{start: {row:number; col:number;}; end: IPoint}):IRange; + + screenRangeForBufferRange(bufferRange:{start: IPoint; end: number[]}):IRange; + screenRangeForBufferRange(bufferRange:{start: number[]; end: number[]}):IRange; + screenRangeForBufferRange(bufferRange:{start: {row:number; col:number;}; end: number[]}):IRange; + + screenRangeForBufferRange(bufferRange:{start: IPoint; end: {row:number; col:number;}}):IRange; + screenRangeForBufferRange(bufferRange:{start: number[]; end: {row:number; col:number;}}):IRange; + screenRangeForBufferRange(bufferRange:{start: {row:number; col:number;}; end: {row:number; col:number;}}):IRange; + + bufferRangeForScreenRange(screenRange:IPoint[]):IRange; + + bufferRangeForScreenRange(screenRange:IRange):IRange; + + bufferRangeForScreenRange(screenRange:{start: IPoint; end: IPoint}):IRange; + bufferRangeForScreenRange(screenRange:{start: number[]; end: IPoint}):IRange; + bufferRangeForScreenRange(screenRange:{start: {row:number; col:number;}; end: IPoint}):IRange; + + bufferRangeForScreenRange(screenRange:{start: IPoint; end: number[]}):IRange; + bufferRangeForScreenRange(screenRange:{start: number[]; end: number[]}):IRange; + bufferRangeForScreenRange(screenRange:{start: {row:number; col:number;}; end: number[]}):IRange; + + bufferRangeForScreenRange(screenRange:{start: IPoint; end: {row:number; col:number;}}):IRange; + bufferRangeForScreenRange(screenRange:{start: number[]; end: {row:number; col:number;}}):IRange; + bufferRangeForScreenRange(screenRange:{start: {row:number; col:number;}; end: {row:number; col:number;}}):IRange; + + pixelRangeForScreenRange(screenRange:IPoint[], clip?:boolean):IRange; + + pixelRangeForScreenRange(screenRange:IRange, clip?:boolean):IRange; + + pixelRangeForScreenRange(screenRange:{start: IPoint; end: IPoint}, clip?:boolean):IRange; + pixelRangeForScreenRange(screenRange:{start: number[]; end: IPoint}, clip?:boolean):IRange; + pixelRangeForScreenRange(screenRange:{start: {row:number; col:number;}; end: IPoint}, clip?:boolean):IRange; + + pixelRangeForScreenRange(screenRange:{start: IPoint; end: number[]}, clip?:boolean):IRange; + pixelRangeForScreenRange(screenRange:{start: number[]; end: number[]}, clip?:boolean):IRange; + pixelRangeForScreenRange(screenRange:{start: {row:number; col:number;}; end: number[]}, clip?:boolean):IRange; + + pixelRangeForScreenRange(screenRange:{start: IPoint; end: {row:number; col:number;}}, clip?:boolean):IRange; + pixelRangeForScreenRange(screenRange:{start: number[]; end: {row:number; col:number;}}, clip?:boolean):IRange; + pixelRangeForScreenRange(screenRange:{start: {row:number; col:number;}; end: {row:number; col:number;}}, clip?:boolean):IRange; + + pixelPositionForScreenPosition(screenPosition:IPoint, clip?:boolean):IPoint; + pixelPositionForScreenPosition(screenPosition:number[], clip?:boolean):IPoint; + pixelPositionForScreenPosition(screenPosition:{row:number; col:number;}, clip?:boolean):IPoint; + + screenPositionForPixelPosition(pixelPosition:any):IPoint; + + pixelPositionForBufferPosition(bufferPosition:any):any; + getLineCount():number; + getLastRow():number; + getMaxLineLength():number; + screenPositionForBufferPosition(bufferPosition:any, options:any):any; + bufferPositionForScreenPosition(bufferPosition:any, options:any):any; + scopesForBufferPosition(bufferPosition:any):any; + bufferRangeForScopeAtPosition(selector:any, position:any):any; + tokenForBufferPosition(bufferPosition:any):any; + getGrammar():IGrammar; + setGrammar(grammar:IGrammar):any; + reloadGrammar():any; + clipScreenPosition(screenPosition:any, options:any):any; + findWrapColumn(line:any, softWrapColumn:any):any; + rangeForAllLines():IRange; + getMarker(id:number):IDisplayBufferMarker; + getMarkers():IDisplayBufferMarker[]; + getMarkerCount():number; + markScreenRange(range:IRange, ...args:any[]):IDisplayBufferMarker; + markBufferRange(range:IRange, options?:any):IDisplayBufferMarker; + markScreenPosition(screenPosition:IPoint, options?:any):IDisplayBufferMarker; + markBufferPosition(bufferPosition:IPoint, options?:any):IDisplayBufferMarker; + destroyMarker(id:number):any; + findMarker(params?:any):IDisplayBufferMarker; + findMarkers(params?:any):IDisplayBufferMarker[]; + translateToBufferMarkerParams(params?:any):any; + findFoldMarker(attributes:any):IMarker; + findFoldMarkers(attributes:any):IMarker[]; + getFoldMarkerAttributes(attributes?:any):any; + pauseMarkerObservers():any; + resumeMarkerObservers():any; + refreshMarkerScreenPositions():any; + destroy():any; + logLines(start:number, end:number):any[]; + handleTokenizedBufferChange(tokenizedBufferChange:any):any; + updateScreenLines(startBufferRow:any, endBufferRow:any, bufferDelta?:number, options?:any):any; + buildScreenLines(startBufferRow:any, endBufferRow:any):any; + findMaxLineLength(startScreenRow:any, endScreenRow:any, newScreenLines:any):any; + handleBufferMarkersUpdated():any; + handleBufferMarkerCreated(marker:any):any; + createFoldForMarker(maker:any):IFold; + foldForMarker(marker:any):any; } interface ICursor { @@ -896,6 +1088,10 @@ declare module AtomCore { getRows():number[]; } + interface ITokenizedBuffer { + // TBD + } + interface ITokenizedLine { // TBD } @@ -904,7 +1100,16 @@ declare module AtomCore { // TBD } + interface IFoldStatic { + new (displayBuffer:IDisplayBuffer, marker:IMarker):IFold; + // TBD + } + interface IFold { + id:number; + displayBuffer:IDisplayBuffer; + marker:IMarker; + // TBD } @@ -967,7 +1172,10 @@ declare module AtomCore { // TBD } - interface IMarker { + interface IMarker extends Emissary.IEmitter { + // Serializable.includeInto(Editor); + // Delegator.includeInto(Editor); + // TBD } From 657277a43c05d721641f880b646354eb452394c5 Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Sun, 4 May 2014 20:16:10 -0400 Subject: [PATCH 28/49] Renamed tests file. Fixed remaining tests. --- ...dash-tests.disabled.ts => lodash-tests.ts} | 1963 ++- lodash/lodash.d.ts | 11432 ++++++++-------- 2 files changed, 6697 insertions(+), 6698 deletions(-) rename lodash/{lodash-tests.disabled.ts => lodash-tests.ts} (56%) diff --git a/lodash/lodash-tests.disabled.ts b/lodash/lodash-tests.ts similarity index 56% rename from lodash/lodash-tests.disabled.ts rename to lodash/lodash-tests.ts index de96b3d978..953d32d379 100644 --- a/lodash/lodash-tests.disabled.ts +++ b/lodash/lodash-tests.ts @@ -1,982 +1,981 @@ -/// - -declare var $: any, jQuery: any; - -interface IFoodOrganic { - name: string; - organic: boolean; -} - -interface IFoodType { - name: string; - type: string; -} - -interface IFoodCombined { - name: string; - organic: boolean; - type: string; -} - -interface IStoogesQuote { - name: string; - quotes: string[]; -} - -interface IStoogesAge { - name: string; - age: number; -} - -interface IStoogesCombined { - name: string; - age: number; - quotes: string[]; -} - -interface IKey { - dir: string; - code: number; -} - -var foodsOrganic: IFoodOrganic[] = [ - { name: 'banana', organic: true }, - { name: 'beet', organic: false }, -]; -var foodsType: IFoodType[] = [ - { name: 'apple', type: 'fruit' }, - { name: 'banana', type: 'fruit' }, - { name: 'beet', type: 'vegetable' } -]; -var foodsCombined: IFoodCombined[] = [ - { 'name': 'apple', 'organic': false, 'type': 'fruit' }, - { 'name': 'carrot', 'organic': true, 'type': 'vegetable' } -]; - -var stoogesQuotes: IStoogesQuote[] = [ - { 'name': 'curly', 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, - { 'name': 'moe', 'quotes': ['Spread out!', 'You knucklehead!'] } -]; -var stoogesAges: IStoogesAge[] = [ - { 'name': 'moe', 'age': 40 }, - { 'name': 'larry', 'age': 50 } -]; - -var stoogesCombined: IStoogesCombined[] = [ - { 'name': 'curly', 'age': 30, 'quotes': ['Oh, a wise guy, eh?', 'Poifect!'] }, - { 'name': 'moe', 'age': 40, 'quotes': ['Spread out!', 'You knucklehead!'] } -]; - -var keys: IKey[] = [ - { 'dir': 'left', 'code': 97 }, - { 'dir': 'right', 'code': 100 } -]; - -class Dog { - constructor(public name: string) {} - - public bark() { - console.log('Woof, woof!'); - } -} - -var result : any; - -/************* - * Chaining * - *************/ -result = <_.LoDashWrapper>_('test'); -result = <_.LoDashWrapper>_(1); -result = <_.LoDashWrapper>_(true); -result = <_.LoDashArrayWrapper>_(['test1', 'test2']); -// Appears to be a change in the compiler, if the type explicity implements the object indexer. -// Looking at: https://typescript.codeplex.com/wikipage?title=Known%20breaking%20changes%20between%200.8%20and%200.9&referringTitle=Documentation -// "The ‘noimplicitany’ option now warns on the use of the hidden default indexer" -result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }); - -result = <_.LoDashWrapper>_.chain('test'); -result = <_.LoDashWrapper>_('test').chain(); -result = <_.LoDashWrapper>_.chain(1); -result = <_.LoDashWrapper>_(1).chain(); -result = <_.LoDashWrapper>_.chain(true); -result = <_.LoDashWrapper>_(true).chain(); -result = <_.LoDashArrayWrapper>_.chain(['test1', 'test2']); -result = <_.LoDashArrayWrapper>_(['test1', 'test2']).chain(); -result = <_.LoDashObjectWrapper<_.Dictionary>>_.chain(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).chain(); - -//Wrapped array shortcut methods -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).concat(5, 6); -result = <_.LoDashWrapper>_([1, 2, 3, 4]).join(','); -result = <_.LoDashWrapper>_([1, 2, 3, 4]).pop(); -_([1, 2, 3, 4]).push(5, 6, 7); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).reverse(); -result = <_.LoDashWrapper>_([1, 2, 3, 4]).shift(); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).slice(1, 2); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).slice(2); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).sort((a, b) => 1); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).splice(1); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).splice(1, 2, 5, 6); -result = <_.LoDashWrapper>_([1, 2, 3, 4]).unshift(5, 6); - -result = _.tap([1, 2, 3, 4], function(array) { console.log(array); }); -result = <_.LoDashWrapper>_('test').tap(function(value) { console.log(value); }); -result = <_.LoDashArrayWrapper>_([1, 2, 3, 4]).tap(function(array) { console.log(array); }); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).tap(function (array) { console.log(array); }); - -result = _('test').toString(); -result = _([1, 2, 3]).toString(); -result = _({'key1': 'test1', 'key2': 'test2'}).toString(); - -result = _('test').valueOf(); -result = _([1, 2, 3]).valueOf(); -result = <_.Dictionary>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).valueOf(); - -result = _('test').value(); -result = _([1, 2, 3]).value(); -result = <_.Dictionary>_(<{ [index: string]: string; }>{ 'key1': 'test1', 'key2': 'test2' }).value(); - -// /************* -// * Arrays * -// *************/ -result = _.compact([0, 1, false, 2, '', 3]); - result = <_.LoDashArrayWrapper>_([0, 1, false, 2, '', 3]).compact(); - -result = _.difference([1, 2, 3, 4, 5], [5, 2, 10]); - result = <_.LoDashArrayWrapper>_([1, 2, 3, 4, 5]).difference([5, 2, 10]); - -result = _.rest([1, 2, 3]); -result = _.rest([1, 2, 3], 2); -result = _.rest([1, 2, 3], (num) => num < 3) -result = _.rest(foodsOrganic, 'test'); -result = _.rest(foodsType, { 'type': 'value' }); - -result = _.drop([1, 2, 3]); -result = _.drop([1, 2, 3], 2); -result = _.drop([1, 2, 3], (num) => num < 3) -result = _.drop(foodsOrganic, 'test'); -result = _.drop(foodsType, { 'type': 'value' }); - -result = _.tail([1, 2, 3]) -result = _.tail([1, 2, 3], 2) -result = _.tail([1, 2, 3], (num) => num < 3) -result = _.tail(foodsOrganic, 'test') -result = _.tail(foodsType, { 'type': 'value' }) - -result = _.findIndex(['apple', 'banana', 'beet'], function(f) { - return /^b/.test(f); -}); -result = _.findIndex(['apple', 'banana', 'beet'], 'apple'); -result = _.findIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple'}); - -result = _.findLastIndex(['apple', 'banana', 'beet'], function(f: string) { - return /^b/.test(f); -}); -result = _.findLastIndex(['apple', 'banana', 'beet'], 'apple'); -result = _.findLastIndex([{ food: 'apple' }, { food: 'banana' }, { food: 'beet' }], { food: 'apple'}); - -result = _.first([1, 2, 3]); -result = _.first([1, 2, 3], 2); -result = _.first([1, 2, 3], function(num) { - return num < 3; -}); -result = _.first(foodsOrganic, 'organic'); -result = _.first(foodsType, { 'type': 'fruit' }); - - result = _.head([1, 2, 3]); - result = _.head([1, 2, 3], 2); - result = _.head([1, 2, 3], function(num) { - return num < 3; - }); - result = _.head(foodsOrganic, 'organic'); - result = _.head(foodsType, { 'type': 'fruit' }); - - 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 = _.flatten([1, [2], [3, [[4]]]]); -result = _.flatten([1, [2], [3, [[4]]]], true); -var result: any -result = _.flatten(stoogesQuotes, 'quotes'); - - result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(); - result = <_.LoDashArrayWrapper>_([1, [2], [3, [[4]]]]).flatten(true); - result = <_.LoDashArrayWrapper>_(stoogesQuotes).flatten('quotes'); - -result = _.indexOf([1, 2, 3, 1, 2, 3], 2); -result = _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); -result = _.indexOf([1, 1, 2, 2, 3, 3], 2, true); - -result = _.initial([1, 2, 3]); -result = _.initial([1, 2, 3], 2); -result = _.initial([1, 2, 3], function(num) { - return num > 1; -}); -result = _.initial(foodsOrganic, 'organic'); -result = _.initial(foodsType, { 'type': 'vegetable' }); - -result = _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); - -result = _.last([1, 2, 3]); -result = _.last([1, 2, 3], 2); -result = _.last([1, 2, 3], function(num) { - return num > 1; -}); -result = _.last(foodsOrganic, 'organic'); -result = _.last(foodsType, { 'type': 'vegetable' }); - -result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); -result = _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); - -result = <{[key: string]: any}>_.zipObject(['moe', 'larry'], [30, 40]); -result = <{[key: string]: any}>_.object(['moe', 'larry'], [30, 40]); - -result = _.pull([1, 2, 3, 1, 2, 3], 2, 3); - -result = _.range(10); -result = _.range(1, 11); -result = _.range(0, 30, 5); -result = _.range(0, -10, -1); -result = _.range(1, 4, 0); -result = _.range(0); - -result = _.remove([1, 2, 3, 4, 5, 6], function(num: number) { return num % 2 == 0; }); -result = _.remove(foodsOrganic, 'organic'); -result = _.remove(foodsType, { 'type': 'vegetable'}); - -result = _.sortedIndex([20, 30, 50], 40); -result = _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); -var sortedIndexDict = { - 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 } -}; -result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { - return sortedIndexDict.wordToNumber[word]; -}); -result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { - return this.wordToNumber[word]; -}, sortedIndexDict); - -result = _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); - -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) { - return letter.toLowerCase(); -}); -result = _.uniq([1, 2.5, 3, 1.5, 2, 3.5], function(num) { return this.floor(num); }, Math); -result = <{x: number;}[]>_.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); - - result = _.unique([1, 2, 1, 3, 1]); - result = _.unique([1, 1, 2, 2, 3], true); - result = _.unique(['A', 'b', 'C', 'a', 'B', 'c'], function(letter) { - return letter.toLowerCase(); - }); - 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 = _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); - -result = _.zip(['moe', 'larry'], [30, 40], [true, false]); -result = _.unzip(['moe', 'larry'], [30, 40], [true, false]); - -// /* ************* -// * Collections * -// ************* */ - -result = _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); -result = _.at(['moe', 'larry', 'curly'], 0, 2); - -result = _.contains([1, 2, 3], 1); -result = _.contains([1, 2, 3], 1, 2); -result = _.contains({ 'name': 'moe', 'age': 40 }, 'moe'); -result = _.contains('curly', 'ur'); - - result = _.include([1, 2, 3], 1); - result = _.include([1, 2, 3], 1, 2); - result = _.include({ 'name': 'moe', 'age': 40 }, 'moe'); - result = _.include('curly', 'ur'); - -result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); -result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); -result = <_.Dictionary>_.countBy(['one', 'two', 'three'], 'length'); - -result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function (num) { return Math.floor(num); }); -result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.3, 6.1, 6.4]).countBy(function (num) { return this.floor(num); }, Math); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).countBy('length'); - -result = _.every([true, 1, null, 'yes'], Boolean); -result = _.every(stoogesAges, 'age'); -result = _.every(stoogesAges, { 'age': 50 }); - - result = _.all([true, 1, null, 'yes'], Boolean); - result = _.all(stoogesAges, 'age'); - result = _.all(stoogesAges, { 'age': 50 }); - -result = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -result = _.filter(foodsCombined, 'organic'); -result = _.filter(foodsCombined, { 'type': 'fruit' }); - - result = _([1, 2, 3, 4, 5, 6]).filter(function(num) { return num % 2 == 0; }).value(); - result = _(foodsCombined).filter('organic').value(); - result = _(foodsCombined).filter({ 'type': 'fruit' }).value(); - - result = _.select([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); - result = _.select(foodsCombined, 'organic'); - result = _.select(foodsCombined, { 'type': 'fruit' }); - - result = _([1, 2, 3, 4, 5, 6]).select(function(num) { return num % 2 == 0; }).value(); - result = _(foodsCombined).select('organic').value(); - result = _(foodsCombined).select({ 'type': 'fruit' }).value(); - -result = _.find([1, 2, 3, 4], function(num) { - return num % 2 == 0; -}); -result = _.find(foodsCombined, { 'type': 'vegetable' }); -result = _.find(foodsCombined, 'organic'); - - result = _.detect([1, 2, 3, 4], function(num) { - return num % 2 == 0; - }); - result = _.detect(foodsCombined, { 'type': 'vegetable' }); - result = _.detect(foodsCombined, 'organic'); - - result = _.findWhere([1, 2, 3, 4], function(num) { - return num % 2 == 0; - }); - result = _.findWhere(foodsCombined, { 'type': 'vegetable' }); - result = _.findWhere(foodsCombined, 'organic'); - -result = _.findLast([1, 2, 3, 4], function(num) { - return num % 2 == 0; -}); -result = _.findLast(foodsCombined, { 'type': 'vegetable' }); -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 = _.each([1, 2, 3], function(num) { console.log(num); }); - result = <_.Dictionary>_.each({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); }); - -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); }); - -result = <_.LoDashArrayWrapper>_([1, 2, 3]).each(function (num) { console.log(num); }); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).each(function (num) { console.log(num); }); - -result = _.forEachRight([1, 2, 3], function(num) { console.log(num); }); -result = <_.Dictionary>_.forEachRight({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); }); - - result = _.eachRight([1, 2, 3], function(num) { console.log(num); }); - result = <_.Dictionary>_.eachRight({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); }); - -result = <_.LoDashArrayWrapper>_([1, 2, 3]).forEachRight(function (num) { console.log(num); }); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).forEachRight(function (num) { console.log(num); }); - -result = <_.LoDashArrayWrapper>_([1, 2, 3]).eachRight(function (num) { console.log(num); }); -result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).eachRight(function (num) { console.log(num); }); - -result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); -result = <_.Dictionary>_.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); -result = <_.Dictionary>_.groupBy(['one', 'two', 'three'], 'length'); - - result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function(num) { return Math.floor(num); }); - result = <_.LoDashObjectWrapper<_.Dictionary>>_([4.2, 6.1, 6.4]).groupBy(function(num) { return this.floor(num); }, Math); - result = <_.LoDashObjectWrapper<_.Dictionary>>_(['one', 'two', 'three']).groupBy('length'); - -result = <_.Dictionary>_.indexBy(keys, 'dir'); -result = <_.Dictionary>_.indexBy(keys, function(key) { return String.fromCharCode(key.code); }); -result = <_.Dictionary>_.indexBy(keys, function(key) { this.fromCharCode(key.code); }, String); - -result = _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); -result = _.invoke([123, 456], String.prototype.split, ''); - -result = _.map([1, 2, 3], function(num) { return num * 3; }); -result = _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); -result = _.map(stoogesAges, 'name'); - - result = _([1, 2, 3]).map(function(num) { return num * 3; }).value(); - result = _({ 'one': 1, 'two': 2, 'three': 3 }).map(function(num) { return num * 3; }).value(); - result = _(stoogesAges).map('name').value(); - -result = _.collect([1, 2, 3], function(num) { return num * 3; }); -result = _.collect({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); -result = _.collect(stoogesAges, 'name'); - - result = _([1, 2, 3]).collect(function(num) { return num * 3; }).value(); - result = _({ 'one': 1, 'two': 2, 'three': 3 }).collect(function(num) { return num * 3; }).value(); - result = _(stoogesAges).collect('name').value(); - -result = _.max([4, 2, 8, 6]); -result = _.max(stoogesAges, function(stooge) { return stooge.age; }); -result = _.max(stoogesAges, 'age'); - -result = _.min([4, 2, 8, 6]); -result = _.min(stoogesAges, function(stooge) { return stooge.age; }); -result = _.min(stoogesAges, 'age'); - -result = _.pluck(stoogesAges, 'name'); - -result = _.reduce([1, 2, 3], function(sum: number, num: number) { - return sum + num; -}); -interface ABC { - a: number; - b: number; - c: number; -} -result = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(r: ABC, num, key) { - r[key] = num * 3; - return r; -}, {}); - -result = _.foldl([1, 2, 3], function(sum, num) { - return sum + num; -}); -result = _.foldl({ 'a': 1, 'b': 2, 'c': 3 }, function(r: ABC, num, key) { - r[key] = num * 3; - return r; -}, {}); - -result = _.inject([1, 2, 3], function(sum, num) { - return sum + num; -}); -result = _.inject({ 'a': 1, 'b': 2, 'c': 3 }, function(r: ABC, num, key) { - 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); }, []); - -result = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); -result = _.reject(foodsCombined, 'organic'); -result = _.reject(foodsCombined, { 'type': 'fruit' }); - -result = _.sample([1, 2, 3, 4]); -result = _.sample([1, 2, 3, 4], 2); - -result = _.shuffle([1, 2, 3, 4, 5, 6]); - -result = _.size([1, 2]); -result = _.size({ 'one': 1, 'two': 2, 'three': 3 }); -result = _.size('curly'); - -result = _.some([null, 0, 'yes', false], Boolean); -result = _.some(foodsCombined, 'organic'); -result = _.some(foodsCombined, { 'type': 'meat' }); - -result = _.any([null, 0, 'yes', false], Boolean); -result = _.any(foodsCombined, 'organic'); -result = _.any(foodsCombined, { 'type': 'meat' }); - -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'); - -(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!'] }); - -/************* - * Functions * - *************/ -var saves = ['profile', 'settings']; -var asyncSave = (obj: any) => obj.done(); -var done: Function; - -done = _.after(saves.length, function() { - console.log('Done saving!'); -}); - -_.forEach(saves, function(type) { - asyncSave({ 'type': type, 'complete': done }); -}); - -done = _(saves.length).after(function() { - console.log('Done saving!'); -}).value(); - -_.forEach(saves, function(type) { - asyncSave({ 'type': type, 'complete': done }); -}); - -var funcBind = function (greeting: string) { return greeting + ' ' + this.name }; -var funcBind2: () => any = _.bind(funcBind, { 'name': 'moe' }, 'hi'); -funcBind2(); - -var funcBind3: () => any = _(funcBind).bind({ 'name': 'moe' }, 'hi').value(); -funcBind3(); - -var view = { - 'label': 'docs', - 'onClick': function() { console.log('clicked ' + this.label); } -}; - -view = _.bindAll(view); -jQuery('#docs').on('click', view.onClick); - -view = _(view).bindAll().value(); -jQuery('#docs').on('click', view.onClick); - -var objectBindKey = { - 'name': 'moe', - 'greet': function(greeting: string) { - return greeting + ' ' + this.name; - } -}; - -var funcBindKey: Function = _.bindKey(objectBindKey, 'greet', 'hi'); -funcBindKey(); - -objectBindKey.greet = function(greeting) { - return greeting + ', ' + this.name + '!'; -}; - -funcBindKey(); - -funcBindKey = _(objectBindKey).bindKey('greet', 'hi').value(); -funcBindKey(); - -var realNameMap = { - 'curly': 'jerome' -}; - -var format = function(name: string) { - name = realNameMap[name.toLowerCase()] || name; - return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase(); -}; - -var greet = function(formatted: string) { - return 'Hiya ' + formatted + '!'; -}; - -result = _.compose(greet, format); -result = <_.LoDashObjectWrapper>_(greet).compose(format); - -var createCallbackObj: { [index: string]: string; } = { name: 'Joe' }; -result = <() => any>_.createCallback('name'); -result = <() => boolean>_.createCallback(createCallbackObj); -result = <_.LoDashObjectWrapper<() => any>>_('name').createCallback(); -result = <_.LoDashObjectWrapper<() => boolean>>_(createCallbackObj).createCallback(); - -result = _.curry(function(a, b, c) { - console.log(a + b + c); -}); - -result = <_.LoDashObjectWrapper>_(function(a, b, c) { - console.log(a + b + c); -}).curry(); - -declare var source: any; -result = _.debounce(function() {}, 150); - -jQuery('#postbox').on('click', _.debounce(function() {}, 300, { - 'leading': true, - 'trailing': false -})); - -source.addEventListener('message', _.debounce(function() {}, 250, { - 'maxWait': 1000 -}), false); - -result = <_.LoDashObjectWrapper>_(function() {}).debounce(150); - -jQuery('#postbox').on('click', <_.LoDashObjectWrapper>_(function() {}).debounce(300, { - 'leading': true, - 'trailing': false -})); - -source.addEventListener('message', <_.LoDashObjectWrapper>_(function() {}).debounce(250, { - 'maxWait': 1000 -}), false); - -var returnedDebounce = _.throttle(function (a) { return a * 5; }, 5); -returnedThrottled(4); - -result = _.defer(function() { console.log('deferred'); }); -result = <_.LoDashWrapper>_(function() { console.log('deferred'); }).defer(); - -var log = _.bind(console.log, console); -result = _.delay(log, 1000, 'logged later'); -result = <_.LoDashWrapper>_(log).delay(1000, 'logged later'); - -var fibonacci = _.memoize(function(n) { - return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); -}); - -var data = { - 'moe': { 'name': 'moe', 'age': 40 }, - 'curly': { 'name': 'curly', 'age': 60 } -}; - -var stooge = _.memoize(function(name: string) { return data[name]; }, _.identity); -stooge('curly'); - -stooge['cache']['curly'].name = 'jerome'; -stooge('curly'); - -var returnedMemoize = _.throttle(function (a) { return a * 5; }, 5); -returnedMemoize(4); - -var initialize = _.once(function(){ }); -initialize(); -initialize();'' -var returnedOnce = _.throttle(function (a) { return a * 5; }, 5); -returnedOnce(4); - -var greetPartial = function(greeting: string, name: string) { return greeting + ' ' + name; }; -var hi = _.partial(greetPartial, 'hi'); -hi('moe'); - -var defaultsDeep = _.partialRight(_.merge, _.defaults); - -var optionsPartialRight = { - 'variable': 'data', - 'imports': { 'jq': $ } -}; - -defaultsDeep(optionsPartialRight, _.templateSettings); - -var throttled = _.throttle(function () { }, 100); -jQuery(window).on('scroll', throttled); - -jQuery('.interactive').on('click', _.throttle(function() { }, 300000, { - 'trailing': false -})); - -var returnedThrottled = _.throttle(function (a) { return a*5; }, 5); -returnedThrottled(4); - -var helloWrap = function(name: string) { return 'hello ' + name; }; -var helloWrap2 = _.wrap(helloWrap, function(func) { - return 'before, ' + func('moe') + ', after'; -}); -helloWrap2(); - -/********** -* Objects * -***********/ -interface NameAge { - name: string; - age: number; -} -result = _.assign({ 'name': 'moe' }, { 'age': 40 }); -result = _.assign({ 'name': 'moe' }, { 'age': 40 }, function(a, b) { - return typeof a == 'undefined' ? b : a; -}); - -result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).assign({ 'age': 40 }); -result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).assign({ 'age': 40 }, function(a, b) { - return typeof a == 'undefined' ? b : a; -}); - -result = _.extend({ 'name': 'moe' }, { 'age': 40 }); -result = _.extend({ 'name': 'moe' }, { 'age': 40 }, function(a, b) { - return typeof a == 'undefined' ? b : a; -}); - -result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).extend({ 'age': 40 }); -result = <_.LoDashObjectWrapper>_({ 'name': 'moe' }).extend({ 'age': 40 }, function(a, b) { - return typeof a == 'undefined' ? b : a; -}); - -result = _.clone(stoogesAges); -result = _.clone(stoogesAges, true); -result = _.clone(stoogesAges, true, function(value) { - return _.isElement(value) ? value.cloneNode(false) : undefined; -}); - -result = _.cloneDeep(stoogesAges); -result = _.cloneDeep(stoogesAges, function(value) { - return _.isElement(value) ? value.cloneNode(false) : undefined; -}); - -interface Food { - name: string; - type: string; -} -var foodDefaults = { 'name': 'apple' }; -result = _.defaults(foodDefaults, { 'name': 'banana', 'type': 'fruit' }); - result = <_.LoDashObjectWrapper>_(foodDefaults).defaults({ 'name': 'banana', 'type': 'fruit' }); - -result = _.findKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { - return num % 2 == 0; -}); - -result = _.findLastKey({ 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, function(num) { - return num % 2 == 1; -}); - -result = _.forIn(new Dog('Dagny'), function(value, key) { - console.log(key); -}); - -result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forIn(function(value, key) { - console.log(key); -}); - -result = _.forInRight(new Dog('Dagny'), function(value, key) { - console.log(key); -}); - -result = <_.LoDashObjectWrapper>_(new Dog('Dagny')).forInRight(function(value, key) { - console.log(key); -}); - -interface ZeroOne { - 0: string; - 1: string; - one: string; -} - -result = _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { - console.log(key); -}); - - result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwn(function(num, key) { - console.log(key); - }); - -result = _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { - console.log(key); -}); - - result = <_.LoDashObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwnRight(function(num, key) { - console.log(key); - }); - -result = _.functions(_); -result = _.methods(_); - -result = <_.LoDashArrayWrapper>_(_).functions(); -result = <_.LoDashArrayWrapper>_(_).methods(); - -result = _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); - -interface FirstSecond { - first: string; - second: string; -} -result = _.invert({ 'first': 'moe', 'second': 'larry' }); - -(function(...args: any[]) { return _.isArguments(arguments); })(1, 2, 3); - -(function () { return _.isArray(arguments); })(); -result = _.isArray([1, 2, 3]); - -result = _.isBoolean(null); - -result = _.isDate(new Date()); - -result = _.isElement(document.body); - -result = _.isEmpty([1, 2, 3]); -result = _.isEmpty({}); -result = _.isEmpty(''); - -var moe = { 'name': 'moe', 'age': 40 }; -var copy = { 'name': 'moe', 'age': 40 }; - -result = _.isEqual(moe, copy); - -var words = ['hello', 'goodbye']; -var otherWords = ['hi', 'goodbye']; - -result = _.isEqual(words, otherWords, function(a, b) { - var reGreet = /^(?:hello|hi)$/i, - aGreet = _.isString(a) && reGreet.test(a), - bGreet = _.isString(b) && reGreet.test(b); - - return (aGreet || bGreet) ? (aGreet == bGreet) : undefined; -}); - -result = _.isFinite(-101); -result = _.isFinite('10'); -result = _.isFinite(true); -result = _.isFinite(''); -result = _.isFinite(Infinity); - -result = _.isFunction(_); - -result = _.isNaN(NaN); -result = _.isNaN(new Number(NaN)); -result = _.isNaN(undefined); - -result = _.isNull(null); -result = _.isNull(undefined); - -result = _.isNumber(8.4 * 5); - -result = _.isObject({}); -result = _.isObject([1, 2, 3]); -result = _.isObject(1); - -class Stooge { - constructor( - public name: string, - public age: number - ) {} -} - -result = _.isPlainObject(new Stooge('moe', 40)); -result = _.isPlainObject([1, 2, 3]); -result = _.isPlainObject({ 'name': 'moe', 'age': 40 }); - -result = _.isRegExp(/moe/); - -result = _.isString('moe'); - -result = _.isUndefined(void 0); - -result = _.keys({ 'one': 1, 'two': 2, 'three': 3 }); - -var mergeNames = { - 'stooges': [ - { 'name': 'moe' }, - { 'name': 'larry' } - ] -}; - -var mergeAges = { - 'stooges': [ - { 'age': 40 }, - { 'age': 50 } - ] -}; - -result = _.merge(mergeNames, mergeAges); - -var mergeFood = { - 'fruits': ['apple'], - 'vegetables': ['beet'] -}; - -var mergeOtherFood = { - 'fruits': ['banana'], - 'vegetables': ['carrot'] -}; - -interface FruitVeg { - fruits: string[]; - vegetables: string[] -}; - -result = _.merge(mergeFood, mergeOtherFood, function(a, b) { - return _.isArray(a) ? a.concat(b) : undefined; -}); - -interface HasName { - name: string; -} -result = _.omit({ 'name': 'moe', 'age': 40 }, 'age'); -result = _.omit({ 'name': 'moe', 'age': 40 }, ['age']); -result = _.omit({ 'name': 'moe', 'age': 40 }, function(value) { - return typeof value == 'number'; -}); - -result = _.pairs({ 'moe': 30, 'larry': 40 }); - -result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, 'name'); -result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, ['name']); -result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key) { - return key.charAt(0) != '_'; -}); - -result = _.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function(r, num) { - num *= num; - if (num % 2) { - return r.push(num) < 3; - } -}); -// → [1, 9, 25] - -result = <{a:number;b:number;c:number;}>_.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(r, num, key) { - r[key] = num * 3; -}); - -result = _.values({ 'one': 1, 'two': 2, 'three': 3 }); - -/********** -* Utilities * -***********/ - -result = _.escape('Moe, Larry & Curly'); - -result = <{ name: string }>_.identity({ 'name': 'moe' }); - -_.mixin({ - 'capitalize': function(string) { - return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); - } -}); - -var lodash = _.noConflict(); - -result = _.parseInt('08'); - -result = _.random(0, 5); -result = _.random(5); -result = _.random(5, true); -result = _.random(1.2, 5.2); -result = _.random(0, 5, true); - -var object = { - 'cheese': 'crumpets', - 'stuff': function() { - return 'nonsense'; - } -}; - -result = _.result(object, 'cheese'); -result = _.result(object, 'stuff'); - -var tempObject = {}; -result = _.runInContext(tempObject); - -result = <_.TemplateExecutor>_.template('hello <%= name %>'); -result = _.template('<%- value %>', { 'value': '