@limitlesspc/std 0.20.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.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/array.d.ts +209 -0
- package/dist/array.js +41 -0
- package/dist/async/index.d.ts +48 -0
- package/dist/async/index.js +155 -0
- package/dist/bytes.d.ts +38 -0
- package/dist/bytes.js +35 -0
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-C2DS6YRJ.js +1664 -0
- package/dist/chunk-DO4NH5XG.js +523 -0
- package/dist/chunk-EWSJTMH2.js +68 -0
- package/dist/chunk-ILLWUQPY.js +139 -0
- package/dist/chunk-LJSF3QBT.js +122 -0
- package/dist/chunk-MG5VQSTV.js +89 -0
- package/dist/chunk-TMLWLR46.js +12 -0
- package/dist/chunk-WBSY6KRH.js +358 -0
- package/dist/cmath/index.d.ts +57 -0
- package/dist/cmath/index.js +187 -0
- package/dist/cmp.d.ts +11 -0
- package/dist/cmp.js +12 -0
- package/dist/csv.d.ts +3 -0
- package/dist/csv.js +16 -0
- package/dist/easing.d.ts +37 -0
- package/dist/easing.js +157 -0
- package/dist/events.d.ts +20 -0
- package/dist/events.js +67 -0
- package/dist/fn/index.d.ts +66 -0
- package/dist/fn/index.js +25 -0
- package/dist/gfx/index.d.ts +13 -0
- package/dist/gfx/index.js +68 -0
- package/dist/iter/index.d.ts +226 -0
- package/dist/iter/index.js +65 -0
- package/dist/math/index.d.ts +463 -0
- package/dist/math/index.js +129 -0
- package/dist/object.d.ts +72 -0
- package/dist/object.js +24 -0
- package/dist/random.d.ts +68 -0
- package/dist/random.js +22 -0
- package/dist/string/index.d.ts +62 -0
- package/dist/string/index.js +98 -0
- package/dist/structs/index.d.ts +184 -0
- package/dist/structs/index.js +24 -0
- package/dist/time/index.d.ts +35 -0
- package/dist/time/index.js +84 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.js +1 -0
- package/dist/vec3-D7Wuy2AZ.d.ts +70 -0
- package/package.json +111 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// src/object.ts
|
|
2
|
+
var hasOwn = (obj, key) => Object.hasOwn(obj, key);
|
|
3
|
+
function shallowEquals(a, b) {
|
|
4
|
+
if (a === b) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
for (const key in a) {
|
|
8
|
+
if (hasOwn(a, key) && !hasOwn(b, key)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
for (const key in b) {
|
|
13
|
+
if (hasOwn(b, key) && !hasOwn(a, key)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
function deepEquals(a, b) {
|
|
20
|
+
if (a === b) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if (a == null || b == null) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (a.constructor !== b.constructor) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
for (const key in a) {
|
|
30
|
+
if (hasOwn(a, key)) {
|
|
31
|
+
if (!hasOwn(b, key)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (a[key] === b[key]) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (typeof a[key] !== "object") {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (!deepEquals(a[key], b[key])) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const key in b) {
|
|
46
|
+
if (hasOwn(b, key)) {
|
|
47
|
+
if (!hasOwn(a, key)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (a[key] === b[key]) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (typeof b[key] !== "object") {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (!deepEquals(a[key], b[key])) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
var objectKeys = Object.keys;
|
|
64
|
+
var objectEntries = Object.entries;
|
|
65
|
+
var objectFromEntries = Object.fromEntries;
|
|
66
|
+
function value2Keys(obj) {
|
|
67
|
+
const result = {};
|
|
68
|
+
for (const [key, iter] of objectEntries(obj)) {
|
|
69
|
+
for (const v of iter) {
|
|
70
|
+
result[v] ||= [];
|
|
71
|
+
result[v].push(key);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
function objectMap(obj, fn) {
|
|
77
|
+
return objectFromEntries(
|
|
78
|
+
// @ts-expect-error have to nudge the type system here
|
|
79
|
+
objectEntries(obj).map(([key, value]) => [key, fn([key, value])])
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
function deepCopy(object) {
|
|
83
|
+
if (object == null) {
|
|
84
|
+
return object;
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(object)) {
|
|
87
|
+
return object.map(deepCopy);
|
|
88
|
+
}
|
|
89
|
+
if (typeof object !== "object") {
|
|
90
|
+
return object;
|
|
91
|
+
}
|
|
92
|
+
const copy = Object.create(Object.getPrototypeOf(object));
|
|
93
|
+
for (const key in object) {
|
|
94
|
+
if (hasOwn(object, key)) {
|
|
95
|
+
copy[key] = deepCopy(object[key]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return copy;
|
|
99
|
+
}
|
|
100
|
+
function pickByKeys(object, keys) {
|
|
101
|
+
if (Array.isArray(keys)) {
|
|
102
|
+
const result = {};
|
|
103
|
+
for (const key of keys) {
|
|
104
|
+
result[key] = object[key];
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
return object[keys];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export {
|
|
112
|
+
hasOwn,
|
|
113
|
+
shallowEquals,
|
|
114
|
+
deepEquals,
|
|
115
|
+
objectKeys,
|
|
116
|
+
objectEntries,
|
|
117
|
+
objectFromEntries,
|
|
118
|
+
value2Keys,
|
|
119
|
+
objectMap,
|
|
120
|
+
deepCopy,
|
|
121
|
+
pickByKeys
|
|
122
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/fn/pipe.ts
|
|
2
|
+
var pipe = (x, ...fns) => fns.reduce((x2, fn) => fn(x2), x);
|
|
3
|
+
var asyncPipe = async (x, ...fns) => {
|
|
4
|
+
for (const fn of fns) {
|
|
5
|
+
x = fn(await x);
|
|
6
|
+
}
|
|
7
|
+
return x;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/fn/reverse-curry.ts
|
|
11
|
+
var reverseCurry = (fn) => (
|
|
12
|
+
// @ts-expect-error funky type maneuvering
|
|
13
|
+
(...args) => {
|
|
14
|
+
if (args.length === fn.length) {
|
|
15
|
+
return fn(...args);
|
|
16
|
+
}
|
|
17
|
+
return (first) => fn(first, ...args);
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
// src/fn/index.ts
|
|
22
|
+
var noop = () => {
|
|
23
|
+
};
|
|
24
|
+
var identity = (x) => x;
|
|
25
|
+
var constant = (x) => () => x;
|
|
26
|
+
function once(fn) {
|
|
27
|
+
let called = false;
|
|
28
|
+
let result;
|
|
29
|
+
return () => {
|
|
30
|
+
if (called) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
result = fn();
|
|
34
|
+
called = true;
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function memoize(func) {
|
|
39
|
+
const cache = /* @__PURE__ */ new Map();
|
|
40
|
+
return (arg) => {
|
|
41
|
+
if (cache.has(arg)) {
|
|
42
|
+
return cache.get(arg);
|
|
43
|
+
}
|
|
44
|
+
const output = func(arg);
|
|
45
|
+
cache.set(arg, output);
|
|
46
|
+
return output;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function memo(fn) {
|
|
50
|
+
let cache;
|
|
51
|
+
let called = false;
|
|
52
|
+
const memoized = () => {
|
|
53
|
+
if (called) {
|
|
54
|
+
return cache;
|
|
55
|
+
}
|
|
56
|
+
cache = fn();
|
|
57
|
+
called = true;
|
|
58
|
+
return cache;
|
|
59
|
+
};
|
|
60
|
+
memoized.invalidate = () => called = false;
|
|
61
|
+
return memoized;
|
|
62
|
+
}
|
|
63
|
+
function ttlCache(fn, ttl) {
|
|
64
|
+
let cache;
|
|
65
|
+
let called = false;
|
|
66
|
+
let lastCalled = performance.now();
|
|
67
|
+
return () => {
|
|
68
|
+
if (called && performance.now() - lastCalled < ttl) {
|
|
69
|
+
return cache;
|
|
70
|
+
}
|
|
71
|
+
cache = fn();
|
|
72
|
+
called = true;
|
|
73
|
+
lastCalled = performance.now();
|
|
74
|
+
return cache;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
pipe,
|
|
80
|
+
asyncPipe,
|
|
81
|
+
reverseCurry,
|
|
82
|
+
noop,
|
|
83
|
+
identity,
|
|
84
|
+
constant,
|
|
85
|
+
once,
|
|
86
|
+
memoize,
|
|
87
|
+
memo,
|
|
88
|
+
ttlCache
|
|
89
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/cmp.ts
|
|
2
|
+
var ascend = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
3
|
+
var descend = (a, b) => -ascend(a, b);
|
|
4
|
+
var ascendBy = (f) => (a, b) => ascend(f(a), f(b));
|
|
5
|
+
var descendBy = (f) => (a, b) => descend(f(a), f(b));
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
ascend,
|
|
9
|
+
descend,
|
|
10
|
+
ascendBy,
|
|
11
|
+
descendBy
|
|
12
|
+
};
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import {
|
|
2
|
+
reverseCurry
|
|
3
|
+
} from "./chunk-MG5VQSTV.js";
|
|
4
|
+
import {
|
|
5
|
+
pickByKeys
|
|
6
|
+
} from "./chunk-LJSF3QBT.js";
|
|
7
|
+
|
|
8
|
+
// src/iter/associate-by.ts
|
|
9
|
+
var associateBy = reverseCurry(
|
|
10
|
+
(array, key) => {
|
|
11
|
+
const map3 = /* @__PURE__ */ new Map();
|
|
12
|
+
for (const item of array) {
|
|
13
|
+
map3[item[key]] = item;
|
|
14
|
+
}
|
|
15
|
+
return map3;
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// src/iter/chain.ts
|
|
20
|
+
function* chain(...iterables) {
|
|
21
|
+
for (const iterable of iterables) {
|
|
22
|
+
yield* iterable;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/iter/chunk.ts
|
|
27
|
+
var chunk = reverseCurry(function* chunk2(iter, size) {
|
|
28
|
+
let result = [];
|
|
29
|
+
for (const value of iter) {
|
|
30
|
+
result.push(value);
|
|
31
|
+
if (result.length === size) {
|
|
32
|
+
yield result;
|
|
33
|
+
result = [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (result.length) {
|
|
37
|
+
yield result;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// src/iter/collect.ts
|
|
42
|
+
function collect(iter) {
|
|
43
|
+
return [...iter];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/iter/count.ts
|
|
47
|
+
function count(iter) {
|
|
48
|
+
let count2 = 0;
|
|
49
|
+
for (const _ of iter) {
|
|
50
|
+
count2++;
|
|
51
|
+
}
|
|
52
|
+
return count2;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/iter/cycle.ts
|
|
56
|
+
function* cycle(iter) {
|
|
57
|
+
const values = [];
|
|
58
|
+
for (const value of iter) {
|
|
59
|
+
yield value;
|
|
60
|
+
values.push(value);
|
|
61
|
+
}
|
|
62
|
+
while (values.length) {
|
|
63
|
+
for (const value of values) {
|
|
64
|
+
yield value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/iter/enumerate.ts
|
|
70
|
+
function* enumerate(iter) {
|
|
71
|
+
let i = 0;
|
|
72
|
+
for (const value of iter) {
|
|
73
|
+
yield [i++, value];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/iter/every.ts
|
|
78
|
+
var every = reverseCurry((iter, predicate) => {
|
|
79
|
+
for (const item of iter) {
|
|
80
|
+
if (!predicate(item)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// src/iter/filter.ts
|
|
88
|
+
var filter = reverseCurry(function* filter2(iter, predicate) {
|
|
89
|
+
for (const value of iter) {
|
|
90
|
+
if (predicate(value)) {
|
|
91
|
+
yield value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
var filterByKey = reverseCurry(function* filterByKey2(iter, key) {
|
|
96
|
+
for (const value of iter) {
|
|
97
|
+
if (value[key]) {
|
|
98
|
+
yield value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// src/iter/first.ts
|
|
104
|
+
function first(iter) {
|
|
105
|
+
const result = iter[Symbol.iterator]().next();
|
|
106
|
+
if (!result.done) {
|
|
107
|
+
return result.value;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/iter/group-by.ts
|
|
112
|
+
var groupBy = reverseCurry(
|
|
113
|
+
(array, key) => {
|
|
114
|
+
const groups = /* @__PURE__ */ new Map();
|
|
115
|
+
for (const item of array) {
|
|
116
|
+
const value = item[key];
|
|
117
|
+
const group = groups.get(value);
|
|
118
|
+
if (group) {
|
|
119
|
+
group.push(item);
|
|
120
|
+
} else {
|
|
121
|
+
groups.set(value, [item]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return groups;
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// src/iter/intersperse.ts
|
|
129
|
+
var intersperse = reverseCurry(function* intersperse2(iter, separator) {
|
|
130
|
+
let first2 = true;
|
|
131
|
+
for (const value of iter) {
|
|
132
|
+
if (first2) {
|
|
133
|
+
first2 = false;
|
|
134
|
+
} else {
|
|
135
|
+
yield separator;
|
|
136
|
+
}
|
|
137
|
+
yield value;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// src/iter/last.ts
|
|
142
|
+
function last(iter) {
|
|
143
|
+
let last2;
|
|
144
|
+
for (const value of iter) {
|
|
145
|
+
last2 = value;
|
|
146
|
+
}
|
|
147
|
+
return last2;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/iter/map.ts
|
|
151
|
+
var map = reverseCurry(function* map2(iter, fn) {
|
|
152
|
+
for (const item of iter) {
|
|
153
|
+
yield fn(item);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// src/iter/nth.ts
|
|
158
|
+
var nth = reverseCurry((iter, n) => {
|
|
159
|
+
let i = 0;
|
|
160
|
+
for (const value of iter) {
|
|
161
|
+
if (i++ === n) {
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// src/iter/partition.ts
|
|
168
|
+
var partition = reverseCurry(
|
|
169
|
+
(iter, predicate) => {
|
|
170
|
+
const pass = [];
|
|
171
|
+
const fail = [];
|
|
172
|
+
for (const item of iter) {
|
|
173
|
+
if (predicate(item)) {
|
|
174
|
+
pass.push(item);
|
|
175
|
+
} else {
|
|
176
|
+
fail.push(item);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return [pass, fail];
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
// src/iter/pick.ts
|
|
184
|
+
var pick = reverseCurry(function* pick2(iter, keys) {
|
|
185
|
+
if (Array.isArray(keys)) {
|
|
186
|
+
for (const item of iter) {
|
|
187
|
+
yield pickByKeys(item, keys);
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
for (const item of iter) {
|
|
191
|
+
yield item[keys];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// src/iter/range.ts
|
|
197
|
+
function* range(min, max, step = 1) {
|
|
198
|
+
if (max === void 0) {
|
|
199
|
+
yield* range(0, min);
|
|
200
|
+
} else {
|
|
201
|
+
const absStep = Math.abs(step);
|
|
202
|
+
if (max > min) {
|
|
203
|
+
for (let i = min; i < max; i += absStep) {
|
|
204
|
+
yield i;
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
for (let i = min; i > max; i -= absStep) {
|
|
208
|
+
yield i;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/iter/skip.ts
|
|
215
|
+
var skip = reverseCurry(function* skip2(iter, n) {
|
|
216
|
+
let count2 = 0;
|
|
217
|
+
for (const value of iter) {
|
|
218
|
+
if (++count2 > n) {
|
|
219
|
+
yield value;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// src/iter/sliding-window.ts
|
|
225
|
+
var slidingWindow = reverseCurry(function* slidingWindow2(iter, { size, partial }) {
|
|
226
|
+
const window = [];
|
|
227
|
+
for (const value of iter) {
|
|
228
|
+
window.push(value);
|
|
229
|
+
if (window.length > size) {
|
|
230
|
+
window.shift();
|
|
231
|
+
}
|
|
232
|
+
if (window.length === size || partial) {
|
|
233
|
+
yield [...window];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (partial) {
|
|
237
|
+
while (window.length > 1) {
|
|
238
|
+
window.shift();
|
|
239
|
+
yield [...window];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// src/iter/some.ts
|
|
245
|
+
var some = reverseCurry((iter, predicate) => {
|
|
246
|
+
for (const item of iter) {
|
|
247
|
+
if (predicate(item)) {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return false;
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// src/iter/take.ts
|
|
255
|
+
var take = reverseCurry(function* take2(iter, n) {
|
|
256
|
+
let count2 = 0;
|
|
257
|
+
for (const value of iter) {
|
|
258
|
+
if (count2++ < n) {
|
|
259
|
+
yield value;
|
|
260
|
+
} else {
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// src/iter/tap.ts
|
|
267
|
+
var tap = reverseCurry(function* tap2(iter, fn) {
|
|
268
|
+
for (const value of iter) {
|
|
269
|
+
fn(value);
|
|
270
|
+
yield value;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// src/iter/tee.ts
|
|
275
|
+
var tee = reverseCurry((iter, n) => {
|
|
276
|
+
const values = [...iter];
|
|
277
|
+
return [...map(range(n ?? 2), () => values[Symbol.iterator]())];
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// src/iter/unique.ts
|
|
281
|
+
var unique = reverseCurry(function* unique2(iter) {
|
|
282
|
+
const seen = /* @__PURE__ */ new Set();
|
|
283
|
+
for (const item of iter) {
|
|
284
|
+
if (!seen.has(item)) {
|
|
285
|
+
seen.add(item);
|
|
286
|
+
yield item;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
var uniqueBy = reverseCurry(function* uniqueBy2(iter, keyFn) {
|
|
291
|
+
const seen = /* @__PURE__ */ new Set();
|
|
292
|
+
for (const item of iter) {
|
|
293
|
+
const key = keyFn(item);
|
|
294
|
+
if (!seen.has(key)) {
|
|
295
|
+
seen.add(key);
|
|
296
|
+
yield item;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// src/iter/unzip.ts
|
|
302
|
+
var unzip = reverseCurry((iterable) => {
|
|
303
|
+
const array1 = [];
|
|
304
|
+
const array2 = [];
|
|
305
|
+
let i = 0;
|
|
306
|
+
for (const [a, b] of iterable) {
|
|
307
|
+
array1[i] = a;
|
|
308
|
+
array2[i] = b;
|
|
309
|
+
i++;
|
|
310
|
+
}
|
|
311
|
+
return [array1, array2];
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// src/iter/zip.ts
|
|
315
|
+
var zip = reverseCurry(function* zip2(iterable1, iterable2) {
|
|
316
|
+
const iter1 = iterable1[Symbol.iterator]();
|
|
317
|
+
const iter2 = iterable2[Symbol.iterator]();
|
|
318
|
+
while (true) {
|
|
319
|
+
const result1 = iter1.next();
|
|
320
|
+
const result2 = iter2.next();
|
|
321
|
+
if (result1.done || result2.done) {
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
yield [result1.value, result2.value];
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
export {
|
|
329
|
+
associateBy,
|
|
330
|
+
chain,
|
|
331
|
+
chunk,
|
|
332
|
+
collect,
|
|
333
|
+
count,
|
|
334
|
+
cycle,
|
|
335
|
+
enumerate,
|
|
336
|
+
every,
|
|
337
|
+
filter,
|
|
338
|
+
filterByKey,
|
|
339
|
+
first,
|
|
340
|
+
groupBy,
|
|
341
|
+
intersperse,
|
|
342
|
+
last,
|
|
343
|
+
map,
|
|
344
|
+
nth,
|
|
345
|
+
partition,
|
|
346
|
+
pick,
|
|
347
|
+
range,
|
|
348
|
+
skip,
|
|
349
|
+
slidingWindow,
|
|
350
|
+
some,
|
|
351
|
+
take,
|
|
352
|
+
tap,
|
|
353
|
+
tee,
|
|
354
|
+
unique,
|
|
355
|
+
uniqueBy,
|
|
356
|
+
unzip,
|
|
357
|
+
zip
|
|
358
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
interface ComplexLike {
|
|
2
|
+
readonly r: number;
|
|
3
|
+
readonly i: number;
|
|
4
|
+
}
|
|
5
|
+
declare class Complex implements ComplexLike {
|
|
6
|
+
r: number;
|
|
7
|
+
i: number;
|
|
8
|
+
constructor(r?: number, i?: number);
|
|
9
|
+
toString(): string;
|
|
10
|
+
valueOf(): number;
|
|
11
|
+
copy(): Complex;
|
|
12
|
+
get conj(): Complex;
|
|
13
|
+
static fromAngle(angle: number, mag?: number): Complex;
|
|
14
|
+
isReal(): boolean;
|
|
15
|
+
add(c: number | ComplexLike): this;
|
|
16
|
+
static add(c1: Complex, c2: number | ComplexLike): Complex;
|
|
17
|
+
sub(c: number | ComplexLike): this;
|
|
18
|
+
static sub(c1: Complex, c2: number | ComplexLike): Complex;
|
|
19
|
+
mul(c: number | ComplexLike): this;
|
|
20
|
+
static mul(c1: Complex, c2: number | ComplexLike): Complex;
|
|
21
|
+
div(c: number | Complex): this;
|
|
22
|
+
static div(c1: Complex, c2: number | Complex): Complex;
|
|
23
|
+
sq(): this;
|
|
24
|
+
mag(): number;
|
|
25
|
+
magSq(): number;
|
|
26
|
+
angle(): number;
|
|
27
|
+
pow(z: ComplexLike): this;
|
|
28
|
+
}
|
|
29
|
+
declare function complex(real?: number, imaginary?: number): Complex;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Solves ax² + bx + c = 0 for x. In other words, finds the roots of a quadratic equation.
|
|
33
|
+
* @param a the coefficient of x²
|
|
34
|
+
* @param b the coefficient of x
|
|
35
|
+
* @param c the constant
|
|
36
|
+
* @returns An array of roots for the quadratic equation. Any imaginary roots will be NaN.
|
|
37
|
+
*/
|
|
38
|
+
declare function cquadraticRoots(a: number, b: number, c: number): [Complex, Complex];
|
|
39
|
+
|
|
40
|
+
declare function csqrt(z: Complex): Complex;
|
|
41
|
+
declare function clog(z: Complex): Complex;
|
|
42
|
+
declare const cln: typeof clog;
|
|
43
|
+
declare function cexp({ r, i }: ComplexLike): Complex;
|
|
44
|
+
declare function csin({ r, i }: ComplexLike): Complex;
|
|
45
|
+
declare function ccos({ r, i }: ComplexLike): Complex;
|
|
46
|
+
declare function ctan(z: ComplexLike): Complex;
|
|
47
|
+
declare function casin({ r, i }: ComplexLike): Complex;
|
|
48
|
+
declare function cacos({ r, i }: ComplexLike): Complex;
|
|
49
|
+
declare function catan({ r, i }: ComplexLike): Complex;
|
|
50
|
+
declare function csinh({ r, i }: ComplexLike): Complex;
|
|
51
|
+
declare function ccosh({ r, i }: ComplexLike): Complex;
|
|
52
|
+
declare function ctanh(z: ComplexLike): Complex;
|
|
53
|
+
declare function casinh({ r, i }: ComplexLike): Complex;
|
|
54
|
+
declare function cacosh({ r, i }: ComplexLike): Complex;
|
|
55
|
+
declare function catanh({ r, i }: ComplexLike): Complex;
|
|
56
|
+
|
|
57
|
+
export { Complex, type ComplexLike, cacos, cacosh, casin, casinh, catan, catanh, ccos, ccosh, cexp, cln, clog, complex, cquadraticRoots, csin, csinh, csqrt, ctan, ctanh };
|