Skip to content

Fermium-co/LINQ4ES2015

Repository files navigation

LINQ4ES2015

Language Integrated Query (LINQ) for JavaScript based on ECMA Script 2015

(formerly known as ES6)

Installing

In order to install & use LINQ4ES2015, Node JS is required to be installed on Development machine.

If you've not configured jspm yet, follow our blog post

Note: Latest version of jspm must be installed on your machine, try running:

npm update jspm -g

Go to the root directory of the project and run the following command to install LINQ4ES2015:

jspm install linq4es2015

Usage

After installing LINQ4ES2015 you can use the following JavaScript code to import it:

import Linq from "linq4es2015/linq";

a simple usage is shown in the following code (Prototype based approach):

Linq.setExtensions(); // You've to run this, only once, if you're interested in prototype based approach.

let result = [0, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9].asEnumerable()
  .where(num => num % 2 == 0)
  .take(3)
  .orderByDescending(num => num)
  .select(num => '[' + num + ']')
  .distinct()
  .toArray();

let sum = 'a2r3'.asEnumerable().where(chr => !isNaN(chr)).select(num => Number(num)).sum();
  // sum will be 5  

or wihtout extentions (No prototype modification is required):

let enumerable = Linq.asEnumerable([0, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9]);
let result = Linq.toArray(Linq.distinct(Linq.select(Linq.orderByDescending(Linq.take(Linq.where(enumerable, n => n % 2 == 0), 3), n => n), n => '[' + n ']')));
// You don't have to call Linq.setExtensions with this approach, and you can load any module you'd prefer to use, instead of loading all of them.

result will be [ "[2]", "[0]" ] and where predicate will be executed only 4 times.

Important performance tip: This project uses babel at runtime to transpile ECMA 2015 codes to ECMA 5 codes, to make running app on all browsers possible. But for production, you'll need to move transpile time from runtime to build time. This will improve your app performance a lot. We'll add more information about this later, but you can find some good docs about this on jspm & babel docs.

Samples

Note: Each method has its own Wiki page, including description and samples about that method.

Download the samples folder and run the following commands in the sample's root directory:

npm install

jspm insatll    

We need a webserver to run the sample. http-server is a simple one. install it by runnting this command:

npm install http-server -g  

then run the following command in the sample's directory:

http-server

Note that you can use any web server you prefer.

Roadmap

Supported methods:

Click on each method hyperlink to see description and samples. Read Home Wiki first

In Progress Methods:

thenBy thenByDescending

Contribute

See CONTRIBUTING.md

Documentation

See Wiki pages

About

Language Integrated Query for JavaScript based on ECMA Script 2015

Resources

License

Stars

Watchers

Forks

Packages

No packages published