linqx 0.2.0 → 0.3.2

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.
Files changed (144) hide show
  1. package/README.md +181 -87
  2. package/dist/core/dictionary.d.ts +14 -0
  3. package/dist/core/enumerable.d.ts +9 -0
  4. package/dist/core/enumerator.d.ts +10 -0
  5. package/dist/core/grouping.d.ts +11 -0
  6. package/dist/core/lookup.d.ts +12 -0
  7. package/dist/core/memoized-enumerable.d.ts +12 -0
  8. package/dist/core/ordered-enumerable.d.ts +14 -0
  9. package/dist/core/shared-enumerable.d.ts +10 -0
  10. package/dist/extensions.d.ts +18 -0
  11. package/dist/extensions.js +13 -0
  12. package/dist/factories/choice.d.ts +8 -0
  13. package/dist/factories/cycle.d.ts +8 -0
  14. package/dist/factories/defer.d.ts +8 -0
  15. package/dist/factories/empty.d.ts +3 -0
  16. package/dist/factories/from.d.ts +46 -0
  17. package/dist/factories/generate.d.ts +9 -0
  18. package/dist/factories/make.d.ts +8 -0
  19. package/dist/factories/matches.d.ts +14 -0
  20. package/dist/factories/range-down.d.ts +10 -0
  21. package/dist/factories/range-to.d.ts +12 -0
  22. package/dist/factories/range.d.ts +10 -0
  23. package/dist/factories/repeat-with-finalize.d.ts +9 -0
  24. package/dist/factories/repeat.d.ts +9 -0
  25. package/dist/factories/to-infinity.d.ts +9 -0
  26. package/dist/factories/to-negative-infinity.d.ts +9 -0
  27. package/dist/factories/unfold.d.ts +9 -0
  28. package/dist/index.d.ts +87 -3
  29. package/dist/index.js +2 -4
  30. package/dist/internal/create-enumerable.d.ts +3 -0
  31. package/dist/internal/functions.d.ts +6 -0
  32. package/dist/internal/to-iterable.d.ts +2 -0
  33. package/dist/operators/aggregate-by.d.ts +2 -0
  34. package/dist/operators/aggregate.d.ts +2 -0
  35. package/dist/operators/all.d.ts +2 -0
  36. package/dist/operators/alternate.d.ts +2 -0
  37. package/dist/operators/any.d.ts +2 -0
  38. package/dist/operators/append.d.ts +2 -0
  39. package/dist/operators/as-enumerable.d.ts +2 -0
  40. package/dist/operators/average.d.ts +2 -0
  41. package/dist/operators/buffer.d.ts +2 -0
  42. package/dist/operators/cast.d.ts +2 -0
  43. package/dist/operators/catch-error.d.ts +2 -0
  44. package/dist/operators/choose.d.ts +2 -0
  45. package/dist/operators/chunk.d.ts +2 -0
  46. package/dist/operators/concat.d.ts +2 -0
  47. package/dist/operators/contains.d.ts +2 -0
  48. package/dist/operators/count-by.d.ts +2 -0
  49. package/dist/operators/count.d.ts +2 -0
  50. package/dist/operators/create-ordered-enumerable.d.ts +2 -0
  51. package/dist/operators/default-if-empty.d.ts +2 -0
  52. package/dist/operators/distinct-by.d.ts +2 -0
  53. package/dist/operators/distinct-until-changed.d.ts +2 -0
  54. package/dist/operators/distinct.d.ts +2 -0
  55. package/dist/operators/do-action.d.ts +3 -0
  56. package/dist/operators/element-at-or-default.d.ts +2 -0
  57. package/dist/operators/element-at.d.ts +2 -0
  58. package/dist/operators/except-by.d.ts +2 -0
  59. package/dist/operators/except.d.ts +2 -0
  60. package/dist/operators/finally-action.d.ts +2 -0
  61. package/dist/operators/first-or-default.d.ts +2 -0
  62. package/dist/operators/first.d.ts +2 -0
  63. package/dist/operators/flatten.d.ts +2 -0
  64. package/dist/operators/for-each.d.ts +3 -0
  65. package/dist/operators/force.d.ts +2 -0
  66. package/dist/operators/group-by.d.ts +2 -0
  67. package/dist/operators/group-join.d.ts +2 -0
  68. package/dist/operators/index-of.d.ts +2 -0
  69. package/dist/operators/index.d.ts +2 -0
  70. package/dist/operators/insert.d.ts +2 -0
  71. package/dist/operators/intersect-by.d.ts +2 -0
  72. package/dist/operators/intersect.d.ts +2 -0
  73. package/dist/operators/is-empty.d.ts +2 -0
  74. package/dist/operators/join-with.d.ts +2 -0
  75. package/dist/operators/join.d.ts +2 -0
  76. package/dist/operators/last-index-of.d.ts +2 -0
  77. package/dist/operators/last-or-default.d.ts +2 -0
  78. package/dist/operators/last.d.ts +2 -0
  79. package/dist/operators/left-join.d.ts +2 -0
  80. package/dist/operators/let-bind.d.ts +2 -0
  81. package/dist/operators/log.d.ts +2 -0
  82. package/dist/operators/map.d.ts +2 -0
  83. package/dist/operators/max-by.d.ts +2 -0
  84. package/dist/operators/max.d.ts +2 -0
  85. package/dist/operators/memoize.d.ts +2 -0
  86. package/dist/operators/merge.d.ts +2 -0
  87. package/dist/operators/min-by.d.ts +2 -0
  88. package/dist/operators/min.d.ts +2 -0
  89. package/dist/operators/of-type.d.ts +2 -0
  90. package/dist/operators/operators.d.ts +208 -0
  91. package/dist/operators/order-by-descending.d.ts +2 -0
  92. package/dist/operators/order-by.d.ts +2 -0
  93. package/dist/operators/page.d.ts +2 -0
  94. package/dist/operators/pairwise.d.ts +2 -0
  95. package/dist/operators/partition-by.d.ts +2 -0
  96. package/dist/operators/position.d.ts +2 -0
  97. package/dist/operators/prepend.d.ts +2 -0
  98. package/dist/operators/reverse.d.ts +2 -0
  99. package/dist/operators/right-join.d.ts +2 -0
  100. package/dist/operators/scan.d.ts +2 -0
  101. package/dist/operators/select-many.d.ts +2 -0
  102. package/dist/operators/select.d.ts +2 -0
  103. package/dist/operators/sequence-equal.d.ts +2 -0
  104. package/dist/operators/share.d.ts +2 -0
  105. package/dist/operators/shuffle.d.ts +2 -0
  106. package/dist/operators/single-or-default.d.ts +2 -0
  107. package/dist/operators/single.d.ts +2 -0
  108. package/dist/operators/skip-last.d.ts +2 -0
  109. package/dist/operators/skip-while.d.ts +2 -0
  110. package/dist/operators/skip.d.ts +2 -0
  111. package/dist/operators/sum.d.ts +2 -0
  112. package/dist/operators/take-except-last.d.ts +2 -0
  113. package/dist/operators/take-from-last.d.ts +2 -0
  114. package/dist/operators/take-last.d.ts +2 -0
  115. package/dist/operators/take-while.d.ts +2 -0
  116. package/dist/operators/take.d.ts +2 -0
  117. package/dist/operators/then-by-descending.d.ts +2 -0
  118. package/dist/operators/then-by.d.ts +2 -0
  119. package/dist/operators/to-array.d.ts +2 -0
  120. package/dist/operators/to-dictionary.d.ts +2 -0
  121. package/dist/operators/to-joined-string.d.ts +2 -0
  122. package/dist/operators/to-json-string.d.ts +2 -0
  123. package/dist/operators/to-lookup.d.ts +2 -0
  124. package/dist/operators/to-map.d.ts +2 -0
  125. package/dist/operators/to-object.d.ts +2 -0
  126. package/dist/operators/to-set.d.ts +2 -0
  127. package/dist/operators/trace.d.ts +2 -0
  128. package/dist/operators/traverse-breadth-first.d.ts +2 -0
  129. package/dist/operators/traverse-depth-first.d.ts +2 -0
  130. package/dist/operators/union-by.d.ts +2 -0
  131. package/dist/operators/union.d.ts +2 -0
  132. package/dist/operators/weighted-sample.d.ts +2 -0
  133. package/dist/operators/where-if.d.ts +2 -0
  134. package/dist/operators/where.d.ts +2 -0
  135. package/dist/operators/with-neighbors.d.ts +2 -0
  136. package/dist/operators/zip.d.ts +2 -0
  137. package/dist/src-D_Mk3oMP.js +1597 -0
  138. package/dist/types.d.ts +1154 -0
  139. package/dist/utils.d.ts +56 -0
  140. package/package.json +18 -11
  141. package/dist/linq.d.ts +0 -256
  142. package/dist/linq.js +0 -3085
  143. package/dist/linqx.d.ts +0 -36
  144. package/dist/linqx.js +0 -153
