///
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 = _([1, 2, 3]).first();
result = _([1, 2, 3]).first(2).value();
result = _([1, 2, 3]).first(function (num) {
return num < 3;
}).value();
result = _(foodsOrganic).first('organic').value();
result = _(foodsType).first({ 'type': 'fruit' }).value();
result = _.head([1, 2, 3]);
result = _.head([1, 2, 3], 2);
result = _.head([1, 2, 3], function (num) {
return num < 3;
});
result = _.head(foodsOrganic, 'organic');
result = _.head(foodsType, { 'type': 'fruit' });
result = _([1, 2, 3]).head();
result = _([1, 2, 3]).head(2).value();
result = _([1, 2, 3]).head(function (num) {
return num < 3;
}).value();
result = _(foodsOrganic).head('organic').value();
result = _(foodsType).head({ 'type': 'fruit' }).value();
result = _.take([1, 2, 3]);
result = _.take([1, 2, 3], 2);
result = _.take([1, 2, 3], (num) => num < 3);
result = _.take(foodsOrganic, 'organic');
result = _.take(foodsType, { 'type': 'fruit' });
result = _([1, 2, 3]).take();
result = _([1, 2, 3]).take(2).value();
result = _([1, 2, 3]).take(function (num) {
return num < 3;
}).value();
result = _(foodsOrganic).take('organic').value();
result = _(foodsType).take({ 'type': 'fruit' }).value();
result = _.flatten([1, [2], [3, [[4]]]]);
result = _.flatten([1, [2], [3, [[4]]]], true);
var result: any
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: { [idx: string]: number } } = {
'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 }
};
result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) {
return sortedIndexDict.wordToNumber[word];
});
result = _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function (word: string) {
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 = _([1, 2, 1, 3, 1]).uniq().value();
result = _([1, 1, 2, 2, 3]).uniq(true).value();
result = _(['A', 'b', 'C', 'a', 'B', 'c']).uniq(function (letter) {
return letter.toLowerCase();
}).value();
result = _([1, 2.5, 3, 1.5, 2, 3.5]).uniq(function (num) { return this.floor(num); }, Math).value();
result = <{ x: number; }[]>_([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }]).uniq('x').value();
result = _([1, 2, 1, 3, 1]).unique().value();
result = _([1, 1, 2, 2, 3]).unique(true).value();
result = _(['A', 'b', 'C', 'a', 'B', 'c']).unique(function (letter) {
return letter.toLowerCase();
}).value();
result = _([1, 2.5, 3, 1.5, 2, 3.5]).unique(function (num) { return this.floor(num); }, Math).value();
result = <{ x: number; }[]>_([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }]).unique('x').value();
result = _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
result = _.xor([1, 2, 3, 4, 5], [5, 2, 10]);
result = _.xor([1, 2, 3, 4, 5], [5, 2, 10], [4, 5, 6]);
result = <_.LoDashArrayWrapper>_([1, 2, 3, 4, 5]).xor([5, 2, 10]);
result = <_.LoDashArrayWrapper>_([1, 2, 3, 4, 5]).xor([5, 2, 10], [4, 5, 6]);
result = _.zip(['moe', 'larry'], [30, 40], [true, false]);
result = _.unzip(['moe', 'larry'], [30, 40], [true, false]);
result = _(['moe', 'larry']).zip([30, 40], [true, false]).value();
result = _(['moe', 'larry']).unzip([30, 40], [true, false]).value();
// /* *************
// * 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 = _([1, 2, 3, 4]).find(function (num) {
return num % 2 == 0;
});
result = _(foodsCombined).find({ 'type': 'vegetable' });
result = _(foodsCombined).find('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 = _([1, 2, 3, 4]).findLast(function (num) {
return num % 2 == 0;
});
result = _(foodsCombined).findLast({ 'type': 'vegetable' });
result = _(foodsCombined).findLast('organic');
result = _.forEach([1, 2, 3], function (num) { console.log(num); });
result = <_.Dictionary>_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); });
result = _.forEach({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) });
result = _.each([1, 2, 3], function (num) { console.log(num); });
result = <_.Dictionary>_.each({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); });
result = _.each({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) });
result = <_.LoDashArrayWrapper>_([1, 2, 3]).forEach(function (num) { console.log(num); });
result = <_.LoDashObjectWrapper<_.Dictionary>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).forEach(function (num) { console.log(num); });
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 = <_.Dictionary>_.groupBy({ prop1: 4.2, prop2: 6.1, prop3: 6.4}, function (num) { return Math.floor(num); });
result = <_.Dictionary>_.groupBy({ prop1: 4.2, prop2: 6.1, prop3: 6.4}, function (num) { return this.floor(num); }, Math);
result = <_.Dictionary>_.groupBy({ prop1: 'one', prop2: 'two', prop3: 'three'}, 'length');
result = <_.Dictionary>_([4.2, 6.1, 6.4]).groupBy(function (num) { return Math.floor(num); }).value();
result = <_.Dictionary>_([4.2, 6.1, 6.4]).groupBy(function (num) { return this.floor(num); }, Math).value();
result = <_.Dictionary>_(['one', 'two', 'three']).groupBy('length').value();
result = <_.Dictionary>_({ prop1: 4.2, prop2: 6.1, prop3: 6.4}).groupBy(function (num) { return Math.floor(num); }).value();
result = <_.Dictionary>_({ prop1: 4.2, prop2: 6.1, prop3: 6.4}).groupBy(function (num) { return this.floor(num); }, Math).value();
result = <_.Dictionary>_({ prop1: 'one', prop2: 'two', prop3: 'three'}).groupBy('length').value();
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: number) { return num * 3; }).value();
result = _(stoogesAges).map('name').value();
result =