@nlozgachev/pipelined 0.40.0 → 0.42.0
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/Duration-BTeT9D-q.d.mts +127 -0
- package/dist/Duration-BTeT9D-q.d.ts +127 -0
- package/dist/{Task-uupX7xd9.d.ts → Task-BprUabHP.d.mts} +3 -2
- package/dist/{Task-DcXhCZYg.d.mts → Task-Dt3ZMen6.d.ts} +3 -2
- package/dist/{chunk-BQKKTTJS.mjs → chunk-6VYLZTAM.mjs} +3 -2
- package/dist/{chunk-3Q5UBRYB.mjs → chunk-F6SBU7GB.mjs} +88 -4
- package/dist/{chunk-5AFEEFE4.mjs → chunk-GBB6LVLI.mjs} +2 -2
- package/dist/{chunk-4R4XUP4M.mjs → chunk-OAP765G3.mjs} +31 -49
- package/dist/composition.d.mts +128 -1
- package/dist/composition.d.ts +128 -1
- package/dist/composition.js +111 -4
- package/dist/composition.mjs +2 -1
- package/dist/core.d.mts +5 -4
- package/dist/core.d.ts +5 -4
- package/dist/core.js +30 -48
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +145 -80
- package/dist/index.mjs +4 -4
- package/dist/types.d.mts +2 -126
- package/dist/types.d.ts +2 -126
- package/dist/types.mjs +1 -1
- package/dist/utils.d.mts +13 -1
- package/dist/utils.d.ts +13 -1
- package/dist/utils.js +30 -47
- package/dist/utils.mjs +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -402,10 +402,120 @@ pipe.try = (f, onError) => (a) => {
|
|
|
402
402
|
};
|
|
403
403
|
|
|
404
404
|
// src/Composition/tap.ts
|
|
405
|
-
var
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
405
|
+
var import_node_util = require("util");
|
|
406
|
+
|
|
407
|
+
// src/Types/Brand.ts
|
|
408
|
+
var Brand;
|
|
409
|
+
((Brand2) => {
|
|
410
|
+
Brand2.wrap = () => (value) => value;
|
|
411
|
+
Brand2.unwrap = (branded) => branded;
|
|
412
|
+
})(Brand || (Brand = {}));
|
|
413
|
+
|
|
414
|
+
// src/Types/NonEmptyList.ts
|
|
415
|
+
var isNonEmptyList = (list) => list.length > 0;
|
|
416
|
+
|
|
417
|
+
// src/Types/Duration.ts
|
|
418
|
+
var Duration;
|
|
419
|
+
((Duration2) => {
|
|
420
|
+
const wrap = Brand.wrap();
|
|
421
|
+
Duration2.milliseconds = (ms) => wrap(ms);
|
|
422
|
+
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
423
|
+
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
424
|
+
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
425
|
+
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
426
|
+
Duration2.toMilliseconds = (d) => Brand.unwrap(d);
|
|
427
|
+
Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
|
|
428
|
+
Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
429
|
+
Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
430
|
+
Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
431
|
+
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
432
|
+
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
433
|
+
})(Duration || (Duration = {}));
|
|
434
|
+
|
|
435
|
+
// src/Composition/tap.ts
|
|
436
|
+
function tap(f) {
|
|
437
|
+
return (a) => {
|
|
438
|
+
f(a);
|
|
439
|
+
return a;
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
((tap2) => {
|
|
443
|
+
tap2.log = (options) => (a) => {
|
|
444
|
+
const logger = options?.logger ?? console.log;
|
|
445
|
+
const formatter = options?.formatter ?? ((val) => {
|
|
446
|
+
try {
|
|
447
|
+
return typeof val === "object" && val !== null ? JSON.stringify(val) : String(val);
|
|
448
|
+
} catch {
|
|
449
|
+
return String(val);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
const formatted = formatter(a);
|
|
453
|
+
if (options?.label !== void 0) {
|
|
454
|
+
logger(`[${options.label}]: ${formatted}`);
|
|
455
|
+
} else {
|
|
456
|
+
logger(formatted);
|
|
457
|
+
}
|
|
458
|
+
return a;
|
|
459
|
+
};
|
|
460
|
+
tap2.inspect = (options) => (a) => {
|
|
461
|
+
const label = options?.label;
|
|
462
|
+
const depth = options?.depth ?? null;
|
|
463
|
+
const colors = options?.colors ?? true;
|
|
464
|
+
let formatted;
|
|
465
|
+
if (typeof import_node_util.inspect === "function") {
|
|
466
|
+
formatted = (0, import_node_util.inspect)(a, { depth, colors });
|
|
467
|
+
} else {
|
|
468
|
+
try {
|
|
469
|
+
formatted = JSON.stringify(a, null, 2);
|
|
470
|
+
} catch {
|
|
471
|
+
formatted = String(a);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (label !== void 0) {
|
|
475
|
+
console.log(`[${label}]: ${formatted}`);
|
|
476
|
+
} else {
|
|
477
|
+
console.log(formatted);
|
|
478
|
+
}
|
|
479
|
+
return a;
|
|
480
|
+
};
|
|
481
|
+
tap2.async = (fn, options) => (a) => {
|
|
482
|
+
const onError = options?.onError ?? console.error;
|
|
483
|
+
fn(a).catch((err2) => {
|
|
484
|
+
onError(err2);
|
|
485
|
+
});
|
|
486
|
+
return a;
|
|
487
|
+
};
|
|
488
|
+
tap2.time = (fn, config) => (a) => {
|
|
489
|
+
const start = performance.now();
|
|
490
|
+
const triggerFinish = (duration) => {
|
|
491
|
+
if (config.label !== void 0) {
|
|
492
|
+
console.log(`[${config.label}]: ${Duration.toMilliseconds(duration)}ms`);
|
|
493
|
+
} else {
|
|
494
|
+
config.onFinish(duration);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
try {
|
|
498
|
+
const res = fn(a);
|
|
499
|
+
if (res instanceof Promise) {
|
|
500
|
+
res.then(() => {
|
|
501
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
502
|
+
triggerFinish(duration);
|
|
503
|
+
}, () => {
|
|
504
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
505
|
+
triggerFinish(duration);
|
|
506
|
+
});
|
|
507
|
+
} else {
|
|
508
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
509
|
+
triggerFinish(duration);
|
|
510
|
+
}
|
|
511
|
+
} catch (err2) {
|
|
512
|
+
const duration = Duration.milliseconds(performance.now() - start);
|
|
513
|
+
triggerFinish(duration);
|
|
514
|
+
throw err2;
|
|
515
|
+
}
|
|
516
|
+
return a;
|
|
517
|
+
};
|
|
518
|
+
})(tap || (tap = {}));
|
|
409
519
|
|
|
410
520
|
// src/Composition/uncurry.ts
|
|
411
521
|
function uncurry(f) {
|
|
@@ -575,34 +685,6 @@ var Maybe;
|
|
|
575
685
|
};
|
|
576
686
|
})(Maybe || (Maybe = {}));
|
|
577
687
|
|
|
578
|
-
// src/Types/Brand.ts
|
|
579
|
-
var Brand;
|
|
580
|
-
((Brand2) => {
|
|
581
|
-
Brand2.wrap = () => (value) => value;
|
|
582
|
-
Brand2.unwrap = (branded) => branded;
|
|
583
|
-
})(Brand || (Brand = {}));
|
|
584
|
-
|
|
585
|
-
// src/Types/Duration.ts
|
|
586
|
-
var Duration;
|
|
587
|
-
((Duration2) => {
|
|
588
|
-
const wrap = Brand.wrap();
|
|
589
|
-
Duration2.milliseconds = (ms) => wrap(ms);
|
|
590
|
-
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
591
|
-
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
592
|
-
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
593
|
-
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
594
|
-
Duration2.toMilliseconds = (d) => Brand.unwrap(d);
|
|
595
|
-
Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
|
|
596
|
-
Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
597
|
-
Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
598
|
-
Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
599
|
-
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
600
|
-
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
601
|
-
})(Duration || (Duration = {}));
|
|
602
|
-
|
|
603
|
-
// src/Types/NonEmptyList.ts
|
|
604
|
-
var isNonEmptyList = (list) => list.length > 0;
|
|
605
|
-
|
|
606
688
|
// src/internal/Op.util.ts
|
|
607
689
|
var _abortedNil = { kind: "OpNil", reason: "aborted" };
|
|
608
690
|
var _droppedNil = { kind: "OpNil", reason: "dropped" };
|
|
@@ -2046,9 +2128,7 @@ var Task;
|
|
|
2046
2128
|
(signal) => new Promise((res) => {
|
|
2047
2129
|
let timerId;
|
|
2048
2130
|
const onAbort = () => {
|
|
2049
|
-
|
|
2050
|
-
clearTimeout(timerId);
|
|
2051
|
-
}
|
|
2131
|
+
clearTimeout(timerId);
|
|
2052
2132
|
res(toPromise(data, signal));
|
|
2053
2133
|
};
|
|
2054
2134
|
if (signal) {
|
|
@@ -2069,27 +2149,20 @@ var Task;
|
|
|
2069
2149
|
return Promise.resolve([]);
|
|
2070
2150
|
}
|
|
2071
2151
|
const results = [];
|
|
2072
|
-
const wait = () => {
|
|
2073
|
-
|
|
2074
|
-
|
|
2152
|
+
const wait = () => new Promise((r) => {
|
|
2153
|
+
let timerId;
|
|
2154
|
+
const onAbort = () => {
|
|
2155
|
+
clearTimeout(timerId);
|
|
2156
|
+
r();
|
|
2157
|
+
};
|
|
2158
|
+
if (signal) {
|
|
2159
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2075
2160
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
}
|
|
2082
|
-
r();
|
|
2083
|
-
};
|
|
2084
|
-
if (signal) {
|
|
2085
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
2086
|
-
}
|
|
2087
|
-
timerId = setTimeout(() => {
|
|
2088
|
-
signal?.removeEventListener("abort", onAbort);
|
|
2089
|
-
r();
|
|
2090
|
-
}, delayDuration ? getMs2(delayDuration) : 0);
|
|
2091
|
-
});
|
|
2092
|
-
};
|
|
2161
|
+
timerId = setTimeout(() => {
|
|
2162
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2163
|
+
r();
|
|
2164
|
+
}, delayDuration ? getMs2(delayDuration) : 0);
|
|
2165
|
+
});
|
|
2093
2166
|
const run2 = (left) => {
|
|
2094
2167
|
if (signal?.aborted) {
|
|
2095
2168
|
return Promise.resolve(results);
|
|
@@ -2106,27 +2179,20 @@ var Task;
|
|
|
2106
2179
|
});
|
|
2107
2180
|
Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
|
|
2108
2181
|
const { when: predicate, delay: delayDuration, maxAttempts } = options;
|
|
2109
|
-
const wait = () => {
|
|
2110
|
-
|
|
2111
|
-
|
|
2182
|
+
const wait = () => new Promise((r) => {
|
|
2183
|
+
let timerId;
|
|
2184
|
+
const onAbort = () => {
|
|
2185
|
+
clearTimeout(timerId);
|
|
2186
|
+
r();
|
|
2187
|
+
};
|
|
2188
|
+
if (signal) {
|
|
2189
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2112
2190
|
}
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
}
|
|
2119
|
-
r();
|
|
2120
|
-
};
|
|
2121
|
-
if (signal) {
|
|
2122
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
2123
|
-
}
|
|
2124
|
-
timerId = setTimeout(() => {
|
|
2125
|
-
signal?.removeEventListener("abort", onAbort);
|
|
2126
|
-
r();
|
|
2127
|
-
}, delayDuration ? getMs2(delayDuration) : 0);
|
|
2128
|
-
});
|
|
2129
|
-
};
|
|
2191
|
+
timerId = setTimeout(() => {
|
|
2192
|
+
signal?.removeEventListener("abort", onAbort);
|
|
2193
|
+
r();
|
|
2194
|
+
}, delayDuration ? getMs2(delayDuration) : 0);
|
|
2195
|
+
});
|
|
2130
2196
|
const run2 = (attempt, lastValue) => {
|
|
2131
2197
|
if (signal?.aborted && lastValue !== void 0) {
|
|
2132
2198
|
return Promise.resolve(lastValue);
|
|
@@ -2195,9 +2261,7 @@ var Task;
|
|
|
2195
2261
|
const controller = new AbortController();
|
|
2196
2262
|
let timerId;
|
|
2197
2263
|
function cleanUp() {
|
|
2198
|
-
|
|
2199
|
-
clearTimeout(timerId);
|
|
2200
|
-
}
|
|
2264
|
+
clearTimeout(timerId);
|
|
2201
2265
|
outerSignal?.removeEventListener("abort", onOuterAbort);
|
|
2202
2266
|
}
|
|
2203
2267
|
function onOuterAbort() {
|
|
@@ -2243,7 +2307,7 @@ var Task;
|
|
|
2243
2307
|
};
|
|
2244
2308
|
return { task, abort };
|
|
2245
2309
|
};
|
|
2246
|
-
Task2.run = (signal) => (task) =>
|
|
2310
|
+
Task2.run = (signal) => (task) => task(signal);
|
|
2247
2311
|
Task2.bindTo = (key) => (data) => (0, Task2.map)((a) => ({ [key]: a }))(data);
|
|
2248
2312
|
Task2.bind = (key, f) => (data) => (0, Task2.chain)(
|
|
2249
2313
|
(a) => (0, Task2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
@@ -2307,7 +2371,7 @@ var TaskResult3;
|
|
|
2307
2371
|
([of_, oa]) => Result.ap(oa)(of_)
|
|
2308
2372
|
)
|
|
2309
2373
|
);
|
|
2310
|
-
TaskResult4.run = (signal) => (task) =>
|
|
2374
|
+
TaskResult4.run = (signal) => (task) => task(signal);
|
|
2311
2375
|
TaskResult4.bindTo = (key) => (data) => (0, TaskResult4.map)((a) => ({ [key]: a }))(data);
|
|
2312
2376
|
TaskResult4.bind = (key, f) => (data) => (0, TaskResult4.chain)(
|
|
2313
2377
|
(a) => (0, TaskResult4.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
@@ -3035,6 +3099,7 @@ var Num;
|
|
|
3035
3099
|
};
|
|
3036
3100
|
Num2.clamp = (min2, max2) => (n) => Math.min(Math.max(n, min2), max2);
|
|
3037
3101
|
Num2.between = (min2, max2) => (n) => n >= min2 && n <= max2;
|
|
3102
|
+
Num2.inRange = (start, end) => (n) => n >= start && n < end;
|
|
3038
3103
|
Num2.parse = (s) => {
|
|
3039
3104
|
if (s.trim() === "") {
|
|
3040
3105
|
return Maybe.none();
|
package/dist/index.mjs
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
uncurry,
|
|
28
28
|
uncurry3,
|
|
29
29
|
uncurry4
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-F6SBU7GB.mjs";
|
|
31
31
|
import {
|
|
32
32
|
Arr,
|
|
33
33
|
Dict,
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
Rec,
|
|
36
36
|
Str,
|
|
37
37
|
Uniq
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-6VYLZTAM.mjs";
|
|
39
39
|
import {
|
|
40
40
|
Combinable,
|
|
41
41
|
Deferred,
|
|
@@ -61,12 +61,12 @@ import {
|
|
|
61
61
|
These,
|
|
62
62
|
Tuple,
|
|
63
63
|
Validation
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-OAP765G3.mjs";
|
|
65
65
|
import {
|
|
66
66
|
Brand,
|
|
67
67
|
Duration,
|
|
68
68
|
isNonEmptyList
|
|
69
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-GBB6LVLI.mjs";
|
|
70
70
|
export {
|
|
71
71
|
Arr,
|
|
72
72
|
Brand,
|
package/dist/types.d.mts
CHANGED
|
@@ -1,128 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Brand<K, T> creates a nominal type by tagging T with a phantom brand K.
|
|
4
|
-
* Prevents accidentally mixing up values that share the same underlying type.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* type UserId = Brand<"UserId", string>;
|
|
9
|
-
* type ProductId = Brand<"ProductId", string>;
|
|
10
|
-
*
|
|
11
|
-
* const toUserId = Brand.wrap<"UserId", string>();
|
|
12
|
-
* const toProductId = Brand.wrap<"ProductId", string>();
|
|
13
|
-
*
|
|
14
|
-
* const userId: UserId = toUserId("user-123");
|
|
15
|
-
* const productId: ProductId = toProductId("prod-456");
|
|
16
|
-
*
|
|
17
|
-
* // Type error: ProductId is not assignable to UserId
|
|
18
|
-
* // const wrong: UserId = productId;
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
type Brand<K extends string, T> = T & {
|
|
22
|
-
readonly [_brand]: K;
|
|
23
|
-
};
|
|
24
|
-
declare namespace Brand {
|
|
25
|
-
/**
|
|
26
|
-
* Returns a constructor that wraps a value of type T in brand K.
|
|
27
|
-
* The resulting function performs an unchecked cast — only use when the raw
|
|
28
|
-
* value is known to satisfy the brand's invariants.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* type PositiveNumber = Brand<"PositiveNumber", number>;
|
|
33
|
-
* const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
|
|
34
|
-
*
|
|
35
|
-
* const n: PositiveNumber = toPositiveNumber(42);
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
const wrap: <K extends string, T>() => (value: T) => Brand<K, T>;
|
|
39
|
-
/**
|
|
40
|
-
* Strips the brand and returns the underlying value.
|
|
41
|
-
* Since Brand<K, T> extends T this is rarely needed, but can improve readability.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* const userId: UserId = toUserId("user-123");
|
|
46
|
-
* const raw: string = Brand.unwrap(userId); // "user-123"
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
const unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* A branded nominal type representing a duration of time in milliseconds.
|
|
54
|
-
* Use Duration to ensure safe time-based operators and clear unit conversions.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```ts
|
|
58
|
-
* const halfSecond = Duration.milliseconds(500);
|
|
59
|
-
* const twoSeconds = Duration.seconds(2);
|
|
60
|
-
* const total = pipe(halfSecond, Duration.add(twoSeconds));
|
|
61
|
-
*
|
|
62
|
-
* Duration.toSeconds(total); // 2.5
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
type Duration = Brand<"Duration", number>;
|
|
66
|
-
declare namespace Duration {
|
|
67
|
-
/**
|
|
68
|
-
* Creates a Duration from milliseconds.
|
|
69
|
-
*/
|
|
70
|
-
const milliseconds: (ms: number) => Duration;
|
|
71
|
-
/**
|
|
72
|
-
* Creates a Duration from seconds.
|
|
73
|
-
*/
|
|
74
|
-
const seconds: (s: number) => Duration;
|
|
75
|
-
/**
|
|
76
|
-
* Creates a Duration from minutes.
|
|
77
|
-
*/
|
|
78
|
-
const minutes: (m: number) => Duration;
|
|
79
|
-
/**
|
|
80
|
-
* Creates a Duration from hours.
|
|
81
|
-
*/
|
|
82
|
-
const hours: (h: number) => Duration;
|
|
83
|
-
/**
|
|
84
|
-
* Creates a Duration from days.
|
|
85
|
-
*/
|
|
86
|
-
const days: (d: number) => Duration;
|
|
87
|
-
/**
|
|
88
|
-
* Converts a Duration back to raw milliseconds.
|
|
89
|
-
*/
|
|
90
|
-
const toMilliseconds: (d: Duration) => number;
|
|
91
|
-
/**
|
|
92
|
-
* Converts a Duration to seconds.
|
|
93
|
-
*/
|
|
94
|
-
const toSeconds: (d: Duration) => number;
|
|
95
|
-
/**
|
|
96
|
-
* Converts a Duration to minutes.
|
|
97
|
-
*/
|
|
98
|
-
const toMinutes: (d: Duration) => number;
|
|
99
|
-
/**
|
|
100
|
-
* Converts a Duration to hours.
|
|
101
|
-
*/
|
|
102
|
-
const toHours: (d: Duration) => number;
|
|
103
|
-
/**
|
|
104
|
-
* Converts a Duration to days.
|
|
105
|
-
*/
|
|
106
|
-
const toDays: (d: Duration) => number;
|
|
107
|
-
/**
|
|
108
|
-
* Adds two Durations together.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```ts
|
|
112
|
-
* pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
const add: (other: Duration) => (self: Duration) => Duration;
|
|
116
|
-
/**
|
|
117
|
-
* Subtracts the other Duration from this one.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```ts
|
|
121
|
-
* pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
const subtract: (other: Duration) => (self: Duration) => Duration;
|
|
125
|
-
}
|
|
1
|
+
export { B as Brand, D as Duration } from './Duration-BTeT9D-q.mjs';
|
|
126
2
|
|
|
127
3
|
/**
|
|
128
4
|
* A list that is guaranteed to have at least one element.
|
|
@@ -153,4 +29,4 @@ type NonEmptyList<A> = readonly [A, ...A[]];
|
|
|
153
29
|
*/
|
|
154
30
|
declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
|
|
155
31
|
|
|
156
|
-
export {
|
|
32
|
+
export { type NonEmptyList, isNonEmptyList };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,128 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Brand<K, T> creates a nominal type by tagging T with a phantom brand K.
|
|
4
|
-
* Prevents accidentally mixing up values that share the same underlying type.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* type UserId = Brand<"UserId", string>;
|
|
9
|
-
* type ProductId = Brand<"ProductId", string>;
|
|
10
|
-
*
|
|
11
|
-
* const toUserId = Brand.wrap<"UserId", string>();
|
|
12
|
-
* const toProductId = Brand.wrap<"ProductId", string>();
|
|
13
|
-
*
|
|
14
|
-
* const userId: UserId = toUserId("user-123");
|
|
15
|
-
* const productId: ProductId = toProductId("prod-456");
|
|
16
|
-
*
|
|
17
|
-
* // Type error: ProductId is not assignable to UserId
|
|
18
|
-
* // const wrong: UserId = productId;
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
type Brand<K extends string, T> = T & {
|
|
22
|
-
readonly [_brand]: K;
|
|
23
|
-
};
|
|
24
|
-
declare namespace Brand {
|
|
25
|
-
/**
|
|
26
|
-
* Returns a constructor that wraps a value of type T in brand K.
|
|
27
|
-
* The resulting function performs an unchecked cast — only use when the raw
|
|
28
|
-
* value is known to satisfy the brand's invariants.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* type PositiveNumber = Brand<"PositiveNumber", number>;
|
|
33
|
-
* const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
|
|
34
|
-
*
|
|
35
|
-
* const n: PositiveNumber = toPositiveNumber(42);
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
const wrap: <K extends string, T>() => (value: T) => Brand<K, T>;
|
|
39
|
-
/**
|
|
40
|
-
* Strips the brand and returns the underlying value.
|
|
41
|
-
* Since Brand<K, T> extends T this is rarely needed, but can improve readability.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* const userId: UserId = toUserId("user-123");
|
|
46
|
-
* const raw: string = Brand.unwrap(userId); // "user-123"
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
const unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* A branded nominal type representing a duration of time in milliseconds.
|
|
54
|
-
* Use Duration to ensure safe time-based operators and clear unit conversions.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```ts
|
|
58
|
-
* const halfSecond = Duration.milliseconds(500);
|
|
59
|
-
* const twoSeconds = Duration.seconds(2);
|
|
60
|
-
* const total = pipe(halfSecond, Duration.add(twoSeconds));
|
|
61
|
-
*
|
|
62
|
-
* Duration.toSeconds(total); // 2.5
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
type Duration = Brand<"Duration", number>;
|
|
66
|
-
declare namespace Duration {
|
|
67
|
-
/**
|
|
68
|
-
* Creates a Duration from milliseconds.
|
|
69
|
-
*/
|
|
70
|
-
const milliseconds: (ms: number) => Duration;
|
|
71
|
-
/**
|
|
72
|
-
* Creates a Duration from seconds.
|
|
73
|
-
*/
|
|
74
|
-
const seconds: (s: number) => Duration;
|
|
75
|
-
/**
|
|
76
|
-
* Creates a Duration from minutes.
|
|
77
|
-
*/
|
|
78
|
-
const minutes: (m: number) => Duration;
|
|
79
|
-
/**
|
|
80
|
-
* Creates a Duration from hours.
|
|
81
|
-
*/
|
|
82
|
-
const hours: (h: number) => Duration;
|
|
83
|
-
/**
|
|
84
|
-
* Creates a Duration from days.
|
|
85
|
-
*/
|
|
86
|
-
const days: (d: number) => Duration;
|
|
87
|
-
/**
|
|
88
|
-
* Converts a Duration back to raw milliseconds.
|
|
89
|
-
*/
|
|
90
|
-
const toMilliseconds: (d: Duration) => number;
|
|
91
|
-
/**
|
|
92
|
-
* Converts a Duration to seconds.
|
|
93
|
-
*/
|
|
94
|
-
const toSeconds: (d: Duration) => number;
|
|
95
|
-
/**
|
|
96
|
-
* Converts a Duration to minutes.
|
|
97
|
-
*/
|
|
98
|
-
const toMinutes: (d: Duration) => number;
|
|
99
|
-
/**
|
|
100
|
-
* Converts a Duration to hours.
|
|
101
|
-
*/
|
|
102
|
-
const toHours: (d: Duration) => number;
|
|
103
|
-
/**
|
|
104
|
-
* Converts a Duration to days.
|
|
105
|
-
*/
|
|
106
|
-
const toDays: (d: Duration) => number;
|
|
107
|
-
/**
|
|
108
|
-
* Adds two Durations together.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```ts
|
|
112
|
-
* pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
const add: (other: Duration) => (self: Duration) => Duration;
|
|
116
|
-
/**
|
|
117
|
-
* Subtracts the other Duration from this one.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```ts
|
|
121
|
-
* pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
const subtract: (other: Duration) => (self: Duration) => Duration;
|
|
125
|
-
}
|
|
1
|
+
export { B as Brand, D as Duration } from './Duration-BTeT9D-q.js';
|
|
126
2
|
|
|
127
3
|
/**
|
|
128
4
|
* A list that is guaranteed to have at least one element.
|
|
@@ -153,4 +29,4 @@ type NonEmptyList<A> = readonly [A, ...A[]];
|
|
|
153
29
|
*/
|
|
154
30
|
declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
|
|
155
31
|
|
|
156
|
-
export {
|
|
32
|
+
export { type NonEmptyList, isNonEmptyList };
|
package/dist/types.mjs
CHANGED
package/dist/utils.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Task-
|
|
1
|
+
import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Task-BprUabHP.mjs';
|
|
2
2
|
import { NonEmptyList } from './types.mjs';
|
|
3
|
+
import './Duration-BTeT9D-q.mjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Functional array utilities that compose well with pipe.
|
|
@@ -893,6 +894,17 @@ declare namespace Num {
|
|
|
893
894
|
* ```
|
|
894
895
|
*/
|
|
895
896
|
const between: (min: number, max: number) => (n: number) => boolean;
|
|
897
|
+
/**
|
|
898
|
+
* Returns `true` when the number is in the range `[start, end)` (inclusive of `start`, exclusive of `end`).
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```ts
|
|
902
|
+
* pipe(5, Num.inRange(1, 10)); // true
|
|
903
|
+
* pipe(1, Num.inRange(1, 10)); // true
|
|
904
|
+
* pipe(10, Num.inRange(1, 10)); // false
|
|
905
|
+
* ```
|
|
906
|
+
*/
|
|
907
|
+
const inRange: (start: number, end: number) => (n: number) => boolean;
|
|
896
908
|
/**
|
|
897
909
|
* Parses a string as a number. Returns `None` when the result is `NaN`.
|
|
898
910
|
*
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Task-
|
|
1
|
+
import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Task-Dt3ZMen6.js';
|
|
2
2
|
import { NonEmptyList } from './types.js';
|
|
3
|
+
import './Duration-BTeT9D-q.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Functional array utilities that compose well with pipe.
|
|
@@ -893,6 +894,17 @@ declare namespace Num {
|
|
|
893
894
|
* ```
|
|
894
895
|
*/
|
|
895
896
|
const between: (min: number, max: number) => (n: number) => boolean;
|
|
897
|
+
/**
|
|
898
|
+
* Returns `true` when the number is in the range `[start, end)` (inclusive of `start`, exclusive of `end`).
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```ts
|
|
902
|
+
* pipe(5, Num.inRange(1, 10)); // true
|
|
903
|
+
* pipe(1, Num.inRange(1, 10)); // true
|
|
904
|
+
* pipe(10, Num.inRange(1, 10)); // false
|
|
905
|
+
* ```
|
|
906
|
+
*/
|
|
907
|
+
const inRange: (start: number, end: number) => (n: number) => boolean;
|
|
896
908
|
/**
|
|
897
909
|
* Parses a string as a number. Returns `None` when the result is `NaN`.
|
|
898
910
|
*
|