Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ENikS/LINQ
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.9.4
Choose a base ref
...
head repository: ENikS/LINQ
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 1,741 additions and 913 deletions.
  1. +1 −0 .gitignore
  2. +2 −1 .npmignore
  3. +3 −3 .travis.yml
  4. +46 −0 .vscode/launch.json
  5. +24 −0 .vscode/settings.json
  6. +10 −0 .vscode/tasks.json
  7. +7 −0 .vsnodetools.njsproj
  8. +16 −3 NPM.md
  9. +64 −10 README.md
  10. +78 −47 lib/enumerable.ts
  11. +56 −10 lib/generators.ts
  12. +173 −161 lib/linq.ts
  13. +14 −9 lib/utilities.ts
  14. +8 −6 package.json
  15. +69 −3 test/data.ts
  16. +357 −117 test/deferred.ts
  17. +59 −0 test/helpers.ts
  18. +5 −24 test/ienumerable.ts
  19. +22 −6 test/immediate.ts
  20. +2 −2 test/module.ts
  21. +275 −122 test/nogen.ts
  22. +447 −0 test/reentrancy.ts
  23. +3 −1 tsconfig.json
  24. +0 −388 typings/chai-3.2.0.d.ts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -200,3 +200,4 @@ FakesAssemblies/
/lib/test
/lib/src
*.d.ts
/package-lock.json
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ typings/
bin/
obj/
.vs/
.vscode/

test/*.ts

@@ -42,4 +43,4 @@ lib/iterators.d.ts
lib/iterators.ts
lib/linq.ts
lib/utilities.d.ts
lib/utilities.ts
lib/utilities.ts
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
sudo: false
language: node_js

node_js: node
node_js: "node"

install:
- npm install -g typescript
- npm install -g istanbul
- npm install -g remap-istanbul
- npm install -g coveralls
- npm install mocha-lcov-reporter
- npm install
#- npm install yarn
- yarn install

script:
- npm run build
46 changes: 46 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": ["test/", "--recurcive"],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": true,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
},
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"processId": "${command.PickProcess}",
"port": 5858,
"sourceMaps": false,
"outDir": null
}
]
}
24 changes: 24 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/*.js": { "when": "$(basename).ts"},
"test/*.d.ts": true,
"lib/*.d.ts": true,
"**/*.map": true,
"**/*.njsproj": true,
"**/*.git": true,
"**/*.svn": true,
"**/*.hg": true,
"TestResults": true,
"obj": true,
"Obj": true,
"bin": true,
"Bin": true,
".vs": true,
".vscode": true,
"node_modules": true,
"**/*.DS_Store": true
}
}


10 changes: 10 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}
7 changes: 7 additions & 0 deletions .vsnodetools.njsproj
Original file line number Diff line number Diff line change
@@ -46,6 +46,10 @@
<TypeScriptCompile Include="test\deferred.ts">
<TestFramework>Mocha</TestFramework>
</TypeScriptCompile>
<TypeScriptCompile Include="test\helpers.ts">
<SubType>Code</SubType>
<TestFramework>Mocha</TestFramework>
</TypeScriptCompile>
<TypeScriptCompile Include="test\ienumerable.ts">
<TestFramework>Mocha</TestFramework>
</TypeScriptCompile>
@@ -61,6 +65,9 @@
<TypeScriptCompile Include="test\nogen.ts">
<TestFramework>Mocha</TestFramework>
</TypeScriptCompile>
<TypeScriptCompile Include="test\reentrancy.ts">
<TestFramework>Mocha</TestFramework>
</TypeScriptCompile>
<TypeScriptCompile Include="typings\chai-3.2.0.d.ts" />
<TypeScriptCompile Include="typings\mocha.2.2.5.d.ts" />
</ItemGroup>
19 changes: 16 additions & 3 deletions NPM.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[![Coverage Status](https://coveralls.io/repos/github/ENikS/LINQ/badge.svg?branch=master)](https://coveralls.io/github/ENikS/LINQ?branch=master)
[![Dependency Status](https://dependencyci.com/github/ENikS/LINQ/badge)](https://dependencyci.com/github/ENikS/LINQ)
[![License](https://img.shields.io/badge/license-apache%202.0-60C060.svg)](https://github.com/ENikS/LINQ/blob/master/LICENSE)

## Language-Integrated Query (LINQ)

**linq-es2015** is a complete implementation of [LINQ (Language-Integrated Query)](https://en.wikipedia.org/wiki/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). <br/>
It provides an implementation of the standard query operators for querying any data source that implements Iterable<T>. 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](https://blogs.msdn.microsoft.com/charlie/2007/12/10/linq-and-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](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 node module.
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 and corresponding [NPM package](https://www.npmjs.com/package/linq-es5)). 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](http://www.ecma-international.org/ecma-262/6.0/) language specification and utilizes [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)), JavaScript generators ([function*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*)), and [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.
@@ -25,6 +27,14 @@ var count = Enumerable.asEnumerable( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] )
```
For live examples please follow links to ([Node](https://tonicdev.com/eniks/using-linq)) or ([Browser](https://jsfiddle.net/ENikS/pyvjcfa0)).

## 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. <br/>[[See Example](//jsfiddle.net/ENikS/pyvjcfa0/)]


## Using in Angular
The same package could be used on a server as well as on the client. The package does not require any special handling and used as any other module.
[[See Example](https://github.com/ENikS/LINQ/tree/examples/Angular)]

## 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](https://en.wikipedia.org/wiki/CamelCase) notation.
@@ -33,9 +43,12 @@ If used directly in JavaScript names follow [camelCase](https://en.wikipedia.org
* [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)

## Example Projects
* [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)


74 changes: 64 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
[![Build Status](https://travis-ci.org/ENikS/LINQ.svg?branch=master)](https://travis-ci.org/ENikS/LINQ)
[![Coverage Status](https://coveralls.io/repos/github/ENikS/LINQ/badge.svg?branch=master)](https://coveralls.io/github/ENikS/LINQ?branch=master)
[![Dependency Status](https://dependencyci.com/github/ENikS/LINQ/badge)](https://dependencyci.com/github/ENikS/LINQ)
[![Greenkeeper badge](https://badges.greenkeeper.io/ENikS/LINQ.svg)](https://greenkeeper.io/)
[![npm version](https://badge.fury.io/js/linq-es2015.svg)](https://badge.fury.io/js/linq-es2015)
[![Downloads](https://img.shields.io/npm/dm/linq-es2015.svg)](https://www.npmjs.com/package/linq-es2015)
[![License](https://img.shields.io/badge/license-apache%202.0-60C060.svg)](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 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](http://www.ecma-international.org/ecma-262/6.0/) language specification and utilizes [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)), JavaScript generators ([function*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*)), and [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 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. <br/> 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
## 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";
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)
@@ -31,18 +37,66 @@ var iterable = Enumerable.asEnumerable(people)
});

```
For live examples please follow links to ([Node](https://tonicdev.com/eniks/using-linq)) or ([Browser](https://jsfiddle.net/ENikS/pyvjcfa0)).
[[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 ```<script>``` element:
```javascript
<script type="text/javascript" src="//unpkg.com/linq-es2015/dist/linq.min.js"></script>
```
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
<h1>{{title}}</h1>
<div>Count - {{count}}</div>
```
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']
})

## 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](https://en.wikipedia.org/wiki/CamelCase) notation.
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)

## [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)


Loading