JSPM

  • Created
  • Published
  • Downloads 940
  • Score
    100M100P100Q106435F
  • License Apache-2.0

Complete implementation of Language-Integrated Query (LINQ) (ECMAScript 2015 Language Specification)

Package Exports

  • linq-es2015

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (linq-es2015) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Coverage Status Dependency Status License

Language-Integrated Query (LINQ)

linq-es2015 is a complete implementation of LINQ (Language-Integrated Query) pattern and enables you to express traversal, filter, and projection operations over data in JavaScript or any related programming languages (TypeScript, CoffeeScript, etc).
It provides an implementation of the standard query operators for querying any data source that implements Iterable. Methods that are used in a query that return a sequence of values do not consume the target data until the query object is enumerated. This is known as deferred execution. Methods that are used in a query that returns a singleton value execute and consume the target data immediately.

The library is a continuous effort to implement LINQ using latest features of TypeScript and JavaScript languages (For ES5 compatible library look at linq-es5 branch and corresponding NPM package). The library is implemented in TypeScript and transpiled into JavaScript. It is distributed as a native node module. Browserified and minified standalone UMD modules are located in ./dist directory and could be used directly in compatible browsers. This library uses latest ECMAScript 2015 language specification and utilizes Iterables: ( [System.iterator] ), JavaScript generators (function*), and for of loops. All relevant methods are implemented with deferred execution so no unnecessary iterations are performed. The code is backwards compatible with linq-es5 and C# implementations.

Installation

npm install linq-es2015

Using

var Enumerable = require("linq-es2015");
 
var count =  Enumerable.asEnumerable( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] )
                       .Where(a => a % 2 == 1)
                       .Count()

For live examples please follow links to (Node) or (Browser).

Using in browser

Browserified standalone UMD module is located in ./dist directory and could be accessed through NPM CDN service. Both linq.js and linq.min.js are available.
[See Example]

Using in Angular

The same package could be used on a server as well as on a client. All you have to do is to install module as usual:

npm install linq-es2015 --save

In file systemjs.config.js add following two entries:

// map tells the System loader where to look for things
  var map = {
    '@angular':      'node_modules/@angular',
    'linq-es2015':   'node_modules/linq-es2015', // map to module
    . . .
  };

and

// packages tells the System loader how to load when no filename and/or no extension
  var packages = {
    'app':           { main: 'main.js',  defaultExtension: 'js' },
    'linq-es2015':   { main: 'dist/linq.js', defaultExtension: 'js' }, // map to browserified module
    . . .
  };

On the server package is available as any normal module, on the cliend use it like this:

import { Component } from '@angular/core';
import { asEnumerable } from 'linq-es2015';

@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 2 App with LINQ</h1><div>Count - {{Count}}</div>'
})
export class AppComponent { 
    Count: number;

    constructor(){
        this.Count = asEnumerable([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).Where(a => a % 2 == 1)
                                                                  .Count();        
    }
}

[See Example]

Naming Convention

When library is used in TypeScript method names follow original C# convention (Name starts with capital letter). It is done for compatibility reasons so that code could be cut/pasted from C# with just minor reformatting. If used directly in JavaScript names follow camelCase notation.

Documentation

Example Projects