semantic-typescript 0.4.1 → 0.5.3

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.
@@ -1,97 +0,0 @@
1
- import { OrderedCollectable } from "./collectable";
2
- import type { Comparator, Functional, Generator } from "./utility";
3
- export declare abstract class Statistics<E, D extends number | bigint> extends OrderedCollectable<E> {
4
- protected readonly Statistics: symbol;
5
- constructor(generator: Generator<E>);
6
- constructor(generator: Generator<E>, comparator: Comparator<E>);
7
- [Symbol.iterator](): globalThis.Generator<E, void, undefined>;
8
- [Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
9
- count(): bigint;
10
- abstract average(): D;
11
- abstract average(mapper: Functional<E, D>): D;
12
- abstract range(): D;
13
- abstract range(mapper: Functional<E, D>): D;
14
- abstract variance(): D;
15
- abstract variance(mapper: Functional<E, D>): D;
16
- abstract standardDeviation(): D;
17
- abstract standardDeviation(mapper: Functional<E, D>): D;
18
- abstract mean(): D;
19
- abstract mean(mapper: Functional<E, D>): D;
20
- abstract median(): D;
21
- abstract median(mapper: Functional<E, D>): D;
22
- abstract mode(): D;
23
- abstract mode(mapper: Functional<E, D>): D;
24
- frequency(): Map<E, bigint>;
25
- abstract summate(): D;
26
- abstract summate(mapper: Functional<E, D>): D;
27
- abstract quantile(quantile: number): D;
28
- abstract quantile(quantile: number, mapper: Functional<E, D>): D;
29
- abstract interquartileRange(): D;
30
- abstract interquartileRange(mapper: Functional<E, D>): D;
31
- abstract skewness(): D;
32
- abstract skewness(mapper: Functional<E, D>): D;
33
- abstract kurtosis(): D;
34
- abstract kurtosis(mapper: Functional<E, D>): D;
35
- }
36
- export declare class NumericStatistics<E> extends Statistics<E, number> {
37
- protected readonly NumericStatistics: symbol;
38
- constructor(generator: Generator<E>);
39
- constructor(generator: Generator<E>, comparator: Comparator<E>);
40
- [Symbol.iterator](): globalThis.Generator<E, void, undefined>;
41
- [Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
42
- average(): number;
43
- average(mapper: Functional<E, number>): number;
44
- range(): number;
45
- range(mapper: Functional<E, number>): number;
46
- variance(): number;
47
- variance(mapper: Functional<E, number>): number;
48
- standardDeviation(): number;
49
- standardDeviation(mapper: Functional<E, number>): number;
50
- mean(): number;
51
- mean(mapper: Functional<E, number>): number;
52
- median(): number;
53
- median(mapper: Functional<E, number>): number;
54
- mode(): number;
55
- mode(mapper: Functional<E, number>): number;
56
- summate(): number;
57
- summate(mapper: Functional<E, number>): number;
58
- quantile(quantile: number): number;
59
- quantile(quantile: number, mapper: Functional<E, number>): number;
60
- interquartileRange(): number;
61
- interquartileRange(mapper: Functional<E, number>): number;
62
- skewness(): number;
63
- skewness(mapper: Functional<E, number>): number;
64
- kurtosis(): number;
65
- kurtosis(mapper: Functional<E, number>): number;
66
- }
67
- export declare class BigIntStatistics<E> extends Statistics<E, bigint> {
68
- protected readonly BigIntStatistics: symbol;
69
- constructor(generator: Generator<E>);
70
- constructor(generator: Generator<E>, comparator: Comparator<E>);
71
- [Symbol.iterator](): globalThis.Generator<E, void, undefined>;
72
- [Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
73
- average(): bigint;
74
- average(mapper: Functional<E, bigint>): bigint;
75
- range(): bigint;
76
- range(mapper: Functional<E, bigint>): bigint;
77
- variance(): bigint;
78
- variance(mapper: Functional<E, bigint>): bigint;
79
- standardDeviation(): bigint;
80
- standardDeviation(mapper: Functional<E, bigint>): bigint;
81
- mean(): bigint;
82
- mean(mapper: Functional<E, bigint>): bigint;
83
- median(): bigint;
84
- median(mapper: Functional<E, bigint>): bigint;
85
- mode(): bigint;
86
- mode(mapper: Functional<E, bigint>): bigint;
87
- summate(): bigint;
88
- summate(mapper: Functional<E, bigint>): bigint;
89
- quantile(quantile: number): bigint;
90
- quantile(quantile: number, mapper: Functional<E, bigint>): bigint;
91
- interquartileRange(): bigint;
92
- interquartileRange(mapper: Functional<E, bigint>): bigint;
93
- skewness(): bigint;
94
- skewness(mapper: Functional<E, bigint>): bigint;
95
- kurtosis(): bigint;
96
- kurtosis(mapper: Functional<E, bigint>): bigint;
97
- }
@@ -1,483 +0,0 @@
1
- import { OrderedCollectable } from "./collectable";
2
- import { Collector, useBigIntAverage, useBigIntMedian, useBigIntMode, useBigIntSummate, useBigIntVariance, useFrequency, useNumericAverage, useNumericMedian, useNumericMode, useNumericStandardDeviation, useNumericSummate, useNumericVariance, useToArray } from "./collector";
3
- import { isFunction } from "./guard";
4
- import { useCompare, useToBigInt, useToNumber } from "./hook";
5
- import { StatisticsSymbol, NumericStatisticsSymbol, BigIntStatisticsSymbol } from "./symbol";
6
- export class Statistics extends OrderedCollectable {
7
- Statistics = StatisticsSymbol;
8
- constructor(parameter, comparator) {
9
- super(parameter, comparator || useCompare);
10
- Object.defineProperties(this, {
11
- "Statistics": {
12
- value: StatisticsSymbol,
13
- enumerable: false,
14
- writable: false,
15
- configurable: false
16
- }
17
- });
18
- Object.freeze(this);
19
- }
20
- *[Symbol.iterator]() {
21
- try {
22
- let collector = useToArray();
23
- yield* collector.collect(this.source());
24
- }
25
- catch (error) {
26
- throw new Error("Uncaught error on Generator.");
27
- }
28
- }
29
- async *[Symbol.asyncIterator]() {
30
- try {
31
- let collector = useToArray();
32
- yield* collector.collect(this.source());
33
- }
34
- catch (error) {
35
- throw new Error("Uncaught error on AsyncGenerator.");
36
- }
37
- }
38
- count() {
39
- return BigInt(this.buffer.length);
40
- }
41
- frequency() {
42
- return useFrequency().collect(this.source());
43
- }
44
- }
45
- ;
46
- Object.freeze(Statistics);
47
- Object.freeze(Statistics.prototype);
48
- Object.freeze(Object.getPrototypeOf(Statistics));
49
- export class NumericStatistics extends Statistics {
50
- NumericStatistics = NumericStatisticsSymbol;
51
- constructor(parameter, comparator) {
52
- super(parameter, comparator || useCompare);
53
- Object.defineProperties(this, {
54
- "NumericStatistics": {
55
- value: NumericStatisticsSymbol,
56
- enumerable: false,
57
- writable: false,
58
- configurable: false
59
- }
60
- });
61
- Object.freeze(this);
62
- }
63
- *[Symbol.iterator]() {
64
- try {
65
- let collector = useToArray();
66
- yield* collector.collect(this.source());
67
- }
68
- catch (error) {
69
- throw new Error("Uncaught error on Generator.");
70
- }
71
- }
72
- async *[Symbol.asyncIterator]() {
73
- try {
74
- let collector = useToArray();
75
- yield* collector.collect(this.source());
76
- }
77
- catch (error) {
78
- throw new Error("Uncaught error on AsyncGenerator.");
79
- }
80
- }
81
- average(mapper) {
82
- if (this.isEmpty()) {
83
- return 0;
84
- }
85
- try {
86
- if (isFunction(mapper)) {
87
- return useNumericAverage(mapper).collect(this.source());
88
- }
89
- return useNumericAverage().collect(this.source());
90
- }
91
- catch (error) {
92
- throw new Error("Uncaught error on average.");
93
- }
94
- }
95
- range(argument1) {
96
- if (this.isEmpty()) {
97
- return 0;
98
- }
99
- try {
100
- if (this.count() === 1n) {
101
- return 0;
102
- }
103
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
104
- let count = this.buffer.length;
105
- let minimum = this.buffer[0].element;
106
- let maximum = this.buffer[count - 1].element;
107
- return mapper(maximum) - mapper(minimum);
108
- }
109
- catch (error) {
110
- throw new Error("Uncaught error on range.");
111
- }
112
- }
113
- variance(argument1) {
114
- if (this.isEmpty() || this.count() === 1n) {
115
- return 0;
116
- }
117
- try {
118
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
119
- return useNumericVariance(mapper).collect(this.source());
120
- }
121
- catch (error) {
122
- throw new Error("Uncaught error on variance.");
123
- }
124
- }
125
- standardDeviation(argument1) {
126
- try {
127
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
128
- return useNumericStandardDeviation(mapper).collect(this.source());
129
- }
130
- catch (error) {
131
- throw new Error("Uncaught error on standardDeviation.");
132
- }
133
- }
134
- mean(argument1) {
135
- if (this.isEmpty()) {
136
- return 0;
137
- }
138
- try {
139
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
140
- return useNumericAverage(mapper).collect(this.source());
141
- }
142
- catch (error) {
143
- throw new Error("Uncaught error on mean.");
144
- }
145
- }
146
- median(argument1) {
147
- if (this.isEmpty()) {
148
- return 0;
149
- }
150
- try {
151
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
152
- return useNumericMedian(mapper).collect(this.source());
153
- }
154
- catch (error) {
155
- throw new Error("Uncaught error on median.");
156
- }
157
- }
158
- mode(argument1) {
159
- if (this.isEmpty()) {
160
- return 0;
161
- }
162
- try {
163
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
164
- return useNumericMode(mapper).collect(this.source());
165
- }
166
- catch (error) {
167
- throw new Error("Uncaught error on mode.");
168
- }
169
- }
170
- summate(argument1) {
171
- if (this.isEmpty()) {
172
- return 0;
173
- }
174
- try {
175
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
176
- return useNumericSummate(mapper).collect(this.source());
177
- }
178
- catch (error) {
179
- throw new Error("Uncaught error on summate.");
180
- }
181
- }
182
- quantile(quantile, argument1) {
183
- if (this.isEmpty()) {
184
- return 0;
185
- }
186
- if (quantile < 0 || quantile > 1) {
187
- throw new RangeError("Invalid quantile.");
188
- }
189
- try {
190
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
191
- let count = Number(this.count());
192
- let index = Math.floor(quantile * count);
193
- if (index === count) {
194
- index--;
195
- }
196
- let value = mapper(this.buffer[index].element);
197
- return value;
198
- }
199
- catch (error) {
200
- throw new Error("Uncaught error on quantile.");
201
- }
202
- }
203
- interquartileRange(argument1) {
204
- if (this.isEmpty()) {
205
- return 0;
206
- }
207
- try {
208
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
209
- let lower = this.quantile(0.25, mapper);
210
- let upper = this.quantile(0.75, mapper);
211
- return upper - lower;
212
- }
213
- catch (error) {
214
- throw new Error("Uncaught error on interquartileRange.");
215
- }
216
- }
217
- skewness(argument1) {
218
- if (this.isEmpty()) {
219
- return 0;
220
- }
221
- try {
222
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
223
- let mean = this.mean(mapper);
224
- let standardDeviation = this.standardDeviation(mapper);
225
- if (standardDeviation === 0) {
226
- return 0;
227
- }
228
- let data = this.toArray().map(item => mapper(item));
229
- let summate = 0;
230
- for (let value of data) {
231
- let z = (value - mean) / standardDeviation;
232
- summate += Math.pow(z, 3);
233
- }
234
- return summate / data.length;
235
- }
236
- catch (error) {
237
- throw new Error("Uncaught error on skewness.");
238
- }
239
- }
240
- kurtosis(argument1) {
241
- if (this.isEmpty()) {
242
- return 0;
243
- }
244
- try {
245
- let mapper = isFunction(argument1) ? argument1 : useToNumber;
246
- let mean = this.mean(mapper);
247
- let standardDeviation = this.standardDeviation(mapper);
248
- if (standardDeviation === 0) {
249
- return 0;
250
- }
251
- let data = this.toArray().map(item => mapper(item));
252
- let summate = 0;
253
- for (let value of data) {
254
- let z = (value - mean) / standardDeviation;
255
- summate += Math.pow(z, 4);
256
- }
257
- return summate / (data.length * data.length) - 3;
258
- }
259
- catch (error) {
260
- throw new Error("Uncaught error on kurtosis.");
261
- }
262
- }
263
- }
264
- ;
265
- Object.freeze(NumericStatistics);
266
- Object.freeze(NumericStatistics.prototype);
267
- Object.freeze(Object.getPrototypeOf(NumericStatistics));
268
- export class BigIntStatistics extends Statistics {
269
- BigIntStatistics = BigIntStatisticsSymbol;
270
- constructor(parameter, comparator) {
271
- super(parameter, comparator || useCompare);
272
- Object.defineProperties(this, {
273
- "BigIntStatistics": {
274
- value: BigIntStatisticsSymbol,
275
- enumerable: false,
276
- writable: false,
277
- configurable: false
278
- }
279
- });
280
- Object.freeze(this);
281
- }
282
- *[Symbol.iterator]() {
283
- try {
284
- let collector = useToArray();
285
- yield* collector.collect(this.source());
286
- }
287
- catch (error) {
288
- throw new Error("Uncaught error on Generator.");
289
- }
290
- }
291
- async *[Symbol.asyncIterator]() {
292
- try {
293
- let collector = useToArray();
294
- yield* collector.collect(this.source());
295
- }
296
- catch (error) {
297
- throw new Error("Uncaught error on AsyncGenerator.");
298
- }
299
- }
300
- average(argument1) {
301
- if (this.isEmpty()) {
302
- return 0n;
303
- }
304
- try {
305
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
306
- return useBigIntAverage(mapper).collect(this.source());
307
- }
308
- catch (error) {
309
- throw new Error("Uncaught error on average.");
310
- }
311
- }
312
- range(argument1) {
313
- if (this.isEmpty()) {
314
- return 0n;
315
- }
316
- try {
317
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
318
- let count = this.buffer.length;
319
- let minimum = this.buffer[0].element;
320
- let maximum = this.buffer[count - 1].element;
321
- return mapper(maximum) - mapper(minimum);
322
- }
323
- catch (error) {
324
- throw new Error("Uncaught error on range.");
325
- }
326
- }
327
- variance(argument1) {
328
- if (this.isEmpty() || this.count() === 1n) {
329
- return 0n;
330
- }
331
- try {
332
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
333
- return useBigIntVariance(mapper).collect(this.source());
334
- }
335
- catch (error) {
336
- throw new Error("Uncaught error on variance.");
337
- }
338
- }
339
- standardDeviation(argument1) {
340
- try {
341
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
342
- let variance = this.variance(mapper);
343
- return BigInt(Math.sqrt(Number(variance)));
344
- }
345
- catch (error) {
346
- throw new Error("Uncaught error on standardDeviation.");
347
- }
348
- }
349
- mean(argument1) {
350
- if (this.isEmpty()) {
351
- return 0n;
352
- }
353
- try {
354
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
355
- return useBigIntAverage(mapper).collect(this.source());
356
- }
357
- catch (error) {
358
- throw new Error("Uncaught error on mean.");
359
- }
360
- }
361
- median(argument1) {
362
- if (this.isEmpty()) {
363
- return 0n;
364
- }
365
- try {
366
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
367
- return useBigIntMedian(mapper).collect(this.source());
368
- }
369
- catch (error) {
370
- throw new Error("Uncaught error on median.");
371
- }
372
- }
373
- mode(argument1) {
374
- if (this.isEmpty()) {
375
- return 0n;
376
- }
377
- try {
378
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
379
- return useBigIntMode(mapper).collect(this.source());
380
- }
381
- catch (error) {
382
- throw new Error("Uncaught error on mode.");
383
- }
384
- }
385
- summate(argument1) {
386
- if (this.isEmpty()) {
387
- return 0n;
388
- }
389
- try {
390
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
391
- return useBigIntSummate(mapper).collect(this.source());
392
- }
393
- catch (error) {
394
- throw new Error("Uncaught error on summate.");
395
- }
396
- }
397
- quantile(quantile, argument1) {
398
- if (this.isEmpty()) {
399
- return 0n;
400
- }
401
- if (typeof quantile !== "number" || quantile < 0 || quantile > 1) {
402
- throw new RangeError("Invalid quantile.");
403
- }
404
- try {
405
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
406
- let count = Number(this.count());
407
- let index = Math.floor(quantile * count);
408
- if (index === count) {
409
- index--;
410
- }
411
- let value = mapper(this.buffer[index].element);
412
- return value;
413
- }
414
- catch (error) {
415
- throw new Error("Uncaught error on quantile.");
416
- }
417
- }
418
- interquartileRange(argument1) {
419
- if (this.isEmpty()) {
420
- return 0n;
421
- }
422
- try {
423
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
424
- let lower = this.quantile(0.25, mapper);
425
- let upper = this.quantile(0.75, mapper);
426
- return upper - lower;
427
- }
428
- catch (error) {
429
- throw new Error("Uncaught error on interquartileRange.");
430
- }
431
- }
432
- skewness(argument1) {
433
- if (this.isEmpty()) {
434
- return 0n;
435
- }
436
- try {
437
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
438
- let mean = this.mean(mapper);
439
- let standardDeviation = this.standardDeviation(mapper);
440
- if (standardDeviation === 0n) {
441
- return 0n;
442
- }
443
- let data = this.toArray().map(item => mapper(item));
444
- let summate = 0n;
445
- for (let value of data) {
446
- let z = value - mean;
447
- summate += z * z * z;
448
- }
449
- return summate / BigInt(data.length);
450
- }
451
- catch (error) {
452
- throw new Error("Uncaught error on skewness.");
453
- }
454
- }
455
- kurtosis(argument1) {
456
- if (this.isEmpty()) {
457
- return 0n;
458
- }
459
- try {
460
- let mapper = isFunction(argument1) ? argument1 : useToBigInt;
461
- let mean = this.mean(mapper);
462
- let standardDeviation = this.standardDeviation(mapper);
463
- if (standardDeviation === 0n) {
464
- return 0n;
465
- }
466
- let data = this.toArray().map(item => mapper(item));
467
- let summate = 0n;
468
- let count = data.length;
469
- for (let value of data) {
470
- let z = value - mean;
471
- summate += z * z * z * z;
472
- }
473
- return summate / BigInt(count * count) - 3n;
474
- }
475
- catch (error) {
476
- throw new Error("Uncaught error on kurtosis.");
477
- }
478
- }
479
- }
480
- ;
481
- Object.freeze(BigIntStatistics);
482
- Object.freeze(BigIntStatistics.prototype);
483
- Object.freeze(Object.getPrototypeOf(BigIntStatistics));
package/dist/window.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { OrderedCollectable } from "./collectable";
2
- import type { Semantic } from "./semantic";
3
- import type { Comparator, Generator } from "./utility";
4
- export declare class WindowCollectable<E> extends OrderedCollectable<E> {
5
- protected readonly WindowCollectable: symbol;
6
- constructor(generator: Generator<E>);
7
- constructor(generator: Generator<E>, comparator: Comparator<E>);
8
- [Symbol.iterator](): globalThis.Generator<E, void, undefined>;
9
- [Symbol.asyncIterator](): globalThis.AsyncGenerator<E, void, undefined>;
10
- slide(size: bigint, step?: bigint): Semantic<Semantic<E>>;
11
- tumble(size: bigint): Semantic<Semantic<E>>;
12
- }
package/dist/window.js DELETED
@@ -1,72 +0,0 @@
1
- import { OrderedCollectable } from "./collectable";
2
- import { useToAsyncGeneratorFunction, useToGeneratorFunction } from "./collector";
3
- import { from } from "./factory";
4
- import { useCompare } from "./hook";
5
- import { WindowCollectableSymbol } from "./symbol";
6
- export class WindowCollectable extends OrderedCollectable {
7
- WindowCollectable = WindowCollectableSymbol;
8
- constructor(parameter, comparator = useCompare) {
9
- super(parameter, comparator);
10
- Object.defineProperties(this, {
11
- "WindowCollectable": {
12
- value: WindowCollectableSymbol,
13
- writable: false,
14
- enumerable: false,
15
- configurable: false
16
- }
17
- });
18
- Object.freeze(this);
19
- }
20
- *[Symbol.iterator]() {
21
- try {
22
- let collector = useToGeneratorFunction();
23
- yield* collector.collect(this.source());
24
- }
25
- catch (error) {
26
- throw new Error("Uncaught error on Generator.");
27
- }
28
- }
29
- async *[Symbol.asyncIterator]() {
30
- try {
31
- let collector = useToAsyncGeneratorFunction();
32
- yield* collector.collect(this.source());
33
- }
34
- catch (error) {
35
- throw new Error("Uncaught error on AsyncGenerator.");
36
- }
37
- }
38
- slide(size, step = 1n) {
39
- if (size > 0n && step > 0n) {
40
- try {
41
- let source = this.toArray();
42
- let windows = [];
43
- let windowStartIndex = 0n;
44
- while (windowStartIndex < BigInt(source.length)) {
45
- let windowEnd = windowStartIndex + size;
46
- let window = source.slice(Number(windowStartIndex), Number(windowEnd));
47
- if (window.length > 0) {
48
- windows.push(window);
49
- }
50
- windowStartIndex += step;
51
- }
52
- return from(windows).map((window) => from(window));
53
- }
54
- catch (error) {
55
- throw new Error("Invalid arguments.");
56
- }
57
- }
58
- throw new RangeError("Invalid arguments.");
59
- }
60
- tumble(size) {
61
- try {
62
- return this.slide(size, size);
63
- }
64
- catch (error) {
65
- throw new Error("Invalid arguments.");
66
- }
67
- }
68
- }
69
- ;
70
- Object.freeze(WindowCollectable);
71
- Object.freeze(WindowCollectable.prototype);
72
- Object.freeze(Object.getPrototypeOf(WindowCollectable));