iterable-linq-utility 0.0.7 → 0.0.9
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/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type ILinqIterable } from "./linqIterable";
|
|
1
|
+
import { LinqIterableWrapper, type ILinqIterable } from "./linqIterable";
|
|
2
2
|
export declare function from<T>(iterable: Iterable<T>): ILinqIterable<T>;
|
|
3
|
-
export { ILinqIterable };
|
|
3
|
+
export { ILinqIterable, LinqIterableWrapper };
|
|
@@ -1,44 +1,47 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
function
|
|
5
|
-
return (r,
|
|
1
|
+
var w = Object.defineProperty;
|
|
2
|
+
var b = (e, t, r) => t in e ? w(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var n = (e, t, r) => (b(e, typeof t != "symbol" ? t + "" : t, r), r);
|
|
4
|
+
function y(e, t) {
|
|
5
|
+
return (r, i) => t(e(r, i), i);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
return (r,
|
|
7
|
+
function p(e, t) {
|
|
8
|
+
return (r, i) => e(r, i) && t(r, i);
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function z(e, t) {
|
|
11
11
|
return {
|
|
12
12
|
done: e,
|
|
13
13
|
value: t
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function S() {
|
|
17
17
|
return { done: !0, value: void 0 };
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return
|
|
19
|
+
function k(e) {
|
|
20
|
+
return typeof e == "function";
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
function M(e, t) {
|
|
23
|
+
return new f(e, t);
|
|
24
|
+
}
|
|
25
|
+
class f {
|
|
23
26
|
constructor(t, r) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
if (
|
|
28
|
-
const u =
|
|
29
|
-
|
|
27
|
+
n(this, "predicate");
|
|
28
|
+
n(this, "source");
|
|
29
|
+
let i = r, s = t;
|
|
30
|
+
if (s instanceof f) {
|
|
31
|
+
const u = s.predicate;
|
|
32
|
+
s = s.source, i = p(u, i);
|
|
30
33
|
}
|
|
31
|
-
this.source =
|
|
34
|
+
this.source = s, this.predicate = i;
|
|
32
35
|
}
|
|
33
36
|
[Symbol.iterator]() {
|
|
34
|
-
return new
|
|
37
|
+
return new L(this.source, this.predicate);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
class
|
|
40
|
+
class L {
|
|
38
41
|
constructor(t, r) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
n(this, "index", 0);
|
|
43
|
+
n(this, "sourceIterator");
|
|
44
|
+
n(this, "predicate");
|
|
42
45
|
this.sourceIterator = t[Symbol.iterator](), this.predicate = r;
|
|
43
46
|
}
|
|
44
47
|
next() {
|
|
@@ -49,60 +52,60 @@ class S {
|
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
|
-
function
|
|
53
|
-
return new
|
|
55
|
+
function v(e, t) {
|
|
56
|
+
return new m(e, t);
|
|
54
57
|
}
|
|
55
|
-
class
|
|
58
|
+
class m {
|
|
56
59
|
constructor(t, r) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let
|
|
60
|
-
if (
|
|
61
|
-
const u =
|
|
62
|
-
|
|
60
|
+
n(this, "mapper");
|
|
61
|
+
n(this, "source");
|
|
62
|
+
let i = r, s = t;
|
|
63
|
+
if (s instanceof m) {
|
|
64
|
+
const u = s.mapper;
|
|
65
|
+
s = s.source, i = y(u, i);
|
|
63
66
|
}
|
|
64
|
-
this.source = t, this.mapper =
|
|
67
|
+
this.source = t, this.mapper = i;
|
|
65
68
|
}
|
|
66
69
|
[Symbol.iterator]() {
|
|
67
|
-
return new
|
|
70
|
+
return new N(this.source, this.mapper);
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
|
-
class
|
|
73
|
+
class N {
|
|
71
74
|
constructor(t, r) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
n(this, "index", 0);
|
|
76
|
+
n(this, "sourceIterator");
|
|
77
|
+
n(this, "mapper");
|
|
75
78
|
this.sourceIterator = t[Symbol.iterator](), this.mapper = r;
|
|
76
79
|
}
|
|
77
80
|
next() {
|
|
78
81
|
const t = this.sourceIterator.next();
|
|
79
|
-
return t.done !== !0 ?
|
|
82
|
+
return t.done !== !0 ? z(!1, this.mapper(t.value, this.index++)) : S();
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
|
-
function
|
|
83
|
-
const t = e[Symbol.iterator](), r = new
|
|
84
|
-
for (let
|
|
85
|
-
r.addLast(
|
|
85
|
+
function A(e) {
|
|
86
|
+
const t = e[Symbol.iterator](), r = new h();
|
|
87
|
+
for (let i = t.next(); i.done !== !0; i = t.next())
|
|
88
|
+
r.addLast(i.value);
|
|
86
89
|
return r;
|
|
87
90
|
}
|
|
88
|
-
class
|
|
91
|
+
class F {
|
|
89
92
|
constructor(t = null) {
|
|
90
|
-
|
|
93
|
+
n(this, "current", null);
|
|
91
94
|
this.current = t;
|
|
92
95
|
}
|
|
93
96
|
next() {
|
|
94
97
|
const t = this.current;
|
|
95
|
-
return t === null ?
|
|
98
|
+
return t === null ? S() : (this.current = t.nextNode, z(!1, t.data));
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
|
-
class
|
|
101
|
+
class h {
|
|
99
102
|
constructor() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
n(this, "internalSize", 0);
|
|
104
|
+
n(this, "head", null);
|
|
105
|
+
n(this, "tail", null);
|
|
103
106
|
}
|
|
104
107
|
[Symbol.iterator]() {
|
|
105
|
-
return new
|
|
108
|
+
return new F(this.head);
|
|
106
109
|
}
|
|
107
110
|
addFirst(t) {
|
|
108
111
|
const r = {
|
|
@@ -136,54 +139,54 @@ class a {
|
|
|
136
139
|
return this.internalSize;
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
|
-
function
|
|
140
|
-
return e instanceof
|
|
142
|
+
function g(e) {
|
|
143
|
+
return e instanceof I ? e : new I(e);
|
|
141
144
|
}
|
|
142
|
-
class
|
|
145
|
+
class I {
|
|
143
146
|
constructor(t) {
|
|
144
|
-
|
|
145
|
-
if (t instanceof
|
|
147
|
+
n(this, "source");
|
|
148
|
+
if (t instanceof h) {
|
|
146
149
|
this.source = t;
|
|
147
150
|
return;
|
|
148
151
|
}
|
|
149
|
-
this.source =
|
|
152
|
+
this.source = A(t);
|
|
150
153
|
}
|
|
151
154
|
[Symbol.iterator]() {
|
|
152
|
-
return new
|
|
155
|
+
return new P(this.source);
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
|
-
class
|
|
158
|
+
class P {
|
|
156
159
|
constructor(t) {
|
|
157
|
-
|
|
160
|
+
n(this, "sourceIterator");
|
|
158
161
|
this.sourceIterator = t[Symbol.iterator]();
|
|
159
162
|
}
|
|
160
163
|
next() {
|
|
161
164
|
return this.sourceIterator.next();
|
|
162
165
|
}
|
|
163
166
|
}
|
|
164
|
-
function
|
|
165
|
-
return e instanceof
|
|
167
|
+
function R(e) {
|
|
168
|
+
return e instanceof x ? e : new x(e);
|
|
166
169
|
}
|
|
167
|
-
class
|
|
170
|
+
class x {
|
|
168
171
|
constructor(t) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.source = t, this.sourceIterator = t[Symbol.iterator](), t instanceof
|
|
172
|
+
n(this, "isMemoized", !1);
|
|
173
|
+
n(this, "sourceIterator");
|
|
174
|
+
n(this, "linkedList", new h());
|
|
175
|
+
n(this, "source");
|
|
176
|
+
this.source = t, this.sourceIterator = t[Symbol.iterator](), t instanceof h && (this.linkedList = t, this.isMemoized = !0);
|
|
174
177
|
}
|
|
175
178
|
[Symbol.iterator]() {
|
|
176
|
-
return this.isMemoized ? new
|
|
179
|
+
return this.isMemoized ? new T(this.linkedList) : new D(this.sourceIterator, this.linkedList, (t) => this.isMemoized = t.done === !0);
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
|
-
class
|
|
180
|
-
constructor(t, r,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this.linkedList = r, this.linkedListIterator = r[Symbol.iterator](), this.setAsMemoized =
|
|
182
|
+
class D {
|
|
183
|
+
constructor(t, r, i) {
|
|
184
|
+
n(this, "index", 0);
|
|
185
|
+
n(this, "linkedList");
|
|
186
|
+
n(this, "linkedListIterator");
|
|
187
|
+
n(this, "setAsMemoized");
|
|
188
|
+
n(this, "sourceIterator");
|
|
189
|
+
this.linkedList = r, this.linkedListIterator = r[Symbol.iterator](), this.setAsMemoized = i, this.sourceIterator = t;
|
|
187
190
|
}
|
|
188
191
|
next() {
|
|
189
192
|
if (this.linkedList.size() > this.index++)
|
|
@@ -192,26 +195,41 @@ class A {
|
|
|
192
195
|
return this.setAsMemoized(t) || this.linkedList.addLast(t.value), t;
|
|
193
196
|
}
|
|
194
197
|
}
|
|
195
|
-
class
|
|
198
|
+
class T {
|
|
196
199
|
constructor(t) {
|
|
197
|
-
|
|
200
|
+
n(this, "memoizedSourceIterator");
|
|
198
201
|
this.memoizedSourceIterator = t[Symbol.iterator]();
|
|
199
202
|
}
|
|
200
203
|
next() {
|
|
201
204
|
return this.memoizedSourceIterator.next();
|
|
202
205
|
}
|
|
203
206
|
}
|
|
204
|
-
function
|
|
207
|
+
function $(e, t) {
|
|
208
|
+
const r = e[Symbol.iterator]();
|
|
209
|
+
let i = r.next(), s = i.value, u = null;
|
|
210
|
+
for (t == null ? u = (o, a) => o < a ? -1 : o === a ? 0 : 1 : k(t) ? u = t : Array.isArray(t) ? u = (o, a) => {
|
|
211
|
+
let d = 0;
|
|
212
|
+
for (const l of t)
|
|
213
|
+
if (d = o[l] < a[l] ? -1 : o[l] === a[l] ? 0 : 1, d !== 0)
|
|
214
|
+
break;
|
|
215
|
+
return d;
|
|
216
|
+
} : u = (o, a) => o[t] < a[t] ? -1 : o[t] === a[t] ? 0 : 1, i = r.next(); i.done !== !0; i = r.next()) {
|
|
217
|
+
const o = u(s, i.value);
|
|
218
|
+
s = o < 0 || o === 0 ? s : i.value;
|
|
219
|
+
}
|
|
220
|
+
return s == null ? null : s;
|
|
221
|
+
}
|
|
222
|
+
function j(e, t) {
|
|
205
223
|
const r = e[Symbol.iterator]();
|
|
206
|
-
let
|
|
207
|
-
for (let
|
|
208
|
-
if (t(
|
|
224
|
+
let i = 0;
|
|
225
|
+
for (let s = r.next(); s.done !== !0; s = r.next())
|
|
226
|
+
if (t(s.value, i++))
|
|
209
227
|
return !0;
|
|
210
228
|
return !1;
|
|
211
229
|
}
|
|
212
|
-
class
|
|
230
|
+
class c {
|
|
213
231
|
constructor(t) {
|
|
214
|
-
|
|
232
|
+
n(this, "iterable");
|
|
215
233
|
this.iterable = t;
|
|
216
234
|
}
|
|
217
235
|
[Symbol.iterator]() {
|
|
@@ -221,24 +239,28 @@ class o {
|
|
|
221
239
|
return [...this.iterable];
|
|
222
240
|
}
|
|
223
241
|
filter(t) {
|
|
224
|
-
return new
|
|
242
|
+
return new c(M(this.iterable, t));
|
|
225
243
|
}
|
|
226
244
|
map(t) {
|
|
227
|
-
return new
|
|
245
|
+
return new c(v(this.iterable, t));
|
|
228
246
|
}
|
|
229
247
|
materialize() {
|
|
230
|
-
return new
|
|
248
|
+
return new c(g(this.iterable));
|
|
231
249
|
}
|
|
232
250
|
memoize() {
|
|
233
|
-
return new
|
|
251
|
+
return new c(R(this.iterable));
|
|
252
|
+
}
|
|
253
|
+
min(t) {
|
|
254
|
+
return $(this.iterable, t);
|
|
234
255
|
}
|
|
235
256
|
some(t) {
|
|
236
|
-
return
|
|
257
|
+
return j(this.iterable, t);
|
|
237
258
|
}
|
|
238
259
|
}
|
|
239
|
-
function
|
|
240
|
-
return new
|
|
260
|
+
function C(e) {
|
|
261
|
+
return new c(e);
|
|
241
262
|
}
|
|
242
263
|
export {
|
|
243
|
-
|
|
264
|
+
c as LinqIterableWrapper,
|
|
265
|
+
C as from
|
|
244
266
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(o,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(o=typeof globalThis<"u"?globalThis:o||self,u(o["interable-linq-utility"]={}))})(this,function(o){"use strict";var $=Object.defineProperty;var B=(o,u,d)=>u in o?$(o,u,{enumerable:!0,configurable:!0,writable:!0,value:d}):o[u]=d;var n=(o,u,d)=>(B(o,typeof u!="symbol"?u+"":u,d),d);function u(e,t){return(r,i)=>t(e(r,i),i)}function d(e,t){return(r,i)=>e(r,i)&&t(r,i)}function S(e,t){return{done:e,value:t}}function b(){return{done:!0,value:void 0}}function C(e){return e}function w(e){return typeof e=="function"}function M(e,t){return new I(e,t)}class I{constructor(t,r){n(this,"predicate");n(this,"source");let i=r,s=t;if(s instanceof I){const l=s.predicate;s=s.source,i=d(l,i)}this.source=s,this.predicate=i}[Symbol.iterator](){return new k(this.source,this.predicate)}}class k{constructor(t,r){n(this,"index",0);n(this,"sourceIterator");n(this,"predicate");this.sourceIterator=t[Symbol.iterator](),this.predicate=r}next(){for(;;){const t=this.sourceIterator.next();if(t.done===!0||this.predicate(t.value,this.index++))return t}}}function L(e,t){return new x(e,t)}class x{constructor(t,r){n(this,"mapper");n(this,"source");let i=r,s=t;if(s instanceof x){const l=s.mapper;s=s.source,i=u(l,i)}this.source=t,this.mapper=i}[Symbol.iterator](){return new v(this.source,this.mapper)}}class v{constructor(t,r){n(this,"index",0);n(this,"sourceIterator");n(this,"mapper");this.sourceIterator=t[Symbol.iterator](),this.mapper=r}next(){const t=this.sourceIterator.next();return t.done!==!0?S(!1,this.mapper(t.value,this.index++)):b()}}function N(e){const t=e[Symbol.iterator](),r=new f;for(let i=t.next();i.done!==!0;i=t.next())r.addLast(i.value);return r}class A{constructor(t=null){n(this,"current",null);this.current=t}next(){const t=this.current;return t===null?b():(this.current=t.nextNode,S(!1,t.data))}}class f{constructor(){n(this,"internalSize",0);n(this,"head",null);n(this,"tail",null)}[Symbol.iterator](){return new A(this.head)}addFirst(t){const r={data:t,nextNode:null};switch(this.internalSize){case 0:this.head=r,this.tail=r;break;default:r.nextNode=this.head,this.head=r}return this.internalSize++,this}addLast(t){const r={data:t,nextNode:null};switch(this.internalSize){case 0:this.head=r,this.tail=r;break;default:this.tail.nextNode=r,this.tail=r}return this.internalSize++,this}size(){return this.internalSize}}function g(e){return e instanceof p?e:new p(e)}class p{constructor(t){n(this,"source");if(t instanceof f){this.source=t;return}this.source=N(t)}[Symbol.iterator](){return new F(this.source)}}class F{constructor(t){n(this,"sourceIterator");this.sourceIterator=t[Symbol.iterator]()}next(){return this.sourceIterator.next()}}function P(e){return e instanceof y?e:new y(e)}class y{constructor(t){n(this,"isMemoized",!1);n(this,"sourceIterator");n(this,"linkedList",new f);n(this,"source");this.source=t,this.sourceIterator=t[Symbol.iterator](),t instanceof f&&(this.linkedList=t,this.isMemoized=!0)}[Symbol.iterator](){return this.isMemoized?new R(this.linkedList):new T(this.sourceIterator,this.linkedList,t=>this.isMemoized=t.done===!0)}}class T{constructor(t,r,i){n(this,"index",0);n(this,"linkedList");n(this,"linkedListIterator");n(this,"setAsMemoized");n(this,"sourceIterator");this.linkedList=r,this.linkedListIterator=r[Symbol.iterator](),this.setAsMemoized=i,this.sourceIterator=t}next(){if(this.linkedList.size()>this.index++)return this.linkedListIterator.next();const t=this.sourceIterator.next();return this.setAsMemoized(t)||this.linkedList.addLast(t.value),t}}class R{constructor(t){n(this,"memoizedSourceIterator");this.memoizedSourceIterator=t[Symbol.iterator]()}next(){return this.memoizedSourceIterator.next()}}function j(e,t){const r=e[Symbol.iterator]();let i=r.next(),s=i.value,l=null;for(t==null?l=(a,c)=>a<c?-1:a===c?0:1:w(t)?l=t:Array.isArray(t)?l=(a,c)=>{let z=0;for(const m of t)if(z=a[m]<c[m]?-1:a[m]===c[m]?0:1,z!==0)break;return z}:l=(a,c)=>a[t]<c[t]?-1:a[t]===c[t]?0:1,i=r.next();i.done!==!0;i=r.next()){const a=l(s,i.value);s=a<0||a===0?s:i.value}return s==null?null:s}function D(e,t){const r=e[Symbol.iterator]();let i=0;for(let s=r.next();s.done!==!0;s=r.next())if(t(s.value,i++))return!0;return!1}class h{constructor(t){n(this,"iterable");this.iterable=t}[Symbol.iterator](){return this.iterable[Symbol.iterator]()}collectToArray(){return[...this.iterable]}filter(t){return new h(M(this.iterable,t))}map(t){return new h(L(this.iterable,t))}materialize(){return new h(g(this.iterable))}memoize(){return new h(P(this.iterable))}min(t){return j(this.iterable,t)}some(t){return D(this.iterable,t)}}function O(e){return new h(e)}o.LinqIterableWrapper=h,o.from=O,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/linqIterable.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Mapper, Predicate } from '@/types';
|
|
1
|
+
import { Comparer, Mapper, Predicate } from '@/types';
|
|
2
2
|
export interface ILinqIterable<T> {
|
|
3
3
|
[Symbol.iterator](): Iterator<T, any, undefined>;
|
|
4
4
|
collectToArray(): T[];
|
|
@@ -6,9 +6,10 @@ export interface ILinqIterable<T> {
|
|
|
6
6
|
map<R>(mapper: Mapper<T, R>): ILinqIterable<R>;
|
|
7
7
|
materialize(): ILinqIterable<T>;
|
|
8
8
|
memoize(): ILinqIterable<T>;
|
|
9
|
+
min(comparer?: Comparer<T>): T | null | undefined;
|
|
9
10
|
some(predicate: Predicate<T>): boolean;
|
|
10
11
|
}
|
|
11
|
-
export declare class
|
|
12
|
+
export declare class LinqIterableWrapper<T> implements ILinqIterable<T> {
|
|
12
13
|
constructor(iterable: Iterable<T>);
|
|
13
14
|
[Symbol.iterator](): Iterator<T, any, undefined>;
|
|
14
15
|
private iterable;
|
|
@@ -17,5 +18,6 @@ export declare class LinqIterable<T> implements ILinqIterable<T> {
|
|
|
17
18
|
map<R>(mapper: Mapper<T, R>): ILinqIterable<R>;
|
|
18
19
|
materialize(): ILinqIterable<T>;
|
|
19
20
|
memoize(): ILinqIterable<T>;
|
|
21
|
+
min(comparer?: Comparer<T>): T | null | undefined;
|
|
20
22
|
some(predicate: Predicate<T>): boolean;
|
|
21
23
|
}
|
package/dist/types/comparer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare type ComparerFunction<T> = (a: T, b: T
|
|
1
|
+
declare type ComparerFunction<T> = (a: T, b: T) => number;
|
|
2
2
|
declare type ComparingProps<T> = keyof T | Array<keyof T>;
|
|
3
3
|
export declare type Comparer<T> = ComparerFunction<T> | ComparingProps<T>;
|
|
4
4
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iterable-linq-utility",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "An Iterable mutation utility inspired by .net Linq and Javascript Array interface",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/interable-linq-utility.umd.cjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dev": "vite",
|
|
21
21
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --ignore-path .eslintignore",
|
|
22
22
|
"lint-fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix --ignore-path .eslintignore",
|
|
23
|
-
"test": "vitest",
|
|
23
|
+
"test": "vitest run",
|
|
24
24
|
"test:coverage": "vitest run --coverage",
|
|
25
25
|
"test:ui": "vitest --ui"
|
|
26
26
|
},
|