linqx 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -91
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,151 +1,169 @@
|
|
|
1
1
|
# linqx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Modern fork of the original [linq](https://github.com/mihaifm/linq) for JavaScript.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
linqx keeps the familiar LINQ-style API while adding modern exports, new utility methods, improved TypeScript support, and active maintenance.
|
|
6
6
|
|
|
7
|
-
Written in pure JavaScript with no dependencies.
|
|
7
|
+
Written in pure JavaScript with no runtime dependencies.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
---
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
// C# LINQ - delegate
|
|
13
|
-
Enumerable.Range(1, 10)
|
|
14
|
-
.Where(delegate(int i) { return i % 3 == 0; })
|
|
15
|
-
.Select(delegate(int i) { return i * 10; });
|
|
11
|
+
# Key Differences from linq
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
Enumerable.range(1, 10)
|
|
19
|
-
.where(function(i) { return i % 3 == 0; })
|
|
20
|
-
.select(function(i) { return i * 10; });
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
// C# LINQ - lambda
|
|
25
|
-
Enumerable.Range(1, 10).Where((i) => i % 3 == 0).Select((i) => i * 10);
|
|
13
|
+
## 1. Named Export Added
|
|
26
14
|
|
|
27
|
-
|
|
28
|
-
Enumerable.range(1, 10).where((i) => i % 3 == 0).select((i) => i * 10);
|
|
29
|
-
```
|
|
15
|
+
The original package only exposed a default export.
|
|
30
16
|
|
|
31
|
-
|
|
32
|
-
// C# LINQ - anonymous type
|
|
33
|
-
array.Select((val, i) => new { Value: val, Index: i }());
|
|
17
|
+
linqx also provides:
|
|
34
18
|
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
```ts
|
|
20
|
+
export { Enumerable };
|
|
37
21
|
```
|
|
38
22
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# Usage
|
|
42
|
-
|
|
43
|
-
## Node.js (ES modules)
|
|
23
|
+
This makes extensions, wrappers, and custom integrations cleaner and more flexible for `typescript`.
|
|
44
24
|
|
|
45
|
-
|
|
25
|
+
Example:
|
|
46
26
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
27
|
+
```ts
|
|
28
|
+
// enumerable.extensions.ts
|
|
29
|
+
import { Enumerable } from "linqx";
|
|
50
30
|
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
declare module "linqx" {
|
|
32
|
+
namespace Enumerable {
|
|
33
|
+
export function crossJoin<T>(this: Enumerable.IEnumerable<T>): Enumerable.IEnumerable<{ left: T; right: T; }>;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
53
36
|
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
Enumerable.prototype.crossJoin = function <T>(this: Enumerable.IEnumerable<T>): Enumerable.IEnumerable<{ left: T; right: T; }> {
|
|
38
|
+
return Enumerable.from(crossJoinIterator(this));
|
|
39
|
+
|
|
40
|
+
function* crossJoinIterator(enumerable: Enumerable.IEnumerable<T>): Iterable<{ left: T; right: T; }> {
|
|
41
|
+
for (const item of enumerable) {
|
|
42
|
+
for (const otherItem of enumerable) {
|
|
43
|
+
yield { left: item, right: otherItem };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
56
48
|
```
|
|
57
49
|
|
|
58
|
-
|
|
50
|
+
Useful when augmenting prototypes or writing reusable helpers.
|
|
59
51
|
|
|
60
|
-
|
|
61
|
-
"type": "module"
|
|
62
|
-
```
|
|
52
|
+
---
|
|
63
53
|
|
|
64
|
-
|
|
54
|
+
## 2. Additional APIs
|
|
65
55
|
|
|
66
|
-
|
|
56
|
+
linqx adds practical methods not available in the original package.
|
|
67
57
|
|
|
68
|
-
Install version 3 of this library:
|
|
69
58
|
|
|
70
|
-
|
|
59
|
+
```ts
|
|
60
|
+
whereIf(flag, predicate)
|
|
61
|
+
page(pageNumber, pageSize)
|
|
62
|
+
page({ pageNumber, pageSize })
|
|
63
|
+
joinWith(separator)
|
|
64
|
+
toMap(keySelector, valueSelector)
|
|
65
|
+
chunk(size)
|
|
66
|
+
index()
|
|
67
|
+
position()
|
|
68
|
+
withNeighbors()
|
|
69
|
+
```
|
|
71
70
|
|
|
72
|
-
|
|
71
|
+
---
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
const Enumerable = require('linq')
|
|
73
|
+
# Installation
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
```bash
|
|
76
|
+
npm install linqx
|
|
79
77
|
```
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
---
|
|
82
80
|
|
|
83
|
-
|
|
81
|
+
# Usage
|
|
84
82
|
|
|
85
|
-
|
|
83
|
+
## ES Modules
|
|
86
84
|
|
|
87
|
-
|
|
85
|
+
```ts
|
|
86
|
+
import Enumerable from "linqx";
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
const result = Enumerable
|
|
89
|
+
.range(1, 10)
|
|
90
|
+
.where(x => x % 3 === 0)
|
|
91
|
+
.select(x => x * 10)
|
|
92
|
+
.toArray();
|
|
94
93
|
```
|
|
95
94
|
|
|
96
|
-
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Named Export
|
|
97
98
|
|
|
98
99
|
```ts
|
|
99
|
-
import Enumerable from
|
|
100
|
+
import { Enumerable } from "linqx";
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
let x: tnum = Enumerable.from([1, 2, 3]);
|
|
102
|
+
const values = Enumerable.from([1, 2, 3]);
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
---
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
## TypeScript
|
|
108
108
|
|
|
109
109
|
```ts
|
|
110
|
-
|
|
111
|
-
import Enumerable from 'https://deno.land/x/linq@4.0.0/linq.js'
|
|
110
|
+
import Enumerable from "linqx";
|
|
112
111
|
|
|
113
|
-
|
|
112
|
+
const items: Enumerable.IEnumerable<number> = Enumerable.from([1, 2, 3]);
|
|
114
113
|
```
|
|
114
|
+
---
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
## New API Examples
|
|
117
117
|
|
|
118
118
|
```ts
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
// whereIf
|
|
120
|
+
Enumerable
|
|
121
|
+
.from([1, 2, 3, 4])
|
|
122
|
+
.whereIf(true, x => x > 2)
|
|
123
|
+
.toArray();
|
|
124
|
+
|
|
125
|
+
// chunk
|
|
126
|
+
Enumerable
|
|
127
|
+
.from([1, 2, 3, 4, 5])
|
|
128
|
+
.chunk(2)
|
|
129
|
+
.toArray();
|
|
130
|
+
// result: [[1, 2], [3, 4], [5]]
|
|
131
|
+
|
|
132
|
+
// withNeighbors
|
|
133
|
+
for (const { prev, item, next } of Enumerable.from([10, 20, 30]).withNeighbors()) {
|
|
134
|
+
}
|
|
122
135
|
|
|
123
|
-
|
|
136
|
+
// position
|
|
137
|
+
for (const { index, item, isFirst, isLast } of Enumerable.from(["a", "b", "c"]).position()) {
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
---
|
|
124
141
|
|
|
125
|
-
|
|
142
|
+
# Migration from linq
|
|
126
143
|
|
|
127
|
-
|
|
144
|
+
Most projects can switch directly:
|
|
128
145
|
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
import Enumerable from './linq.min.js'
|
|
133
|
-
Enumerable.from([1, 2, 3]).forEach(x => console.log(x))
|
|
134
|
-
</script>
|
|
146
|
+
```diff
|
|
147
|
+
-import Enumerable from "linq";
|
|
148
|
+
+import Enumerable from "linqx";
|
|
135
149
|
```
|
|
136
150
|
|
|
137
|
-
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
# Repository
|
|
138
154
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
| jsDelivr | <https://jsdelivr.com/package/npm/linq> |
|
|
143
|
-
| packd | <https://bundle.run/linq@latest?name=linq> |
|
|
155
|
+
https://github.com/huoshan12345/linqx
|
|
156
|
+
|
|
157
|
+
---
|
|
144
158
|
|
|
145
159
|
# Credits
|
|
146
160
|
|
|
147
|
-
|
|
161
|
+
Based on the original work by Yoshifumi Kawai and later linq maintainers.
|
|
162
|
+
|
|
163
|
+
Independent community fork.
|
|
164
|
+
|
|
165
|
+
---
|
|
148
166
|
|
|
149
167
|
# License
|
|
150
168
|
|
|
151
|
-
|
|
169
|
+
MIT
|
package/package.json
CHANGED