ex-js-linq
v2.1.0
Published
Linq framework for node js programming language
Downloads
2
Maintainers
Readme
ex-js-linq
helpful libraries for JavaScript programming
Features
- .forEach
- .select
- .selectMany
- .where
- .firstOrDefault
- .indexOf
- .groupBy
- .any
- .exists
- .sum
- .avg
- .min
- .max
- .remove
- .take
- .skip
- .orderBy
- .orderByDescending
- .toArray
- .distinct
- .add
- .addRange
- .join
- .count
Using npm
npm install ex-js-linq
Overview
var linq = require("ex-js-linq");
var sampleData = [
{ id: 3, name: "julia", age: 22, city: "izmir", cars: ["Fiat"] },
{ id: 2, name: "Marry", age: 25, city: "istanbul", cars: ["Ford"] },
{ id: 4, name: "julia", age: 22, city: "izmir", cars: ["Fiat"] },
{ id: 1, name: "John", age: 30, city: "istanbul", cars: ["Ford", "BMW", "Fiat"] },
{ id: 5, name: "Furkan", age: 22, city: "istanbul", cars: [] }
];
.forEach
new linq(sampleData).forEach(function(x){
console.log(x);
});
.select
var result= new linq(sampleData)
.select(function(x){return x.age})
.toArray();
// or
var result=new linq(sampleData)
.select(function(x){
return {
name:x.name,
age:x.age
}
}).toArray();
.selectMany
var result= new linq(sampleData)
.selectMany(function(x){return x.cars})
.toArray();
// result => ["Fiat","Ford","Fiat",...]
.where
var result=new linq(sampleData)
.where(function(x){return x.age>23;})
.toArray();
.firstOrDefault
var result=new linq(sampleData)
.firstOrDefault(function(x){return x.id==5;});
// or
var result=new linq(sampleData)
.firstOrDefault();
.indexOf
var index=new linq(sampleData)
.indexOf(function(x){return x.id==5;});
.groupBy
var result=new linq(sampleData)
.groupBy(function(x){return x.city;})
.selectMany(function(x){
return x.items
}).toArray();
// result =>[item1,item2,item3,...]
// or
var result=new linq(sampleData)
.groupBy(function(x){return x.city;})
.toArray();
// result => [{key:"istanbul",items:[item1,item2,...]},{key:"izmir",items:[item1,item2,...]}]
.any
var result=new linq(sampleData)
.any(function(x){return x.id==5;});
// result => true
.exists
var result=new linq(sampleData)
.exists(function(x){return x.id==5;});
// result => true
.sum
var result=new linq(sampleData)
.sum(function(x){return x.age;});
// or
var result=new linq([1,2,3]).sum();
// result => 6
.avg
var result=new linq(sampleData)
.avg(function(x){return x.age;});
// or
var result=new linq([1,2,3]).sum();
// result => 2
.min
var result=new linq(sampleData)
.min(function(x){return x.age;});
// result => 22
// or
var result=new linq([1,2,3]).sum();
// result => 1
.max
var result=new linq(sampleData)
.min(function(x){return x.age;});
// result => 30
// or
var result=new linq([1,2,3]).sum();
// result => 3
.remove
var result=new linq(sampleData)
.remove(function(x){return x.age==22;})
.toArray();
.take
var result=new linq(sampleData)
.take(5).toArray();
.skip
var result=new linq(sampleData)
.skip(1).take(3).toArray();
.orderBy
var result=new linq(sampleData)
.orderBy(function(x){ return x.age})
.toArray();
.orderByDescending
var result=new linq(sampleData)
.orderByDescending(function(x){ return x.age})
.toArray();
.toArray
var result=new linq(sampleData).toArray();
.distinct
var result=new linq(sampleData).distinct().toArray();
// or
var result=new linq(sampleData).distinct(function(x){ return x.id;}).toArray();
.add
var item={};
new linq(sampleData).add(item);
.addRange
var items=[];
new linq(sampleData).add(items);
.join
var items=[];
var result=new linq(sampleData).join(items).toArray();
.count
var count=new linq(sampleData).count();
// or
var count=new linq(sampleData).count(function(x){ return x.cars.lenght>2;});