package/README.md CHANGED
@@ -1,151 +1,245 @@
1
1
  # linqx
2
2
 
3
- Fork of the original [linq](https://github.com/mihaifm/linq) for JavaScript, updated with modern improvements and API changes.
3
+ Modern fork of the original [linq](https://github.com/mihaifm/linq) for JavaScript.
4
4
 
5
- It contains all the original .NET methods plus a few additions.
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 TypeScript with no runtime dependencies.
8
8
 
9
- ## Examples
9
+ ---
10
10
 
11
- ```js
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
- // linq.js - anonymous function
18
- Enumerable.range(1, 10)
19
- .where(function(i) { return i % 3 == 0; })
20
- .select(function(i) { return i * 10; });
21
- ```
13
+ ## 1. Named Export Added
14
+
15
+ The original package only exposed a default export.
22
16
 
23
- ```js
24
- // C# LINQ - lambda
25
- Enumerable.Range(1, 10).Where((i) => i % 3 == 0).Select((i) => i * 10);
17
+ linqx also provides:
26
18
 
27
- // linq.js - arrow function
28
- Enumerable.range(1, 10).where((i) => i % 3 == 0).select((i) => i * 10);
19
+ ```ts
20
+ export { Enumerable };
29
21
  ```
30
22
 
31
- ```js
32
- // C# LINQ - anonymous type
33
- array.Select((val, i) => new { Value: val, Index: i }());
23
+ This makes extensions, wrappers, and custom integrations cleaner and more flexible for `typescript`.
34
24
 
35
- // linq.js - object literal
36
- Enumerable.from(array).select((val, i) => ({ value: val, index: i }));
37
- ```
25
+ Example:
38
26
 
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.
27
+ ```ts
28
+ // enumerable.extensions.ts
29
+ import { Enumerable } from "linqx";
40
30
 
41
- # Usage
31
+ declare module "linqx" {
32
+ namespace Enumerable {
33
+ export function crossJoin<T>(this: Enumerable.IEnumerable<T>): Enumerable.IEnumerable<{ left: T; right: T; }>;
34
+ }
35
+ }
36
+
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
+ };
48
+ ```
42
49
 
43
- ## Node.js (ES modules)
50
+ Useful when augmenting prototypes or writing reusable helpers.
44
51
 
45
- Install the latest version of the library with npm:
52
+ ---
46
53
 
47
- npm install linq
54
+ ## 2. Additional APIs
48
55
 
49
- Load it in your code with the `import` syntax:
56
+ linqx adds practical methods not available in the original package.
50
57
 
51
- ```js
52
- import Enumerable from 'linq'
53
58
 
54
- let result = Enumerable.range(1, 10).where(i => i % 3 == 0).select(i => i * 10)
55
- console.log(result.toArray()) // [ 30, 60, 90 ]
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
+ append(element)
70
+ prepend(element)
71
+ skipLast(count)
72
+ takeLast(count)
73
+ distinctBy(keySelector)
74
+ exceptBy(keys, keySelector)
75
+ intersectBy(keys, keySelector)
76
+ unionBy(sequence, keySelector)
77
+ countBy(keySelector)
78
+ aggregateBy(keySelector, seed, accumulator)
79
+ rightJoin(sequence, outerKeySelector, innerKeySelector, resultSelector)
80
+ toSet()
56
81
  ```
57
82
 
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:
83
+ ---
59
84
 
60
- ```json
61
- "type": "module"
85
+ # Installation
86
+
87
+ ```bash
88
+ npm install linqx
62
89
  ```
63
90
 
64
- If you're not planning to use ES modules, check the CommonJS section below.
91
+ ---
92
+
93
+ # Usage
94
+
95
+ ## ES Modules
65
96
 
66
- ## Node.js (CommonJS modules)
97
+ ```ts
98
+ import Enumerable from "linqx";
67
99
 
68
- Install version 3 of this library:
100
+ const result = Enumerable
101
+ .range(1, 10)
102
+ .where(x => x % 3 === 0)
103
+ .select(x => x * 10)
104
+ .toArray();
105
+ ```
69
106
 
70
- npm install linq@3
107
+ ---
71
108
 
72
- Load it with the `require` syntax:
109
+ ## Named Export
73
110
 
74
- ```js
75
- const Enumerable = require('linq')
111
+ ```ts
112
+ import { Enumerable } from "linqx";
76
113
 
77
- let count = Enumerable.range(1, 10).count(i => i < 5)
78
- console.log(count) // 4
114
+ const values = Enumerable.from([1, 2, 3]);
79
115
  ```
80
116
 
81
- The [cjs](https://github.com/mihaifm/linq/tree/cjs) branch contains the source code for the CommonJS version of the library.
117
+ ---
82
118
 
83
119
  ## TypeScript
84
120
 
85
- Install the latest version of the library with npm.
121
+ ```ts
122
+ import Enumerable from "linqx";
86
123
 
87
- Configure your compiler options in `tsconfig.json`
124
+ const items: Enumerable.IEnumerable<number> = Enumerable.from([1, 2, 3]);
125
+ ```
88
126
 
89
- ```json
90
- "compilerOptions": {
91
- "target": "ES2020",
92
- "moduleResolution": "node"
93
- }
127
+ ## Tutorial
128
+
129
+ Build the package and run the TypeScript tutorial:
130
+
131
+ ```bash
132
+ pnpm tutorial
94
133
  ```
95
134
 
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:
135
+ ---
136
+
137
+ ## New API Examples
97
138
 
98
139
  ```ts
99
- import Enumerable from 'linq';
140
+ // whereIf
141
+ Enumerable
142
+ .from([1, 2, 3, 4])
143
+ .whereIf(true, x => x > 2)
144
+ .toArray();
145
+
146
+ // chunk
147
+ Enumerable
148
+ .from([1, 2, 3, 4, 5])
149
+ .chunk(2)
150
+ .toArray();
151
+ // result: [[1, 2], [3, 4], [5]]
152
+
153
+ // withNeighbors
154
+ for (const { prev, item, next } of Enumerable.from([10, 20, 30]).withNeighbors()) {
155
+ }
100
156
 
101
- type tnum = Enumerable.IEnumerable<number>;
102
- let x: tnum = Enumerable.from([1, 2, 3]);
157
+ // position
158
+ for (const { index, item, isFirst, isLast } of Enumerable.from(["a", "b", "c"]).position()) {
159
+ }
160
+
161
+ // Standard sequence helpers
162
+ Enumerable.from([2, 3]).prepend(1).append(4).toArray();
163
+ // result: [1, 2, 3, 4]
164
+
165
+ Enumerable.from([1, 2, 3, 4]).skipLast(2).toArray();
166
+ // result: [1, 2]
167
+
168
+ Enumerable.from([1, 2, 3, 4]).takeLast(2).toArray();
169
+ // result: [3, 4]
170
+
171
+ // Key-based set operations
172
+ Enumerable
173
+ .from([{ id: 1, name: "first" }, { id: 1, name: "second" }])
174
+ .distinctBy(item => item.id)
175
+ .toArray();
176
+ // result: [{ id: 1, name: "first" }]
177
+
178
+ Enumerable
179
+ .from([{ id: 1 }, { id: 2 }, { id: 3 }])
180
+ .exceptBy([2], item => item.id)
181
+ .toArray();
182
+ // result: [{ id: 1 }, { id: 3 }]
183
+
184
+ // Per-key aggregation
185
+ Enumerable
186
+ .from(["a", "b", "a"])
187
+ .countBy(value => value)
188
+ .toArray();
189
+ // result: [{ key: "a", value: 2 }, { key: "b", value: 1 }]
190
+
191
+ Enumerable
192
+ .from([{ category: "a", amount: 2 }, { category: "a", amount: 3 }])
193
+ .aggregateBy(item => item.category, 0, (sum, item) => sum + item.amount)
194
+ .toArray();
195
+ // result: [{ key: "a", value: 5 }]
196
+
197
+ // Native Set materialization
198
+ Enumerable.from([1, 1, 2]).toSet();
103
199
  ```
104
200
 
105
- ## Deno
201
+ `countBy` and `aggregateBy` return
202
+ `Enumerable.IEnumerable<Enumerable.KeyValuePair<TKey, TValue>>`. Key-based methods accept an
203
+ optional final comparison selector when keys need normalization, such as
204
+ `key => key.toLowerCase()` for case-insensitive string keys.
106
205
 
107
- Import the library from deno.land. Use the `@deno-types` annotation to load type definitions:
206
+ ---
108
207
 
109
- ```ts
110
- // @deno-types="https://deno.land/x/linq@4.0.0/linq.d.ts"
111
- import Enumerable from 'https://deno.land/x/linq@4.0.0/linq.js'
208
+ # Migration from linq
209
+
210
+ Most projects can switch directly:
112
211
 
113
- let radius = Enumerable.toInfinity(1).where(r => r * r * Math.PI > 10000).first()
212
+ ```diff
213
+ -import Enumerable from "linq";
214
+ +import Enumerable from "linqx";
114
215
  ```
115
216
 
116
- You can also install locally with npm. Use the full file path when importing the library:
217
+ The original string Lambda syntax is no longer supported. Pass JavaScript functions instead:
117
218
 
118
219
  ```ts
119
- // @deno-types="./node_modules/linq/linq.d.ts"
120
- import Enumerable from './node_modules/linq/linq.js'
220
+ // supported
221
+ Enumerable.from([1, 2, 3, 4]).where(value => value % 2 === 0);
222
+
223
+ // not supported
224
+ Enumerable.from([1, 2, 3, 4]).where("value => value % 2 === 0");
121
225
  ```
122
226
 
123
- ## Browser
227
+ ---
124
228
 
125
- The minified version of the library is available in the [release](https://github.com/mihaifm/linq/releases/latest) archive.
229
+ # Repository
126
230
 
127
- Load it via `<script type="module">`:
231
+ https://github.com/huoshan12345/linqx
128
232
 
129
- ```html
130
- <script type="module" src="./linq.min.js"></script>
131
- <script type="module">
132
- import Enumerable from './linq.min.js'
133
- Enumerable.from([1, 2, 3]).forEach(x => console.log(x))
134
- </script>
135
- ```
233
+ ---
136
234
 
137
- You can also load the library via a CDN:
235
+ # Credits
138
236
 
139
- | CDN | URL |
140
- | ---------: | :----------------------------------------- |
141
- | unpkg | <https://unpkg.com/linq/> |
142
- | jsDelivr | <https://jsdelivr.com/package/npm/linq> |
143
- | packd | <https://bundle.run/linq@latest?name=linq> |
237
+ Based on the original work by Yoshifumi Kawai and later linq maintainers.
144
238
 
145
- # Credits
239
+ Independent community fork.
146
240
 
147
- [Yoshifumi Kawai](https://github.com/neuecc) developed the [original version](https://github.com/neuecc/linq.js/) of this library.
241
+ ---
148
242
 
149
243
  # License
150
244
 
151
- [MIT License](https://github.com/mihaifm/linq/blob/master/LICENSE)
245
+ MIT
@@ -0,0 +1,14 @@
1
+ import type { IDictionary, IEnumerable, KeyValuePair } from '../types.js';
2
+ export declare class Dictionary<TKey, TValue> implements IDictionary<TKey, TValue> {
3
+ private readonly compareSelector;
4
+ private readonly entries;
5
+ constructor(compareSelector?: (key: TKey) => unknown);
6
+ add(key: TKey, value: TValue): void;
7
+ get(key: TKey): TValue;
8
+ set(key: TKey, value: TValue): boolean;
9
+ contains(key: TKey): boolean;
10
+ clear(): void;
11
+ remove(key: TKey): void;
12
+ count(): number;
13
+ toEnumerable(): IEnumerable<KeyValuePair<TKey, TValue>>;
14
+ }
@@ -0,0 +1,9 @@
1
+ import type { IEnumerable, IEnumerator } from '../types.js';
2
+ export declare class EnumerableSequence<T> implements Iterable<T> {
3
+ private readonly iteratorFactory;
4
+ constructor(iteratorFactory: () => Iterator<T>);
5
+ [Symbol.iterator](): Iterator<T>;
6
+ getEnumerator(): IEnumerator<T>;
7
+ }
8
+ export interface EnumerableSequence<T> extends IEnumerable<T> {
9
+ }
@@ -0,0 +1,10 @@
1
+ import type { IEnumerator } from '../types.js';
2
+ export declare class Enumerator<T> implements IEnumerator<T> {
3
+ private readonly iterator;
4
+ private value;
5
+ private done;
6
+ constructor(iterator: Iterator<T>);
7
+ current(): T;
8
+ moveNext(): boolean;
9
+ dispose(): void;
10
+ }
@@ -0,0 +1,11 @@
1
+ import { EnumerableSequence } from './enumerable.js';
2
+ import type { IGrouping } from '../types.js';
3
+ export declare class Grouping<TKey, TElement> extends EnumerableSequence<TElement> {
4
+ private readonly groupKey;
5
+ private readonly source;
6
+ constructor(groupKey: TKey, source: TElement[]);
7
+ key(): TKey;
8
+ getSource(): TElement[];
9
+ }
10
+ export interface Grouping<TKey, TElement> extends IGrouping<TKey, TElement> {
11
+ }
@@ -0,0 +1,12 @@
1
+ import type { IEnumerable, ILookup } from '../types.js';
2
+ import { Grouping } from './grouping.js';
3
+ export declare class Lookup<TKey, TElement> implements ILookup<TKey, TElement> {
4
+ private readonly compareSelector;
5
+ private readonly entries;
6
+ constructor(compareSelector?: (key: TKey) => unknown);
7
+ add(key: TKey, element: TElement): void;
8
+ count(): number;
9
+ get(key: TKey): IEnumerable<TElement>;
10
+ contains(key: TKey): boolean;
11
+ toEnumerable(): IEnumerable<Grouping<TKey, TElement>>;
12
+ }
@@ -0,0 +1,12 @@
1
+ import type { IDisposableEnumerable } from '../types.js';
2
+ import { EnumerableSequence } from './enumerable.js';
3
+ export declare class MemoizedEnumerable<T> extends EnumerableSequence<T> {
4
+ private readonly sourceIterator;
5
+ private readonly cache;
6
+ private completed;
7
+ constructor(source: Iterable<T>);
8
+ private nextAt;
9
+ dispose(): void;
10
+ }
11
+ export interface MemoizedEnumerable<T> extends IDisposableEnumerable<T> {
12
+ }
@@ -0,0 +1,14 @@
1
+ import type { Comparer, IOrderedEnumerable } from '../types.js';
2
+ import { EnumerableSequence } from './enumerable.js';
3
+ export interface SortCriterion<T> {
4
+ keySelector: (element: T) => unknown;
5
+ comparer: Comparer<unknown>;
6
+ descending: boolean;
7
+ }
8
+ export declare class OrderedEnumerable<T> extends EnumerableSequence<T> {
9
+ readonly source: Iterable<T>;
10
+ readonly criteria: readonly SortCriterion<T>[];
11
+ constructor(source: Iterable<T>, criteria: readonly SortCriterion<T>[]);
12
+ }
13
+ export interface OrderedEnumerable<T> extends IOrderedEnumerable<T> {
14
+ }
@@ -0,0 +1,10 @@
1
+ import type { IDisposableEnumerable } from '../types.js';
2
+ import { EnumerableSequence } from './enumerable.js';
3
+ export declare class SharedEnumerable<T> extends EnumerableSequence<T> {
4
+ private readonly sourceIterator;
5
+ private disposed;
6
+ constructor(source: Iterable<T>);
7
+ dispose(): void;
8
+ }
9
+ export interface SharedEnumerable<T> extends IDisposableEnumerable<T> {
10
+ }
@@ -0,0 +1,18 @@
1
+ import { Enumerable } from '.';
2
+ declare global {
3
+ interface Map<K, V> {
4
+ asEnumerable(): Enumerable.IEnumerable<[K, V]>;
5
+ }
6
+ interface Array<T> {
7
+ asEnumerable(): Enumerable.IEnumerable<T>;
8
+ }
9
+ interface NamedNodeMap {
10
+ asEnumerable(): Enumerable.IEnumerable<Attr>;
11
+ }
12
+ interface NodeList {
13
+ asEnumerable(): Enumerable.IEnumerable<Node>;
14
+ }
15
+ interface HTMLCollection {
16
+ asEnumerable(): Enumerable.IEnumerable<Element>;
17
+ }
18
+ }
@@ -0,0 +1,13 @@
1
+ import { n as e, t } from "./src-D_Mk3oMP.js";
2
+ e(Array.prototype, "asEnumerable", function() {
3
+ return t.from(this);
4
+ }), e(Map.prototype, "asEnumerable", function() {
5
+ return t.from(this);
6
+ }), typeof document < "u" && (e(NamedNodeMap.prototype, "asEnumerable", function() {
7
+ return t.from(this);
8
+ }), e(NodeList.prototype, "asEnumerable", function() {
9
+ return t.from(this);
10
+ }), e(HTMLCollection.prototype, "asEnumerable", function() {
11
+ return t.from(this);
12
+ }));
13
+ //#endregion
@@ -0,0 +1,8 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Creates a sequence that randomly selects from a fixed set with replacement.
4
+ *
5
+ * @param values The candidate values.
6
+ * @returns An infinite deferred sequence, or an empty sequence when no values are supplied.
7
+ */
8
+ export declare function choice<T>(...values: T[]): IEnumerable<T>;
@@ -0,0 +1,8 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Creates a sequence that repeatedly emits a fixed set of values in order.
4
+ *
5
+ * @param values The values in each cycle.
6
+ * @returns An infinite deferred sequence, or an empty sequence when no values are supplied.
7
+ */
8
+ export declare function cycle<T>(...values: T[]): IEnumerable<T>;
@@ -0,0 +1,8 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Defers creation of a sequence until enumeration begins.
4
+ *
5
+ * @param factory Creates the sequence used by each enumeration.
6
+ * @returns A deferred sequence that invokes `factory` once per enumeration.
7
+ */
8
+ export declare function defer<T>(factory: () => IEnumerable<T>): IEnumerable<T>;
@@ -0,0 +1,3 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /** @returns A reusable sequence containing no elements. */
3
+ export declare function empty<T>(): IEnumerable<T>;
@@ -0,0 +1,46 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /** @returns An empty sequence. */
3
+ export declare function from(): IEnumerable<unknown>;
4
+ /**
5
+ * Wraps a number as a single-element sequence.
6
+ *
7
+ * @param source The number to wrap.
8
+ * @returns A sequence containing `source`.
9
+ */
10
+ export declare function from(source: number): IEnumerable<number>;
11
+ /**
12
+ * Wraps a boolean as a single-element sequence.
13
+ *
14
+ * @param source The boolean to wrap.
15
+ * @returns A sequence containing `source`.
16
+ */
17
+ export declare function from(source: boolean): IEnumerable<boolean>;
18
+ /**
19
+ * Enumerates the characters in a string.
20
+ *
21
+ * @param source The string to enumerate.
22
+ * @returns A reusable sequence of Unicode code-point strings.
23
+ */
24
+ export declare function from(source: string): IEnumerable<string>;
25
+ /**
26
+ * Converts an iterable, iterator, array-like object, or source factory to a linqx sequence.
27
+ *
28
+ * A source factory is called once per enumeration. A bare iterator is forward-only and is not
29
+ * reset between enumerations.
30
+ *
31
+ * @param source The source to adapt or a function that creates one.
32
+ * @returns A sequence over the source values.
33
+ */
34
+ export declare function from<T>(source: Iterable<T> | Iterator<T> | ArrayLike<T> | (() => Iterable<T> | Iterator<T>)): IEnumerable<T>;
35
+ /**
36
+ * Enumerates an object's own enumerable string-keyed, non-function properties.
37
+ *
38
+ * @param source The object whose properties will be enumerated.
39
+ * @returns A deferred sequence of key-value entries.
40
+ */
41
+ export declare function from<TKey extends PropertyKey, TValue>(source: Record<TKey, TValue>): IEnumerable<{
42
+ /** The property's key. */
43
+ key: TKey;
44
+ /** The property's value. */
45
+ value: TValue;
46
+ }>;
@@ -0,0 +1,9 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Generates elements by repeatedly invoking a function.
4
+ *
5
+ * @param func Produces the next element.
6
+ * @param count The number of elements to produce. Omit it for an infinite sequence.
7
+ * @returns A deferred generated sequence.
8
+ */
9
+ export declare function generate<T>(func: () => T, count?: number): IEnumerable<T>;
@@ -0,0 +1,8 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Creates a sequence containing exactly one element.
4
+ *
5
+ * @param element The element to contain.
6
+ * @returns A reusable single-element sequence.
7
+ */
8
+ export declare function make<T>(element: T): IEnumerable<T>;
@@ -0,0 +1,14 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Enumerates every regular-expression match in a string.
4
+ *
5
+ * A cloned expression is made global automatically, so the supplied `RegExp.lastIndex` is not
6
+ * read or modified.
7
+ *
8
+ * @param input The string to search.
9
+ * @param pattern A regular expression or pattern string.
10
+ * @param flags Flags used only when `pattern` is a string; `g` is added when absent.
11
+ * @returns A deferred sequence of regular-expression match arrays.
12
+ * @throws {SyntaxError} When a pattern string or its flags are invalid.
13
+ */
14
+ export declare function matches<T extends RegExpMatchArray = RegExpMatchArray>(input: string, pattern: RegExp | string, flags?: string): IEnumerable<T>;
@@ -0,0 +1,10 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Creates a counted descending arithmetic sequence.
4
+ *
5
+ * @param start The first value.
6
+ * @param count The number of values; non-positive values produce an empty sequence.
7
+ * @param step The absolute decrement between consecutive values; defaults to one.
8
+ * @returns A deferred descending numeric sequence.
9
+ */
10
+ export declare function rangeDown(start: number, count: number, step?: number): IEnumerable<number>;
@@ -0,0 +1,12 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Creates an arithmetic sequence between two inclusive endpoints.
4
+ *
5
+ * The direction is inferred from the endpoints and the absolute value of `step` is used.
6
+ *
7
+ * @param start The first value.
8
+ * @param to The inclusive endpoint.
9
+ * @param step The non-zero distance between consecutive values; defaults to one.
10
+ * @returns A deferred numeric sequence.
11
+ */
12
+ export declare function rangeTo(start: number, to: number, step?: number): IEnumerable<number>;
@@ -0,0 +1,10 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Creates a counted arithmetic sequence.
4
+ *
5
+ * @param start The first value.
6
+ * @param count The number of values; non-positive values produce an empty sequence.
7
+ * @param step The difference between consecutive values; defaults to one.
8
+ * @returns A deferred numeric sequence.
9
+ */
10
+ export declare function range(start: number, count: number, step?: number): IEnumerable<number>;
@@ -0,0 +1,9 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Initializes one value, repeats it indefinitely, and finalizes it when enumeration stops.
4
+ *
5
+ * @param initializer Creates the value once per enumeration.
6
+ * @param finalizer Releases the value after completion, failure, or early termination.
7
+ * @returns An infinite deferred sequence with deterministic finalization.
8
+ */
9
+ export declare function repeatWithFinalize<T>(initializer: () => T, finalizer: (element: T) => void): IEnumerable<T>;
@@ -0,0 +1,9 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Repeats one element.
4
+ *
5
+ * @param element The value to repeat.
6
+ * @param count The number of repetitions. Omit it for an infinite sequence.
7
+ * @returns A deferred repeated sequence.
8
+ */
9
+ export declare function repeat<T>(element: T, count?: number): IEnumerable<T>;
@@ -0,0 +1,9 @@
1
+ import type { IEnumerable } from '../types.js';
2
+ /**
3
+ * Creates an infinite ascending arithmetic sequence.
4
+ *
5
+ * @param start The first value; defaults to zero.
6
+ * @param step The amount added after each element; defaults to one.
7
+ * @returns An infinite deferred numeric sequence.
8
+ */
9
+ export declare function toInfinity(start?: number, step?: number): IEnumerable<number>;