@bodil/core 0.5.7 → 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.
Files changed (78) hide show
  1. package/dist/assert.js.map +1 -1
  2. package/dist/assert.test.js.map +1 -1
  3. package/dist/async/abortable-promise.d.ts +1 -1
  4. package/dist/async/abortable-promise.js +1 -1
  5. package/dist/async/abortable-promise.js.map +1 -1
  6. package/dist/async/abortable-promise.test.js +1 -1
  7. package/dist/async/abortable-promise.test.js.map +1 -1
  8. package/dist/async/emitter.test.js +1 -1
  9. package/dist/async/emitter.test.js.map +1 -1
  10. package/dist/collections/lfu-cache.js +1 -1
  11. package/dist/collections/lfu-cache.js.map +1 -1
  12. package/dist/collections/lru-cache.js +1 -1
  13. package/dist/collections/lru-cache.js.map +1 -1
  14. package/dist/decorators.test.js.map +1 -1
  15. package/dist/disposable.js.map +1 -1
  16. package/dist/disposable.test.js +1 -1
  17. package/dist/disposable.test.js.map +1 -1
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.js +2 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/logger.d.ts +19 -0
  22. package/dist/logger.js +26 -0
  23. package/dist/logger.js.map +1 -0
  24. package/dist/order.js.map +1 -1
  25. package/dist/order.test.js +1 -1
  26. package/dist/order.test.js.map +1 -1
  27. package/dist/time.test.js.map +1 -1
  28. package/package.json +29 -1
  29. package/src/assert.test.ts +1 -0
  30. package/src/assert.ts +9 -7
  31. package/src/async/abortable-promise.test.ts +2 -1
  32. package/src/async/abortable-promise.ts +17 -17
  33. package/src/async/emitter.test.ts +2 -1
  34. package/src/collections/lfu-cache.ts +1 -1
  35. package/src/collections/linked-list.ts +1 -1
  36. package/src/collections/lru-cache.ts +2 -2
  37. package/src/decorators.test.ts +1 -0
  38. package/src/decorators.ts +1 -1
  39. package/src/disposable.test.ts +4 -2
  40. package/src/disposable.ts +2 -1
  41. package/src/index.ts +2 -1
  42. package/src/logger.ts +38 -0
  43. package/src/order.test.ts +2 -1
  44. package/src/order.ts +1 -1
  45. package/src/time.test.ts +1 -0
  46. package/src/time.ts +4 -4
  47. package/dist/assert.d.ts +0 -93
  48. package/dist/assert.test.d.ts +0 -1
  49. package/dist/async/abortable-promise.test.d.ts +0 -1
  50. package/dist/async/emitter.d.ts +0 -10
  51. package/dist/async/emitter.js +0 -22
  52. package/dist/async/emitter.js.map +0 -1
  53. package/dist/async/emitter.test.d.ts +0 -1
  54. package/dist/async.d.ts +0 -28
  55. package/dist/async.js +0 -53
  56. package/dist/async.js.map +0 -1
  57. package/dist/collections/lfu-cache.d.ts +0 -45
  58. package/dist/collections/lfu-cache.test.d.ts +0 -1
  59. package/dist/collections/linked-list.d.ts +0 -47
  60. package/dist/collections/lru-cache.d.ts +0 -45
  61. package/dist/collections/lru-cache.test.d.ts +0 -1
  62. package/dist/collections.d.ts +0 -7
  63. package/dist/collections.js +0 -8
  64. package/dist/collections.js.map +0 -1
  65. package/dist/decorators.d.ts +0 -12
  66. package/dist/decorators.test.d.ts +0 -1
  67. package/dist/disposable.d.ts +0 -122
  68. package/dist/disposable.test.d.ts +0 -1
  69. package/dist/fun.d.ts +0 -40
  70. package/dist/fun.js +0 -40
  71. package/dist/fun.js.map +0 -1
  72. package/dist/order.d.ts +0 -55
  73. package/dist/order.test.d.ts +0 -1
  74. package/dist/time.d.ts +0 -80
  75. package/dist/time.test.d.ts +0 -1
  76. package/dist/types.d.ts +0 -17
  77. package/dist/types.js +0 -6
  78. package/dist/types.js.map +0 -1
