https://github.com/eniks/linq
TypeScript Implementation of Language-Integrated Query (LINQ) (ECMAScript 2015)
https://github.com/eniks/linq
angular ecmascript2015 iterables javascript linq typescript
Last synced: 12 months ago
JSON representation
TypeScript Implementation of Language-Integrated Query (LINQ) (ECMAScript 2015)
- Host: GitHub
- URL: https://github.com/eniks/linq
- Owner: ENikS
- License: apache-2.0
- Created: 2015-05-31T20:42:18.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2021-04-12T17:58:38.000Z (almost 5 years ago)
- Last Synced: 2025-03-31T07:08:34.013Z (12 months ago)
- Topics: angular, ecmascript2015, iterables, javascript, linq, typescript
- Language: TypeScript
- Homepage:
- Size: 768 KB
- Stars: 115
- Watchers: 13
- Forks: 26
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/ENikS/LINQ)
[](https://coveralls.io/github/ENikS/LINQ?branch=master)
[](https://dependencyci.com/github/ENikS/LINQ)
[](https://greenkeeper.io/)
[](https://badge.fury.io/js/linq-es2015)
[](https://www.npmjs.com/package/linq-es2015)
[](https://github.com/ENikS/LINQ/blob/master/LICENSE)
The library is a continuous effort to implement LINQ using latest features of TypeScript and JavaScript languages (For [ES5](http://www.ecma-international.org/ecma-262/5.1/) compatible library look at [linq-es5](https://github.com/ENikS/LINQ/tree/linq-es5) branch). The library is implemented in TypeScript and transpiled into JavaScript. It is distributed as a native module. It utilizes latest [ECMAScript 2015](http://www.ecma-international.org/ecma-262/6.0/) language specification: [Iterables](http://www.ecma-international.org/ecma-262/6.0/#sec-iterable-interface) ([ [System.iterator] ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)), generators ([function*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*)), [for of](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) loops.
All relevant methods are implemented with [deferred execution](https://blogs.msdn.microsoft.com/charlie/2007/12/10/linq-and-deferred-execution/) so no unnecessary iterations are performed.
The code is backwards compatible with [linq-es5](https://github.com/ENikS/LINQ/tree/linq-es5) and [C#](https://msdn.microsoft.com/en-us/library/system.linq.enumerable.aspx) implementations.
## Using in Node
Install module with this command:
```
npm install linq-es2015 --save
```
Once installed it could be loaded and used like this:
```javascript
import * as Enumerable from "linq-es2015";
var count = Enumerable.asEnumerable( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] )
.Where(a => a % 2 == 1)
.Count()
var iterable = Enumerable.asEnumerable(people)
.GroupJoin(pets,
person => person,
pet => pet.Owner,
(person, petCollection) => {
return {
Owner: person.Name,
Pets: asEnumerable(petCollection)
.Select(pet=> pet.Name)
.ToArray()
};
});
```
[[See Example](https://tonicdev.com/eniks/using-linq)]
## Using in browser
[Browserified](//browserify.org/) "[standalone](//github.com/substack/node-browserify#usage)" [UMD](//github.com/umdjs/umd) module is located in ```/dist``` directory and could be accessed through [NPM CDN service](//unpkg.com). Both [linq.js](//unpkg.com/linq-es2015/dist/linq.js) and [linq.min.js](//unpkg.com/linq-es2015/dist/linq.min.js) are available.
Module is loaded with `````` element:
```javascript
<script type="text/javascript" src="//unpkg.com/linq-es2015/dist/linq.min.js">
```
Loading this script creates ```Enumerable``` global variable. You can use it to perform LINQ queries:
```javascript
var count = Enumerable.asEnumerable( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] )
.Where(a => a % 2 == 1)
.Count()
```
[[See Example](//jsfiddle.net/ENikS/pyvjcfa0/)]
## Using in Angular 2
The same package could be used on a server as well as on the client. You have to install module as usual:
```
npm install linq-es2015 --save
```
Open ```app.components.html``` file and add element to hold calculated value:
```javascript
{{title}}
Count - {{count}}
```
and finally import ```linq-es2015``` in app.component.ts and do some calculations:
```javascript
import { Component } from '@angular/core';
import { asEnumerable } from 'linq-es2015';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
count: number;
constructor(){
this.count = asEnumerable([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).Where(a => a % 2 == 1)
.Count();
}
}
```
[[See Example](https://github.com/ENikS/LINQ/tree/examples/Angular)]
## Documentation
* [Library Reference](https://github.com/ENikS/LINQ/wiki)
* [LINQ (Language-Integrated Query)](https://msdn.microsoft.com/en-us/library/bb397926.aspx)
* [Original Documentation (C#)](https://msdn.microsoft.com/en-us/library/system.linq.enumerable.aspx)
## [Example Projects](https://github.com/ENikS/LINQ/tree/examples)
* [Browser Example](https://jsfiddle.net/ENikS/pyvjcfa0/)
* [Node Example](https://tonicdev.com/eniks/using-linq)
* [Angular 2 Example](https://github.com/ENikS/LINQ/tree/examples/Angular)
* [Node Console Example](https://github.com/ENikS/LINQ/tree/examples/Node)
* [TypeScript/JavaScript Web Example](https://github.com/ENikS/LINQ/tree/examples/TypeScript)