@bodil/core 0.5.6 → 0.5.8
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/assert.js.map +1 -1
- package/dist/assert.test.js +2 -2
- package/dist/assert.test.js.map +1 -1
- package/dist/async/abortable-promise.d.ts +1 -1
- package/dist/async/abortable-promise.js +1 -1
- package/dist/async/abortable-promise.js.map +1 -1
- package/dist/async/abortable-promise.test.js +9 -9
- package/dist/async/abortable-promise.test.js.map +1 -1
- package/dist/async/emitter.test.js +1 -1
- package/dist/async/emitter.test.js.map +1 -1
- package/dist/collections/lfu-cache.js +1 -1
- package/dist/collections/lfu-cache.js.map +1 -1
- package/dist/collections/lru-cache.js +1 -1
- package/dist/collections/lru-cache.js.map +1 -1
- package/dist/decorators.test.js.map +1 -1
- package/dist/disposable.js +17 -0
- package/dist/disposable.js.map +1 -1
- package/dist/disposable.test.js +19 -4
- package/dist/disposable.test.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +19 -0
- package/dist/logger.js +26 -0
- package/dist/logger.js.map +1 -0
- package/dist/order.js.map +1 -1
- package/dist/order.test.js +1 -1
- package/dist/order.test.js.map +1 -1
- package/dist/time.test.js.map +1 -1
- package/package.json +40 -12
- package/src/assert.test.ts +11 -10
- package/src/assert.ts +9 -7
- package/src/async/abortable-promise.test.ts +24 -23
- package/src/async/abortable-promise.ts +17 -17
- package/src/async/emitter.test.ts +3 -2
- package/src/async.ts +2 -1
- package/src/collections/lfu-cache.ts +1 -1
- package/src/collections/linked-list.ts +1 -1
- package/src/collections/lru-cache.ts +2 -2
- package/src/decorators.test.ts +1 -0
- package/src/decorators.ts +1 -1
- package/src/disposable.test.ts +24 -4
- package/src/disposable.ts +20 -1
- package/src/index.ts +2 -1
- package/src/logger.ts +38 -0
- package/src/order.test.ts +2 -1
- package/src/order.ts +1 -1
- package/src/time.test.ts +1 -0
- package/src/time.ts +4 -4
- package/dist/assert.d.ts +0 -93
- package/dist/assert.test.d.ts +0 -1
- package/dist/async/abortable-promise.test.d.ts +0 -1
- package/dist/async/emitter.d.ts +0 -10
- package/dist/async/emitter.js +0 -22
- package/dist/async/emitter.js.map +0 -1
- package/dist/async/emitter.test.d.ts +0 -1
- package/dist/async.d.ts +0 -28
- package/dist/async.js +0 -52
- package/dist/async.js.map +0 -1
- package/dist/collections/lfu-cache.d.ts +0 -45
- package/dist/collections/lfu-cache.test.d.ts +0 -1
- package/dist/collections/linked-list.d.ts +0 -47
- package/dist/collections/lru-cache.d.ts +0 -45
- package/dist/collections/lru-cache.test.d.ts +0 -1
- package/dist/collections.d.ts +0 -7
- package/dist/collections.js +0 -8
- package/dist/collections.js.map +0 -1
- package/dist/decorators.d.ts +0 -12
- package/dist/decorators.test.d.ts +0 -1
- package/dist/disposable.d.ts +0 -115
- package/dist/disposable.test.d.ts +0 -1
- package/dist/fun.d.ts +0 -40
- package/dist/fun.js +0 -40
- package/dist/fun.js.map +0 -1
- package/dist/order.d.ts +0 -55
- package/dist/order.test.d.ts +0 -1
- package/dist/time.d.ts +0 -80
- package/dist/time.test.d.ts +0 -1
- package/dist/types.d.ts +0 -17
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
package/src/logger.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type Logger = {
|
|
2
|
+
debug: (...args: Array<any>) => void;
|
|
3
|
+
info: (...args: Array<any>) => void;
|
|
4
|
+
warn: (...args: Array<any>) => void;
|
|
5
|
+
error: (...args: Array<any>) => void;
|
|
6
|
+
log: (...args: Array<any>) => void;
|
|
7
|
+
trace: (...args: Array<any>) => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/* #__PURE__ */ function nope(..._args: Array<any>) {
|
|
11
|
+
// nope
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Log levels are defined as follows:
|
|
15
|
+
// * Dev: debug
|
|
16
|
+
// * Prod: warn
|
|
17
|
+
|
|
18
|
+
/* eslint no-console: "off" */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Methods on `logger` map directly to methods on {@link console}, but in
|
|
22
|
+
* production, only {@link logger.warn} and {@link logger.error} will actually
|
|
23
|
+
* log anything. Any other call to `logger` will be a no-op.
|
|
24
|
+
*
|
|
25
|
+
* "Production" in this case is defined by {@link import.meta.env.DEV} not being
|
|
26
|
+
* `true`. When using esbuild, it should be able to strip out the unused calls
|
|
27
|
+
* if it's able to determine the value of `import.meta.env.DEV` statically.
|
|
28
|
+
*/
|
|
29
|
+
export const logger: Logger = {
|
|
30
|
+
debug: import.meta.env !== undefined && import.meta.env.DEV === true ? console.debug : nope,
|
|
31
|
+
info: import.meta.env !== undefined && import.meta.env.DEV === true ? console.info : nope,
|
|
32
|
+
trace: import.meta.env !== undefined && import.meta.env.DEV === true ? console.trace : nope,
|
|
33
|
+
log: import.meta.env !== undefined && import.meta.env.DEV === true ? console.log : nope,
|
|
34
|
+
warn: console.warn,
|
|
35
|
+
error: console.error,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default logger;
|
package/src/order.test.ts
CHANGED
package/src/order.ts
CHANGED
package/src/time.test.ts
CHANGED
package/src/time.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { Cmp, type OrderFn } from "./order";
|
|
|
25
25
|
*/
|
|
26
26
|
export function isBefore(
|
|
27
27
|
instant: Temporal.Instant,
|
|
28
|
-
other?: Temporal.Instant | Temporal.Duration
|
|
28
|
+
other?: Temporal.Instant | Temporal.Duration,
|
|
29
29
|
): boolean {
|
|
30
30
|
if (other === undefined) {
|
|
31
31
|
return Temporal.Instant.compare(Temporal.Now.instant(), instant) === Cmp.LT;
|
|
@@ -33,7 +33,7 @@ export function isBefore(
|
|
|
33
33
|
return (
|
|
34
34
|
Temporal.Instant.compare(
|
|
35
35
|
instant,
|
|
36
|
-
other instanceof Temporal.Duration ? Temporal.Now.instant().subtract(other) : other
|
|
36
|
+
other instanceof Temporal.Duration ? Temporal.Now.instant().subtract(other) : other,
|
|
37
37
|
) === Cmp.LT
|
|
38
38
|
);
|
|
39
39
|
}
|
|
@@ -56,7 +56,7 @@ export function isBefore(
|
|
|
56
56
|
*/
|
|
57
57
|
export function isAfter(
|
|
58
58
|
instant: Temporal.Instant,
|
|
59
|
-
other?: Temporal.Instant | Temporal.Duration
|
|
59
|
+
other?: Temporal.Instant | Temporal.Duration,
|
|
60
60
|
): boolean {
|
|
61
61
|
if (other === undefined) {
|
|
62
62
|
return Temporal.Instant.compare(Temporal.Now.instant(), instant) === Cmp.GT;
|
|
@@ -64,7 +64,7 @@ export function isAfter(
|
|
|
64
64
|
return (
|
|
65
65
|
Temporal.Instant.compare(
|
|
66
66
|
instant,
|
|
67
|
-
other instanceof Temporal.Duration ? Temporal.Now.instant().add(other) : other
|
|
67
|
+
other instanceof Temporal.Duration ? Temporal.Now.instant().add(other) : other,
|
|
68
68
|
) === Cmp.GT
|
|
69
69
|
);
|
|
70
70
|
}
|
package/dist/assert.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Assertions and predicates.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
interface ImportMetaEnv {
|
|
6
|
-
DEV?: boolean;
|
|
7
|
-
}
|
|
8
|
-
declare global {
|
|
9
|
-
interface ImportMeta {
|
|
10
|
-
env?: ImportMetaEnv;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The specific {@link Error} type thrown by assertions.
|
|
15
|
-
*/
|
|
16
|
-
export declare class AssertionError extends Error {
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Asserts that a condition is true. Throws an exception if it's not.
|
|
20
|
-
*
|
|
21
|
-
* When using Vite, this function generates no code when building a production
|
|
22
|
-
* bundle.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts @import.meta.vitest
|
|
26
|
-
* assert(2 === 2);
|
|
27
|
-
* expect(() => assert(2 === 3)).toThrowError();
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare function assert(assertion: unknown, message?: string): asserts assertion;
|
|
31
|
-
/**
|
|
32
|
-
* As {@link assert}, but isn't skipped in production.
|
|
33
|
-
*/
|
|
34
|
-
export declare function assertAlways(assertion: unknown, message?: string): asserts assertion;
|
|
35
|
-
/**
|
|
36
|
-
* Throws an exception used to mark unreachable code.
|
|
37
|
-
*/
|
|
38
|
-
export declare function unreachable(): never;
|
|
39
|
-
/**
|
|
40
|
-
* Assert that a type is `never` when type checking. Throws an
|
|
41
|
-
* {@link unreachable} exception if it's reached at runtime. This is meant as an
|
|
42
|
-
* exhaustiveness check.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* type State = "on" | "off";
|
|
46
|
-
* function checkState(state: State) {
|
|
47
|
-
* if (state === "on") {
|
|
48
|
-
* console.log("it's on");
|
|
49
|
-
* } else if (state === "off") {
|
|
50
|
-
* console.log("it's off");
|
|
51
|
-
* } else {
|
|
52
|
-
* // this would fail to type check if you
|
|
53
|
-
* // haven't tested all valid `State` values
|
|
54
|
-
* // in the above if statement:
|
|
55
|
-
* assertNever<typeof state>();
|
|
56
|
-
* }
|
|
57
|
-
* }
|
|
58
|
-
*/
|
|
59
|
-
export declare function assertNever<T extends never>(_value: T): T;
|
|
60
|
-
/**
|
|
61
|
-
* Returns the given value unchanged if it's neither `null` nor `undefined`.
|
|
62
|
-
* Throws an exception otherwise.
|
|
63
|
-
*/
|
|
64
|
-
export declare function present<A>(value: A, message?: string): NonNullable<A>;
|
|
65
|
-
/**
|
|
66
|
-
* Tests whether a value is `null`, `undefined`, `false`, an empty array or an
|
|
67
|
-
* empty string.
|
|
68
|
-
*/
|
|
69
|
-
export declare function isEmpty(value: unknown): value is null | undefined | void | "" | [] | false;
|
|
70
|
-
/**
|
|
71
|
-
* Tests whether a value is `null` or `undefined`.
|
|
72
|
-
*/
|
|
73
|
-
export declare function isNullish(value: unknown): value is null | undefined | void;
|
|
74
|
-
/**
|
|
75
|
-
* Tests whether a value is an {@link Iterable}.
|
|
76
|
-
*/
|
|
77
|
-
export declare function isIterable(value: unknown): value is Iterable<unknown>;
|
|
78
|
-
/**
|
|
79
|
-
* Tests whether a value is an {@link AsyncIterable}.
|
|
80
|
-
*/
|
|
81
|
-
export declare function isAsyncIterable(value: unknown): value is AsyncIterable<unknown>;
|
|
82
|
-
/**
|
|
83
|
-
* Compares two values for deep equality.
|
|
84
|
-
*
|
|
85
|
-
* Handles {@link Map}, {@link Set}, {@link ArrayBuffer}, {@link RegExp},
|
|
86
|
-
* {@link Equals} and objects with a `valueOf` or `toString` method in addition
|
|
87
|
-
* to the language built-ins.
|
|
88
|
-
*
|
|
89
|
-
* The implementation is a gently modified version of
|
|
90
|
-
* [fast-deep-equal](https://www.npmjs.com/package/fast-deep-equal).
|
|
91
|
-
*/
|
|
92
|
-
export declare function isDeepEqual(a: unknown, b: unknown): boolean;
|
|
93
|
-
export {};
|
package/dist/assert.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "temporal-polyfill/global";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/async/emitter.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A multi consumer event broadcaster, like an `EventTarget` but async and
|
|
3
|
-
* without named events.
|
|
4
|
-
*/
|
|
5
|
-
export declare class Emitter<A> implements Disposable {
|
|
6
|
-
#private;
|
|
7
|
-
[Symbol.dispose](): void;
|
|
8
|
-
on(listener: (event: A) => void): Disposable;
|
|
9
|
-
emit(event: A): void;
|
|
10
|
-
}
|
package/dist/async/emitter.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { defer } from "../async";
|
|
2
|
-
import { toDisposable } from "../disposable";
|
|
3
|
-
/**
|
|
4
|
-
* A multi consumer event broadcaster, like an `EventTarget` but async and
|
|
5
|
-
* without named events.
|
|
6
|
-
*/
|
|
7
|
-
export class Emitter {
|
|
8
|
-
#listeners = new Set();
|
|
9
|
-
[Symbol.dispose]() {
|
|
10
|
-
this.#listeners.clear();
|
|
11
|
-
}
|
|
12
|
-
on(listener) {
|
|
13
|
-
this.#listeners.add(listener);
|
|
14
|
-
return toDisposable(() => this.#listeners.delete(listener));
|
|
15
|
-
}
|
|
16
|
-
emit(event) {
|
|
17
|
-
for (const listener of this.#listeners) {
|
|
18
|
-
defer(() => listener(event));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=emitter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/async/emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;;GAGG;AACH,MAAM,OAAO,OAAO;IACP,UAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEpD,CAAC,MAAM,CAAC,OAAO,CAAC;QACZ,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,EAAE,CAAC,QAA4B;QAC3B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO,YAAY,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,CAAC,KAAQ;QACT,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACrC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/async.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Async utilities.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
export { AbortablePromise, type AbortableExecutor } from "./async/abortable-promise";
|
|
6
|
-
export { Emitter } from "./async/emitter";
|
|
7
|
-
/**
|
|
8
|
-
* Call the provided function at the soonest opportunity after the current task
|
|
9
|
-
* yields.
|
|
10
|
-
*
|
|
11
|
-
* This is implemented using {@link queueMicrotask}.
|
|
12
|
-
*/
|
|
13
|
-
export declare function defer(fn: () => void | PromiseLike<void>): Disposable;
|
|
14
|
-
export type SchedulerAPI = {
|
|
15
|
-
schedule: (job: () => void) => Disposable;
|
|
16
|
-
};
|
|
17
|
-
export declare const SchedulerAPI: Record<string, SchedulerAPI>;
|
|
18
|
-
/**
|
|
19
|
-
* Return a promise that will resolve after the specified number of
|
|
20
|
-
* milliseconds or {@link Temporal.Duration}.
|
|
21
|
-
*/
|
|
22
|
-
export declare function sleep(duration: number | Temporal.Duration): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Test whether a value is an `AbortError`.
|
|
25
|
-
*/
|
|
26
|
-
export declare function isAbortError(value: unknown): value is DOMException & {
|
|
27
|
-
name: "AbortError";
|
|
28
|
-
};
|
package/dist/async.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Async utilities.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
import { idleCallback, timeout, toDisposable } from "./disposable";
|
|
6
|
-
export { AbortablePromise } from "./async/abortable-promise";
|
|
7
|
-
export { Emitter } from "./async/emitter";
|
|
8
|
-
/**
|
|
9
|
-
* Call the provided function at the soonest opportunity after the current task
|
|
10
|
-
* yields.
|
|
11
|
-
*
|
|
12
|
-
* This is implemented using {@link queueMicrotask}.
|
|
13
|
-
*/
|
|
14
|
-
export function defer(fn) {
|
|
15
|
-
let disposed = false;
|
|
16
|
-
globalThis.queueMicrotask(() => {
|
|
17
|
-
if (disposed) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
disposed = true;
|
|
21
|
-
fn();
|
|
22
|
-
});
|
|
23
|
-
return toDisposable(() => {
|
|
24
|
-
disposed = true;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
export const SchedulerAPI = {
|
|
28
|
-
Microtask: {
|
|
29
|
-
schedule: defer,
|
|
30
|
-
},
|
|
31
|
-
Macrotask: {
|
|
32
|
-
schedule: globalThis.requestIdleCallback !== undefined
|
|
33
|
-
? (f) => idleCallback(f)
|
|
34
|
-
: (f) => timeout(f, 0),
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Return a promise that will resolve after the specified number of
|
|
39
|
-
* milliseconds or {@link Temporal.Duration}.
|
|
40
|
-
*/
|
|
41
|
-
export function sleep(duration) {
|
|
42
|
-
return new Promise((resolve) => {
|
|
43
|
-
setTimeout(resolve, typeof duration === "number" ? duration : duration.total("milliseconds"));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Test whether a value is an `AbortError`.
|
|
48
|
-
*/
|
|
49
|
-
export function isAbortError(value) {
|
|
50
|
-
return value instanceof DOMException && value.name === "AbortError";
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=async.js.map
|
package/dist/async.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async.js","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAA0B,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,EAAkC;IACpD,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,UAAU,CAAC,cAAc,CAAC,GAAG,EAAE;QAC3B,IAAI,QAAQ,EAAE,CAAC;YACX,OAAO;QACX,CAAC;QACD,QAAQ,GAAG,IAAI,CAAC;QAChB,EAAE,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;IACH,OAAO,YAAY,CAAC,GAAG,EAAE;QACrB,QAAQ,GAAG,IAAI,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC;AAMD,MAAM,CAAC,MAAM,YAAY,GAAiC;IACtD,SAAS,EAAE;QACP,QAAQ,EAAE,KAAK;KAClB;IACD,SAAS,EAAE;QACP,QAAQ,EACJ,UAAU,CAAC,mBAAmB,KAAK,SAAS;YACxC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;KACjC;CACJ,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,QAAoC;IACtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,UAAU,CACN,OAAO,EACP,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAC3E,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACvC,OAAO,KAAK,YAAY,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC;AACxE,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { type Option } from "@bodil/opt";
|
|
2
|
-
/**
|
|
3
|
-
* Configuration for the {@link LFUCache}.
|
|
4
|
-
*/
|
|
5
|
-
export type LFUCacheOptions<V> = {
|
|
6
|
-
/**
|
|
7
|
-
* The maximum size of the cache.
|
|
8
|
-
*/
|
|
9
|
-
maxLength?: number;
|
|
10
|
-
/**
|
|
11
|
-
* An optional dispose function to be called when a value is removed from
|
|
12
|
-
* the cache. Defaults to disposing of values which implement
|
|
13
|
-
* {@link Disposable}, and doing nothing otherwise.
|
|
14
|
-
*/
|
|
15
|
-
disposeFunction?: (value: V) => void;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* A Least Frequently Used cache.
|
|
19
|
-
*
|
|
20
|
-
* When the cache needs to drop a value to stay within its bounds, it chooses
|
|
21
|
-
* the value that has the lowest access count.
|
|
22
|
-
*/
|
|
23
|
-
export declare class LFUCache<K, V> implements Disposable {
|
|
24
|
-
#private;
|
|
25
|
-
constructor(options?: LFUCacheOptions<V>);
|
|
26
|
-
[Symbol.dispose](): void;
|
|
27
|
-
/**
|
|
28
|
-
* Get the current size of the cache.
|
|
29
|
-
*/
|
|
30
|
-
get size(): number;
|
|
31
|
-
/**
|
|
32
|
-
* Test if the cache contains a given key.
|
|
33
|
-
*
|
|
34
|
-
* This does not count as an access towards cache invalidation.
|
|
35
|
-
*/
|
|
36
|
-
has(key: K): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Get the value associated with the given key, if it exists in the cache.
|
|
39
|
-
*/
|
|
40
|
-
get(key: K): Option<V>;
|
|
41
|
-
/**
|
|
42
|
-
* Add a key/value pair to the cache.
|
|
43
|
-
*/
|
|
44
|
-
set(key: K, value: V): void;
|
|
45
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@bodil/opt-vitest";
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for nodes in a {@link LinkedList}.
|
|
3
|
-
*/
|
|
4
|
-
export interface ListNode {
|
|
5
|
-
prev?: this;
|
|
6
|
-
next?: this;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* A doubly linked list.
|
|
10
|
-
*
|
|
11
|
-
* You never know when you're going to need one.
|
|
12
|
-
*/
|
|
13
|
-
export declare class LinkedList<Node extends ListNode> implements Iterable<Node> {
|
|
14
|
-
head?: Node;
|
|
15
|
-
tail?: Node;
|
|
16
|
-
/**
|
|
17
|
-
* Remove a node from the list.
|
|
18
|
-
*/
|
|
19
|
-
remove(node: Node): void;
|
|
20
|
-
/**
|
|
21
|
-
* Insert a node into the list between the given nodes.
|
|
22
|
-
*
|
|
23
|
-
* It goes without saying that the `prev`/`next` nodes must be adjacent to
|
|
24
|
-
* each other in the list, or exceptions will be thrown.
|
|
25
|
-
*/
|
|
26
|
-
insert(node: Node, prev?: Node, next?: Node): Node;
|
|
27
|
-
/**
|
|
28
|
-
* Insert a node at the head of the list.
|
|
29
|
-
*/
|
|
30
|
-
pushHead(node: Node): void;
|
|
31
|
-
/**
|
|
32
|
-
* Insert a node at the tail of the list.
|
|
33
|
-
*/
|
|
34
|
-
pushTail(node: Node): void;
|
|
35
|
-
/**
|
|
36
|
-
* Remove the node at the head of the list and return it.
|
|
37
|
-
*/
|
|
38
|
-
popHead(): Node | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* Remove the node at the tail of the list and return it.
|
|
41
|
-
*/
|
|
42
|
-
popTail(): Node | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Iterate over the nodes in the list from head to tail.
|
|
45
|
-
*/
|
|
46
|
-
[Symbol.iterator]: () => IterableIterator<Node>;
|
|
47
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { type Option } from "@bodil/opt";
|
|
2
|
-
/**
|
|
3
|
-
* Configuration for the {@link LRUCache}.
|
|
4
|
-
*/
|
|
5
|
-
export type LRUCacheOptions<V> = {
|
|
6
|
-
/**
|
|
7
|
-
* The maximum size of the cache.
|
|
8
|
-
*/
|
|
9
|
-
maxLength?: number;
|
|
10
|
-
/**
|
|
11
|
-
* An optional dispose function to be called when a value is removed from
|
|
12
|
-
* the cache. Defaults to disposing of values which implement
|
|
13
|
-
* {@link Disposable}, and doing nothing otherwise.
|
|
14
|
-
*/
|
|
15
|
-
disposeFunction?: (value: V) => void;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* A Least Recently Used cache.
|
|
19
|
-
*
|
|
20
|
-
* When the cache needs to drop a value to stay within its bounds, it chooses
|
|
21
|
-
* the value that was accessed the least recently.
|
|
22
|
-
*/
|
|
23
|
-
export declare class LRUCache<K, V> implements Disposable {
|
|
24
|
-
#private;
|
|
25
|
-
constructor(options?: LRUCacheOptions<V>);
|
|
26
|
-
[Symbol.dispose](): void;
|
|
27
|
-
/**
|
|
28
|
-
* Get the current size of the cache.
|
|
29
|
-
*/
|
|
30
|
-
get size(): number;
|
|
31
|
-
/**
|
|
32
|
-
* Test if the cache contains a given key.
|
|
33
|
-
*
|
|
34
|
-
* This does not count as an access towards cache invalidation.
|
|
35
|
-
*/
|
|
36
|
-
has(key: K): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Get the value associated with the given key, if it exists in the cache.
|
|
39
|
-
*/
|
|
40
|
-
get(key: K): Option<V>;
|
|
41
|
-
/**
|
|
42
|
-
* Add a key/value pair to the cache.
|
|
43
|
-
*/
|
|
44
|
-
set(key: K, value: V): void;
|
|
45
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@bodil/opt-vitest";
|
package/dist/collections.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Some useful data structures.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
export { LinkedList, type ListNode } from "./collections/linked-list";
|
|
6
|
-
export { LFUCache, type LFUCacheOptions } from "./collections/lfu-cache";
|
|
7
|
-
export { LRUCache, type LRUCacheOptions } from "./collections/lru-cache";
|
package/dist/collections.js
DELETED
package/dist/collections.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAiB,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAwB,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAwB,MAAM,yBAAyB,CAAC"}
|
package/dist/decorators.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Assorted decorators.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Decorate a getter to cache its result.
|
|
7
|
-
*
|
|
8
|
-
* Useful for deferring initialisation of a property until first access.
|
|
9
|
-
* Instead of `myProperty = new Thing();`,
|
|
10
|
-
* use `@cache get myProperty() { return new Thing(); }`.
|
|
11
|
-
*/
|
|
12
|
-
export declare function cache<C extends object, T>(getter: (this: C) => T, context: ClassGetterDecoratorContext<C, T>): (this: C) => T;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/disposable.d.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tools for working with {@link Disposable}s and things that should have been
|
|
3
|
-
* {@link Disposable}.
|
|
4
|
-
*
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
import type { Constructor } from "type-fest";
|
|
8
|
-
import type { Unsubscribable } from "type-fest/globals";
|
|
9
|
-
/**
|
|
10
|
-
* Test whether something implements {@link Disposable}.
|
|
11
|
-
*/
|
|
12
|
-
export declare function isDisposable(value: unknown): value is Disposable;
|
|
13
|
-
/**
|
|
14
|
-
* Type for something that can be turned into a {@link Disposable}.
|
|
15
|
-
*
|
|
16
|
-
* Includes things that already implement {@link Disposable}, objects with an
|
|
17
|
-
* `unsubscribe()` method (an {@link Unsubscribable}), and functions
|
|
18
|
-
* with no arguments or return values which are assumed to be unsubscribe
|
|
19
|
-
* functions, as popularised by React.
|
|
20
|
-
*/
|
|
21
|
-
export type Disposifiable = (() => void) | Unsubscribable | Disposable;
|
|
22
|
-
/**
|
|
23
|
-
* Construct a new {@link Disposable} out of any {@link Disposifiable}.
|
|
24
|
-
*
|
|
25
|
-
* This constructs a new object which implements {@link Disposable}, and nothing
|
|
26
|
-
* else. The new object's dispose method will dispose of the original
|
|
27
|
-
* {@link Disposifiable}, and ensure that this happens only once, regardless of
|
|
28
|
-
* how many times the dispose method is called.
|
|
29
|
-
*/
|
|
30
|
-
export declare function toDisposable(value: Disposifiable): Disposable;
|
|
31
|
-
/**
|
|
32
|
-
* Call {@link setTimeout} with the provided callback and return a
|
|
33
|
-
* {@link Disposable} which will cancel the timeout when disposed.
|
|
34
|
-
*/
|
|
35
|
-
export declare function timeout(fn: () => void, timeout: number | Temporal.Duration): Disposable;
|
|
36
|
-
/**
|
|
37
|
-
* Call {@link setInterval} with the provided callback and return a
|
|
38
|
-
* {@link Disposable} which will cancel the interval when disposed.
|
|
39
|
-
*/
|
|
40
|
-
export declare function interval(fn: () => void, interval: number | Temporal.Duration): Disposable;
|
|
41
|
-
export declare function idleCallback(callback: IdleRequestCallback, options?: IdleRequestOptions): Disposable;
|
|
42
|
-
/**
|
|
43
|
-
* An implementation of {@link AbortController} which also implements
|
|
44
|
-
* {@link Disposable}.
|
|
45
|
-
*
|
|
46
|
-
* Disposing the controller automatically triggers the abort signal.
|
|
47
|
-
*/
|
|
48
|
-
export declare class DisposableAbortController implements AbortController, Disposable {
|
|
49
|
-
#private;
|
|
50
|
-
get signal(): AbortSignal;
|
|
51
|
-
abort(reason?: any): void;
|
|
52
|
-
[Symbol.dispose](): void;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Create an {@link AbortController} which also implements {@link Disposable}.
|
|
56
|
-
*
|
|
57
|
-
* Disposing the controller automatically triggers the abort signal.
|
|
58
|
-
*
|
|
59
|
-
* @returns A {@link DisposableAbortController}.
|
|
60
|
-
*/
|
|
61
|
-
export declare function abortController(): DisposableAbortController;
|
|
62
|
-
export interface DisposableContext extends Disposable {
|
|
63
|
-
/**
|
|
64
|
-
* Disposes the resources currently held by this context.
|
|
65
|
-
*/
|
|
66
|
-
dispose(): void;
|
|
67
|
-
/**
|
|
68
|
-
* Register a {@link Disposifiable} resource with this context, to be
|
|
69
|
-
* disposed along with it.
|
|
70
|
-
*
|
|
71
|
-
* @returns The {@link Disposable} that was registered with the context.
|
|
72
|
-
*/
|
|
73
|
-
use(resource: null): null;
|
|
74
|
-
use(resource: undefined): undefined;
|
|
75
|
-
use(resource: Disposifiable): Disposable;
|
|
76
|
-
use(resource: Disposifiable | undefined): Disposable | undefined;
|
|
77
|
-
use(resource: Disposifiable | null | undefined): Disposable | null | undefined;
|
|
78
|
-
adopt<A>(value: A, onDispose: (value: A) => void): A;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* A reentrant version of {@link DisposableStack}.
|
|
82
|
-
*
|
|
83
|
-
* This maintains a list of {@link Disposable}s, added with the
|
|
84
|
-
* {@link DisposableContext.use} method, which will all be disposed when you
|
|
85
|
-
* dispose of the {@link DisposableContext} itself.
|
|
86
|
-
*
|
|
87
|
-
* Where this differs from {@link DisposableStack} is that disposing it only
|
|
88
|
-
* resets it after disposing of its dependents, and you can reuse it as many
|
|
89
|
-
* times as you like. This is very handy for managing lifecycle resources, eg. a
|
|
90
|
-
* web component can allocate resources in its `connectedCallback` method and
|
|
91
|
-
* during its connected lifecycle phase which can all be disposed in
|
|
92
|
-
* `disconnectedCallback` with a single call to
|
|
93
|
-
* {@link DisposableContext.dispose}, and it's instantly ready to go again on
|
|
94
|
-
* reconnect.
|
|
95
|
-
*
|
|
96
|
-
* @class
|
|
97
|
-
*/
|
|
98
|
-
export declare const DisposableContext: Constructor<DisposableContext>;
|
|
99
|
-
/**
|
|
100
|
-
* A class mixin which provides a {@link Disposable} implementation.
|
|
101
|
-
*
|
|
102
|
-
* The `use(resource)` method can be used to register {@link Disposifiable}
|
|
103
|
-
* resources which will be disposed when the object's dispose method is called.
|
|
104
|
-
*/
|
|
105
|
-
export declare const AutoDisposable: <C extends Constructor<object>>(superclass: C) => {
|
|
106
|
-
new (...arguments_: any[]): {
|
|
107
|
-
__context?: DisposableContext;
|
|
108
|
-
use(resource: null): null;
|
|
109
|
-
use(resource: undefined): undefined;
|
|
110
|
-
use(resource: Disposifiable): Disposable;
|
|
111
|
-
use(resource: Disposifiable | undefined): Disposable | undefined;
|
|
112
|
-
use(resource: Disposifiable | null | undefined): Disposable | null | undefined;
|
|
113
|
-
[Symbol.dispose](): void;
|
|
114
|
-
};
|
|
115
|
-
} & C;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/fun.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The functional programmer's toolkit.
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Create a function that always returns `value`.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts @import.meta.vitest
|
|
10
|
-
* const alwaysFive: () => number = always(5);
|
|
11
|
-
* expect(alwaysFive()).toEqual(5);
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export declare function always<A>(value: A): () => A;
|
|
15
|
-
/**
|
|
16
|
-
* The identity function: it just returns its argument unchanged.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts @import.meta.vitest
|
|
20
|
-
* expect(id(1337)).toEqual(1337);
|
|
21
|
-
* expect(id("Hello Joe!")).toEqual("Hello Joe!");
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare function id<A>(value: A): A;
|
|
25
|
-
/**
|
|
26
|
-
* A function which does nothing and returns `void`.
|
|
27
|
-
*/
|
|
28
|
-
export declare function nop(): void;
|
|
29
|
-
/**
|
|
30
|
-
* A function which applies the `+` operator to its arguments.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts @import.meta.vitest
|
|
34
|
-
* expect(sum(2, 3)).toEqual(5);
|
|
35
|
-
* expect(sum("foo", "bar")).toEqual("foobar");
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function sum(a: number, b: number): number;
|
|
39
|
-
export declare function sum(a: bigint, b: bigint): bigint;
|
|
40
|
-
export declare function sum(a: string, b: string): string;
|