@@ -1,11 +1,11 @@
1
- import type { Result } from "@bodil/opt";
2
- import { Ok, Err, None, Some } from "@bodil/opt";
1
+ import { Err, None, Ok, Some, type Result } from "@bodil/opt";
2
+
3
3
  import { present } from "../assert";
4
4
  import { isAbortError } from "../async";
5
5
 
6
6
  type Executor<A> = (
7
7
  resolve: (value: A | PromiseLike<A>) => void,
8
- reject: (error?: any) => void
8
+ reject: (error?: any) => void,
9
9
  ) => void;
10
10
 
11
11
  /** Executor function for an {@link AbortablePromise}. */
@@ -18,7 +18,7 @@ export type AbortableExecutor<A, E> = (
18
18
  * The {@link AbortSignal} governing this promise. It should be passed on
19
19
  * to any jobs launched by this function.
20
20
  */
21
- abort: AbortSignal
21
+ abort: AbortSignal,
22
22
  ) => void;
23
23
 
24
24
  type AbortablePromiseConfig<A, E> = {
@@ -53,7 +53,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
53
53
  */
54
54
  static run<A, E = Error>(
55
55
  executor: AbortableExecutor<A, E>,
56
- abort?: AbortSignal
56
+ abort?: AbortSignal,
57
57
  ): AbortablePromise<A, E> {
58
58
  return new AbortablePromise({ executor, abort });
59
59
  }
@@ -66,7 +66,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
66
66
  */
67
67
  static from<A, E = Error>(
68
68
  promise: PromiseLike<A>,
69
- abort?: AbortSignal
69
+ abort?: AbortSignal,
70
70
  ): AbortablePromise<A, E> {
71
71
  return promise instanceof AbortablePromise
72
72
  ? promise
@@ -77,7 +77,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
77
77
  }
78
78
 
79
79
  static override resolve<A, E = Error>(
80
- value?: A | PromiseLike<A>
80
+ value?: A | PromiseLike<A>,
81
81
  ): AbortablePromise<Awaited<A>, E> {
82
82
  return super.resolve(value) as AbortablePromise<Awaited<A>, E>;
83
83
  }
@@ -89,7 +89,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
89
89
 
90
90
  static allAbortable<A extends ReadonlyArray<AbortablePromise<any>>>(
91
91
  executor: (signal: AbortSignal) => A,
92
- abort?: AbortSignal
92
+ abort?: AbortSignal,
93
93
  ): AbortablePromise<{ -readonly [P in keyof A]: Awaited<A[P]> }> {
94
94
  return AbortablePromise.run((resolve, reject, abort) => {
95
95
  if (abort.aborted) {
@@ -116,7 +116,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
116
116
  reject(error);
117
117
  running.forEach((job) => job.abort());
118
118
  }
119
- }
119
+ },
120
120
  );
121
121
  });
122
122
  }, abort);
@@ -124,7 +124,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
124
124
 
125
125
  static raceAbortable<A extends AbortablePromise<any>>(
126
126
  executor: (abort: AbortSignal) => ReadonlyArray<A>,
127
- abort?: AbortSignal
127
+ abort?: AbortSignal,
128
128
  ): AbortablePromise<A extends PromiseLike<infer T> ? T : never> {
129
129
  return AbortablePromise.run((resolve, reject, abort) => {
130
130
  if (abort.aborted) {
@@ -159,8 +159,8 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
159
159
  reject(error);
160
160
  }
161
161
  }
162
- }
163
- )
162
+ },
163
+ ),
164
164
  );
165
165
  }, abort);
166
166
  }
@@ -184,7 +184,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
184
184
  const config = executorOrConfig;
185
185
  abortController = new AbortController();
186
186
  abortSignal = AbortSignal.any(
187
- [abortController.signal, config.abort].filter((s) => s !== undefined)
187
+ [abortController.signal, config.abort].filter((s) => s !== undefined),
188
188
  );
