Skip to content

Commit 6e79333

Browse files
committed
Documentation improvements and additional changes
1 parent 9adbe63 commit 6e79333

File tree

4 files changed

+115
-82
lines changed

4 files changed

+115
-82
lines changed

README.md

+111-22
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
## linq
2-
This is a javascript implementation of the .NET [LINQ](https://msdn.microsoft.com/en-us/library/bb308959.aspx) library.
1+
# linq
32

4-
It contains all the original .NET methods plus a few additions.
5-
6-
### Installation
3+
This is a JavaScript implementation of the .NET [LINQ](https://msdn.microsoft.com/en-us/library/bb308959.aspx) library.
74

8-
With npm:
9-
10-
npm install linq
5+
It contains all the original .NET methods plus a few additions.
116

12-
CDN availability:
7+
Written in pure JavaScript with no dependencies.
138

14-
| CDN | URL |
15-
|-----------:|:-------------------------------------------|
16-
| `unpkg` | <https://unpkg.com/linq/> |
17-
| `jsDelivr` | <https://jsdelivr.com/package/npm/linq> |
18-
| `packd` | <https://bundle.run/linq@latest?name=linq> |
9+
## Examples
1910

20-
### Examples
2111
```js
2212
// C# LINQ - delegate
2313
Enumerable.Range(1, 10)
@@ -32,26 +22,125 @@ Enumerable.range(1, 10)
3222

3323
```js
3424
// C# LINQ - lambda
35-
Enumerable.Range(1, 10).Where(i => i % 3 == 0).Select(i => i * 10);
25+
Enumerable.Range(1, 10).Where((i) => i % 3 == 0).Select((i) => i * 10);
3626

3727
// linq.js - arrow function
38-
Enumerable.range(1, 10).where(i => i % 3 == 0).select(i => i * 10);
28+
Enumerable.range(1, 10).where((i) => i % 3 == 0).select((i) => i * 10);
3929
```
4030

4131
```js
4232
// C# LINQ - anonymous type
43-
array.Select((val, i) => new { Value = val, Index = i });
33+
array.Select((val, i) => new { Value: val, Index: i }());
4434

4535
// linq.js - object literal
46-
Enumerable.from(array).select((val, i) => ({ value: val, index: i}));
36+
Enumerable.from(array).select((val, i) => ({ value: val, index: i }));
37+
```
38+
39+
See [sample/tutorial.js](https://github.com/mihaifm/linq/blob/master/sample/tutorial.js) and the [test](https://github.com/mihaifm/linq/tree/master/test) folder for more examples.
40+
41+
# Usage
42+
43+
## Node.js (ES modules)
44+
45+
Install the latest version of the library with npm:
46+
47+
npm install linq
48+
49+
Load it in your code with the `import` syntax:
50+
51+
```js
52+
import Enumerable from 'linq'
53+
54+
let result = Enumerable.range(1, 10).where(i => i % 3 == 0).select(i => i * 10)
55+
console.log(result.toArray()) // [ 30, 60, 90 ]
56+
```
57+
58+
Because the library is an ES module, this code will only work if your project is also configured as an ES module. Add the following line in your `package.json` to make it an ES module:
59+
60+
```json
61+
"type": "module"
62+
```
63+
64+
If you're not planning to use ES modules, check the CommonJS section below.
65+
66+
## Node.js (CommonJS modules)
67+
68+
Install version 3 of this library:
69+
70+
npm install linq@3
71+
72+
Load it with the `require` syntax:
73+
74+
```js
75+
const Enumerable = require('linq')
76+
77+
let count = Enumerable.range(1, 10).count(i => i < 5)
78+
console.log(count) // 4
79+
```
80+
81+
The [cjs](https://github.com/mihaifm/linq/tree/cjs) branch contains the source code for the CommonJS version of the library.
82+
83+
## TypeScript
84+
85+
Install the latest version of the library with npm.
86+
87+
Configure your compiler options in `tsconfig.json`
88+
89+
```json
90+
"compilerOptions": {
91+
"target": "ES2020",
92+
"moduleResolution": "node"
93+
}
94+
```
95+
96+
The library comes with a `d.ts` file containing type definitions for all the objects and methods, feel free to use them in your code:
97+
98+
```ts
99+
import Enumerable from 'linq';
100+
101+
type tnum = Enumerable.IEnumerable<number>;
102+
let x: tnum = Enumerable.from([1, 2, 3]);
47103
```
48104

49-
See [sample/tutorial.js](https://github.com/mihaifm/linq/blob/master/sample/tutorial.js) for more examples.
105+
## Deno
106+
107+
Install the latest version of the library with npm.
108+
109+
Use the full file path when importing the library. Also use the `@deno-types` annotation to load type definitions:
110+
111+
```ts
112+
// @deno-types="./node_modules/linq/linq.d.ts"
113+
import Enumerable from './node_modules/linq/linq.js'
114+
115+
let radius = Enumerable.toInfinity(1).where(r => r * r * Math.PI > 10000).first()
116+
```
117+
118+
## Browser
119+
120+
The minified version of the library is available in the [release](https://github.com/mihaifm/linq/releases/latest) archive.
121+
122+
Load it via `<script type="module">`:
123+
124+
```html
125+
<script type="module" src="./linq.min.js"></script>
126+
<script type="module">
127+
import Enumerable from './linq.min.js'
128+
Enumerable.from([1, 2, 3]).forEach(x => console.log(x))
129+
</script>
130+
```
131+
132+
You can also load the library via a CDN:
133+
134+
| CDN | URL |
135+
| ---------: | :----------------------------------------- |
136+
| unpkg | <https://unpkg.com/linq/> |
137+
| jsDelivr | <https://jsdelivr.com/package/npm/linq> |
138+
| packd | <https://bundle.run/linq@latest?name=linq> |
50139

51-
### People
140+
# Credits
52141

53142
[Yoshifumi Kawai](https://github.com/neuecc) developed the [original version](http://linqjs.codeplex.com/) of this library, currently no longer maintained.
54143

55-
### License
144+
# License
56145

57146
[MIT License](https://github.com/mihaifm/linq/blob/master/LICENSE)

package.json

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,25 @@
33
"author": "Mihai Ciuraru <[email protected]>",
44
"description": "linq.js - LINQ for JavaScript",
55
"type": "module",
6-
"version": "3.2.4",
6+
"version": "4.0.0",
77
"license": "MIT",
88
"homepage": "https://github.com/mihaifm/linq",
99
"repository": {
1010
"type": "git",
1111
"url": "https://github.com/mihaifm/linq.git"
1212
},
1313
"scripts": {
14-
"test": "node test/testrunner.js",
15-
"minify": "uglifyjs linq.js -c -m -o linq.min.js"
14+
"test": "node test/testrunner.js"
1615
},
1716
"preferGlobal": false,
1817
"keywords": [
1918
"linq"
2019
],
2120
"dependencies": {},
22-
"devDependencies": {
23-
"uglify-js": "3.10.3"
24-
},
2521
"engines": {
2622
"node": "*"
2723
},
28-
"main": "./linq",
24+
"main": "./linq.js",
2925
"exports": "./linq.js",
3026
"types": "./linq.d.ts"
3127
}

sample/tutorial.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Enumerable = require('../linq');
1+
import Enumerable from '../linq.js'
22

33
/////////////////////////////
44
// Simple Lambda Expressions

util/gpg_keys/mihaifm.asc

-52
This file was deleted.

0 commit comments

Comments
 (0)