You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
importEnumerablefrom'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
+
constEnumerable=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
+
importEnumerablefrom'linq';
100
+
101
+
typetnum=Enumerable.IEnumerable<number>;
102
+
let x:tnum=Enumerable.from([1, 2, 3]);
47
103
```
48
104
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
+
importEnumerablefrom'./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.
[Yoshifumi Kawai](https://github.com/neuecc) developed the [original version](http://linqjs.codeplex.com/) of this library, currently no longer maintained.
0 commit comments