189
189
  executor = (resolve, reject) => {
190
190
  const checkAborted = () => {
@@ -213,7 +213,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
213
213
  */
214
214
  abort(reason?: string) {
215
215
  present(this.#abortController, "cannot abort a non-abortable Promise").abort(
216
- new DOMException(reason, "AbortError")
216
+ new DOMException(reason, "AbortError"),
217
217
  );
218
218
  }
219
219
 
@@ -223,7 +223,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
223
223
  get signal(): AbortSignal {
224
224
  return present(
225
225
  this.#abortSignal,
226
- "AbortablePromise: signal accessed before initialisation"
226
+ "AbortablePromise: signal accessed before initialisation",
227
227
  );
228
228
  }
229
229
 
@@ -250,7 +250,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
250
250
 
251
251
  override then<TResult1 = A, TResult2 = never>(
252
252
  onfulfilled?: ((value: A) => TResult1 | PromiseLike<TResult1>) | null,
253
- onrejected?: ((reason: E) => TResult2 | PromiseLike<TResult2>) | null
253
+ onrejected?: ((reason: E) => TResult2 | PromiseLike<TResult2>) | null,
254
254
  ): AbortablePromise<TResult1 | TResult2, E> {
255
255
  contextParent.unshift(this);
256
256
  const result = super.then(onfulfilled, onrejected) as AbortablePromise<
@@ -262,7 +262,7 @@ export class AbortablePromise<A, E = Error> extends Promise<A> implements Dispos
262
262
  }
263
263
 
264
264
  override catch<TResult = never>(
265
- onrejected?: ((reason: E) => TResult | PromiseLike<TResult>) | null
265
+ onrejected?: ((reason: E) => TResult | PromiseLike<TResult>) | null,
266
266
  ): AbortablePromise<A | TResult, E> {
267
267
  contextParent.unshift(this);
268
268
  const result = super.catch(onrejected) as AbortablePromise<A | TResult, E>;
@@ -1,6 +1,7 @@
1
1
  import { expect, test } from "vitest";
2
- import { Emitter } from "./emitter";
2
+
3
3
  import { sleep } from "../async";
4
+ import { Emitter } from "./emitter";
4
5
 
5
6
  test("Emitter", async () => {
6
7
  const e = new Emitter<number>();
@@ -1,8 +1,8 @@
1
1
  import { None, Some, type Option } from "@bodil/opt";
2
2
 
3
- import { LinkedList, type ListNode } from "./linked-list";
4
3
  import { assert } from "../assert";
5
4
  import { isDisposable } from "../disposable";
5
+ import { LinkedList, type ListNode } from "./linked-list";
6
6
 
7
7
  interface LFUNode<K> extends ListNode {
8
8
  freq: number;
@@ -128,7 +128,7 @@ export class LinkedList<Node extends ListNode> implements Iterable<Node> {
128
128
  * Iterate over the nodes in the list from head to tail.
129
129
  */
130
130
  [Symbol.iterator]: () => IterableIterator<Node> = function* (
131
- this: LinkedList<Node>
131
+ this: LinkedList<Node>,
132
132
  ): Generator<Node> {
133
133
  let node = this.head;
134
134
  while (node !== undefined) {
@@ -1,8 +1,8 @@
1
1
  import { None, Some, type Option } from "@bodil/opt";
2
- import { assert } from "../assert";
3
2
 
4
- import { LinkedList, type ListNode } from "./linked-list";
3
+ import { assert } from "../assert";
5
4
  import { isDisposable } from "../disposable";
5
+ import { LinkedList, type ListNode } from "./linked-list";
6
6
 
7
7
  interface LRUNode<K, V> extends ListNode {
8
8
  key: K;
@@ -1,4 +1,5 @@
1
1
  import { expect, test } from "vitest";
2
+
2
3
  import { cache } from "./decorators";
3
4
 
4
5
  test("@cache", () => {
package/src/decorators.ts CHANGED
@@ -14,7 +14,7 @@ const cachedValues = new WeakMap<WeakKey, Record<string | symbol, unknown>>();
14
14
  */
15
15
  export function cache<C extends object, T>(
16
16
  getter: (this: C) => T,
17
- context: ClassGetterDecoratorContext<C, T>
17
+ context: ClassGetterDecoratorContext<C, T>,
18
18
  ): (this: C) => T {
19
19
  return function (this: C): T {
20
20
  let meta = cachedValues.get(this);
@@ -1,7 +1,9 @@
1
1
  /* eslint-disable @typescript-eslint/no-empty-function */
2
- import { test, expect } from "vitest";
3
- import { DisposableContext, isDisposifiable } from "./disposable";
2
+
4
3
  import type { Unsubscribable } from "type-fest/globals";
4
+ import { expect, test } from "vitest";
5
+
6
+ import { DisposableContext, isDisposifiable } from "./disposable";
5
7
 
6
8
  test("disposes resources", () => {
7
9
  const context = new DisposableContext();
package/src/disposable.ts CHANGED
@@ -5,10 +5,11 @@
5
5
  * @module
6
6
  */
7
7
 
8
- import { assert } from "./assert";
9
8
  import type { Constructor } from "type-fest";
10
9
  import type { Unsubscribable } from "type-fest/globals";
11
10
 
11
+ import { assert } from "./assert";
12
+
12
13
  // @ts-ignore polyfill Symbol.dispose if missing
13
14
  Symbol.dispose ??= Symbol.for("Symbol.dispose");
14
15
 
package/src/index.ts CHANGED
@@ -9,8 +9,9 @@ import * as collections from "./collections";
9
9
  import * as decorators from "./decorators";
10
10
  import * as disposable from "./disposable";
11
11
  import * as fun from "./fun";
12
+ import * as logger from "./logger";
12
13
  import * as order from "./order";
13
14
  import * as time from "./time";
14
15
  import * as types from "./types";
15
16
 
16
- export { assert, async, collections, decorators, disposable, fun, order, time, types };
17
+ export { assert, async, collections, decorators, disposable, fun, logger, order, time, types };
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
@@ -1,4 +1,5 @@
1
- import { test, expect } from "vitest";
1
+ import { expect, test } from "vitest";
2
+
2
3
  import * as Order from "./order";
3
4
 
4
5
  import "@bodil/opt-vitest";
package/src/order.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * @module
4
4
  */
5
5
 
6
- import { None, type Option, Some } from "@bodil/opt";
6
+ import { None, Some, type Option } from "@bodil/opt";
7
7
 
8
8
  export enum Cmp {
9
9
  /** Less than. */
package/src/time.test.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import "temporal-polyfill/global";
2
2
 
3
3
  import { expect, test } from "vitest";
4
+
4
5
  import { time } from ".";
5
6
 
6
7
  test("time.min", () => {
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 {};
@@ -1 +0,0 @@
1
- import "temporal-polyfill/global";
@@ -1 +0,0 @@
1
- export {};
@@ -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
- }
@@ -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,53 +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
- // eslint-disable-next-line no-useless-assignment
28
- export const SchedulerAPI = {
29
- Microtask: {
30
- schedule: defer,
31
- },
32
- Macrotask: {
33
- schedule: globalThis.requestIdleCallback !== undefined
34
- ? (f) => idleCallback(f)
35
- : (f) => timeout(f, 0),
36
- },
37
- };
38
- /**
39
- * Return a promise that will resolve after the specified number of
40
- * milliseconds or {@link Temporal.Duration}.
41
- */
42
- export function sleep(duration) {
43
- return new Promise((resolve) => {
44
- setTimeout(resolve, typeof duration === "number" ? duration : duration.total("milliseconds"));
45
- });
46
- }
47
- /**
48
- * Test whether a value is an `AbortError`.
49
- */
50
- export function isAbortError(value) {
51
- return value instanceof DOMException && value.name === "AbortError";
52
- }
53
- //# 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,iDAAiD;AACjD,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
- }