@bodil/core 0.5.3 → 0.5.5

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.
@@ -123,16 +123,15 @@ export function abortController() {
123
123
  }
124
124
  class DisposableContextNative {
125
125
  constructor() {
126
- this.#stack = new DisposableStack();
126
+ this.stack = new DisposableStack();
127
127
  this.dispose = this[Symbol.dispose];
128
128
  }
129
- #stack;
130
129
  [Symbol.dispose]() {
131
130
  try {
132
- this.#stack[Symbol.dispose]();
131
+ this.stack[Symbol.dispose]();
133
132
  }
134
133
  finally {
135
- this.#stack = new DisposableStack();
134
+ this.stack = new DisposableStack();
136
135
  }
137
136
  }
138
137
  use(resource) {
@@ -140,7 +139,7 @@ class DisposableContextNative {
140
139
  return resource;
141
140
  }
142
141
  if (isDisposable(resource)) {
143
- this.#stack.use(resource);
142
+ this.stack.use(resource);
144
143
  return resource;
145
144
  }
146
145
  const dispose = extractDisposeFn(resource);
@@ -149,26 +148,25 @@ class DisposableContextNative {
149
148
  dispose();
150
149
  },
151
150
  };
152
- this.#stack.use(wrappedDisposable);
151
+ this.stack.use(wrappedDisposable);
153
152
  return wrappedDisposable;
154
153
  }
155
154
  adopt(value, onDispose) {
156
- this.#stack.adopt(value, onDispose);
155
+ this.stack.adopt(value, onDispose);
157
156
  return value;
158
157
  }
159
158
  }
160
159
  class DisposableContextPolyfill {
161
160
  constructor() {
162
- this.#disposables = new Set();
161
+ this.disposables = new Set();
163
162
  this.dispose = this[Symbol.dispose];
164
163
  }
165
- #disposables;
166
164
  [Symbol.dispose]() {
167
- if (this.#disposables.size === 0) {
165
+ if (this.disposables.size === 0) {
168
166
  return;
169
167
  }
170
168
  const errors = [];
171
- for (const disposable of Array.from(this.#disposables).reverse()) {
169
+ for (const disposable of Array.from(this.disposables).reverse()) {
172
170
  try {
173
171
  disposable[Symbol.dispose]();
174
172
  }
@@ -176,7 +174,7 @@ class DisposableContextPolyfill {
176
174
  errors.push(e);
177
175
  }
178
176
  }
179
- assert(this.#disposables.size === 0, "DisposableContext: disposables remaining in context after dispose, this isn't supposed to happen");
177
+ assert(this.disposables.size === 0, "DisposableContext: disposables remaining in context after dispose, this isn't supposed to happen");
180
178
  if (errors.length > 0) {
181
179
  throw errors.reduce((prev, next) => new SuppressedError(next, prev));
182
180
  }
@@ -185,7 +183,7 @@ class DisposableContextPolyfill {
185
183
  if (resource === undefined || resource === null) {
186
184
  return resource;
187
185
  }
188
- let disposables = this.#disposables;
186
+ let disposables = this.disposables;
189
187
  const dispose = extractDisposeFn(resource);
190
188
  const wrappedDisposable = {
191
189
  [Symbol.dispose]() {
@@ -235,16 +233,19 @@ export const DisposableContext = Object.hasOwn(globalThis, "DisposableStack")
235
233
  * resources which will be disposed when the object's dispose method is called.
236
234
  */
237
235
  export const AutoDisposable = (superclass) => class extends superclass {
238
- #_context = new DisposableContext();
236
+ constructor() {
237
+ super(...arguments);
238
+ this.__context = new DisposableContext();
239
+ }
239
240
  [Symbol.dispose]() {
240
- if (this.#_context !== undefined) {
241
- this.#_context.dispose();
242
- this.#_context = undefined;
241
+ if (this.__context !== undefined) {
242
+ this.__context.dispose();
243
+ this.__context = undefined;
243
244
  }
244
245
  }
245
246
  use(resource) {
246
- assert(this.#_context, "AutoDisposable: use() called after dispose");
247
- return this.#_context.use(resource);
247
+ assert(this.__context, "AutoDisposable: use() called after dispose");
248
+ return this.__context.use(resource);
248
249
  }
249
250
  };
250
251
  //# sourceMappingURL=disposable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"disposable.js","sourceRoot":"","sources":["../src/disposable.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC,gDAAgD;AAChD,MAAM,CAAC,OAAO,KAAK,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACvC,IAAI,CAAC;QACD,OAAO,OA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AED,KAAK,CAAI,KAAQ,EAAE,SAA6B;QAC5C,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACjC,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAmC,MAAM,CAAC,MAAM,CAC1E,UAAU,EACV,iBAAiB,CACpB;IACG,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,yBAAyB,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAgC,UAAa,EAAE,EAAE,CAC3E,KAAM,SAAQ,UAAU;IAAxB;;QACI,cAAS,GAAuB,IAAI,iBAAiB,EAAE,CAAC;IAkB5D,CAAC;IAhBG,CAAC,MAAM,CAAC,OAAO,CAAC;QACZ,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;YACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC/B,CAAC;IACL,CAAC;IAOD,GAAG,CAAC,QAA0C;QAC1C,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,4CAA4C,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;CACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bodil/core",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "My TypeScript standard library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -79,29 +79,29 @@
79
79
  "access": "public"
80
80
  },
81
81
  "dependencies": {
82
- "@bodil/opt": "^0.4.3",
83
- "type-fest": "^5.3.1"
82
+ "@bodil/opt": "^1.0.0",
83
+ "type-fest": "^5.6.0"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@bodil/opt-vitest": "^1.1.0",
87
- "@eslint/eslintrc": "^3.3.3",
88
- "@eslint/js": "^9.39.2",
89
- "@typescript-eslint/eslint-plugin": "^8.52.0",
90
- "@typescript-eslint/parser": "^8.52.0",
87
+ "@eslint/eslintrc": "^3.3.5",
88
+ "@eslint/js": "^9.39.4",
89
+ "@typescript-eslint/eslint-plugin": "^8.60.0",
90
+ "@typescript-eslint/parser": "^8.60.0",
91
91
  "@typhonjs-typedoc/ts-lib-docs": "^2024.12.25",
92
- "eslint": "^9.39.2",
92
+ "eslint": "^9.39.4",
93
93
  "eslint-config-prettier": "^10.1.8",
94
94
  "eslint-plugin-jsdoc": "^58.1.1",
95
95
  "globals": "^16.5.0",
96
96
  "npm-run-all2": "^8.0.4",
97
- "prettier": "^3.7.4",
98
- "temporal-polyfill": "^0.3.0",
99
- "typedoc": "^0.28.15",
97
+ "prettier": "^3.8.3",
98
+ "temporal-polyfill": "^0.3.2",
99
+ "typedoc": "^0.28.19",
100
100
  "typedoc-plugin-extras": "^4.0.1",
101
- "typedoc-plugin-mdn-links": "^5.0.10",
101
+ "typedoc-plugin-mdn-links": "^5.1.1",
102
102
  "typedoc-theme-fresh": "^0.2.3",
103
103
  "typescript": "^5.9.3",
104
- "vite-plugin-doctest": "^1.1.1",
104
+ "vite-plugin-doctest": "^1.2.2",
105
105
  "vitest": "^3.2.4"
106
106
  },
107
107
  "scripts": {
package/src/disposable.ts CHANGED
@@ -80,7 +80,7 @@ export function timeout(fn: () => void, timeout: number | Temporal.Duration): Di
80
80
  disposable[Symbol.dispose]();
81
81
  fn();
82
82
  },
83
- typeof timeout === "number" ? timeout : timeout.total("milliseconds")
83
+ typeof timeout === "number" ? timeout : timeout.total("milliseconds"),
84
84
  );
85
85
  const disposable = toDisposable(() => {
86
86
  if (id !== null) {
@@ -97,7 +97,7 @@ export function timeout(fn: () => void, timeout: number | Temporal.Duration): Di
97
97
  export function interval(fn: () => void, interval: number | Temporal.Duration): Disposable {
98
98
  const id = globalThis.setInterval(
99
99
  fn,
100
- typeof interval === "number" ? interval : interval.total("milliseconds")
100
+ typeof interval === "number" ? interval : interval.total("milliseconds"),
101
101
  );
102
102
  return toDisposable(() => {
103
103
  clearInterval(id);
@@ -106,7 +106,7 @@ export function interval(fn: () => void, interval: number | Temporal.Duration):
106
106
 
107
107
  export function idleCallback(
108
108
  callback: IdleRequestCallback,
109
- options?: IdleRequestOptions
109
+ options?: IdleRequestOptions,
110
110
  ): Disposable {
111
111
  let id: number | null = globalThis.requestIdleCallback((deadline: IdleDeadline) => {
112
112
  id = null;
@@ -177,14 +177,14 @@ export interface DisposableContext extends Disposable {
177
177
  }
178
178
 
179
179
  class DisposableContextNative implements DisposableContext {
180
- #stack: DisposableStack = new DisposableStack();
180
+ private stack: DisposableStack = new DisposableStack();
181
181
 
182
182
  dispose = this[Symbol.dispose];
183
183
  [Symbol.dispose]() {
184
184
  try {
185
- this.#stack[Symbol.dispose]();
185
+ this.stack[Symbol.dispose]();
186
186
  } finally {
187
- this.#stack = new DisposableStack();
187
+ this.stack = new DisposableStack();
188
188
  }
189
189
  }
190
190
 
@@ -198,7 +198,7 @@ class DisposableContextNative implements DisposableContext {
198
198
  return resource;
199
199
  }
200
200
  if (isDisposable(resource)) {
201
- this.#stack.use(resource);
201
+ this.stack.use(resource);
202
202
  return resource;
203
203
  }
204
204
  const dispose = extractDisposeFn(resource);
@@ -207,26 +207,26 @@ class DisposableContextNative implements DisposableContext {
207
207
  dispose();
208
208
  },
209
209
  };
210
- this.#stack.use(wrappedDisposable);
210
+ this.stack.use(wrappedDisposable);
211
211
  return wrappedDisposable;
212
212
  }
213
213
 
214
214
  adopt<A>(value: A, onDispose: (value: A) => void): A {
215
- this.#stack.adopt(value, onDispose);
215
+ this.stack.adopt(value, onDispose);
216
216
  return value;
217
217
  }
218
218
  }
219
219
 
220
220
  class DisposableContextPolyfill implements DisposableContext {
221
- readonly #disposables = new Set<Disposable>();
221
+ private readonly disposables = new Set<Disposable>();
222
222
 
223
223
  dispose = this[Symbol.dispose];
224
224
  [Symbol.dispose](): void {
225
- if (this.#disposables.size === 0) {
225
+ if (this.disposables.size === 0) {
226
226
  return;
227
227
  }
228
228
  const errors: Array<unknown> = [];
229
- for (const disposable of Array.from(this.#disposables).reverse()) {
229
+ for (const disposable of Array.from(this.disposables).reverse()) {
230
230
  try {
231
231
  disposable[Symbol.dispose]();
232
232
  } catch (e) {
@@ -234,8 +234,8 @@ class DisposableContextPolyfill implements DisposableContext {
234
234
  }
235
235
  }
236
236
  assert(
237
- this.#disposables.size === 0,
238
- "DisposableContext: disposables remaining in context after dispose, this isn't supposed to happen"
237
+ this.disposables.size === 0,
238
+ "DisposableContext: disposables remaining in context after dispose, this isn't supposed to happen",
239
239
  );
240
240
  if (errors.length > 0) {
241
241
  throw errors.reduce((prev, next) => new SuppressedError(next, prev));
@@ -251,7 +251,7 @@ class DisposableContextPolyfill implements DisposableContext {
251
251
  if (resource === undefined || resource === null) {
252
252
  return resource;
253
253
  }
254
- let disposables: Set<Disposable> | undefined = this.#disposables;
254
+ let disposables: Set<Disposable> | undefined = this.disposables;
255
255
  const dispose = extractDisposeFn(resource);
256
256
  const wrappedDisposable = {
257
257
  [Symbol.dispose](): void {
@@ -292,7 +292,10 @@ class DisposableContextPolyfill implements DisposableContext {
292
292
  *
293
293
  * @class
294
294
  */
295
- export const DisposableContext = Object.hasOwn(globalThis, "DisposableStack")
295
+ export const DisposableContext: Constructor<DisposableContext> = Object.hasOwn(
296
+ globalThis,
297
+ "DisposableStack",
298
+ )
296
299
  ? DisposableContextNative
297
300
  : DisposableContextPolyfill;
298
301
 
@@ -304,12 +307,12 @@ export const DisposableContext = Object.hasOwn(globalThis, "DisposableStack")
304
307
  */
305
308
  export const AutoDisposable = <C extends Constructor<object>>(superclass: C) =>
306
309
  class extends superclass implements Disposable {
307
- #_context?: DisposableContext = new DisposableContext();
310
+ __context?: DisposableContext = new DisposableContext();
308
311
 
309
312
  [Symbol.dispose](): void {
310
- if (this.#_context !== undefined) {
311
- this.#_context.dispose();
312
- this.#_context = undefined;
313
+ if (this.__context !== undefined) {
314
+ this.__context.dispose();
315
+ this.__context = undefined;
313
316
  }
314
317
  }
315
318
 
@@ -319,7 +322,7 @@ export const AutoDisposable = <C extends Constructor<object>>(superclass: C) =>
319
322
  use(resource: Disposifiable | undefined): Disposable | undefined;
320
323
  use(resource: Disposifiable | null | undefined): Disposable | null | undefined;
321
324
  use(resource: Disposifiable | null | undefined): Disposable | null | undefined {
322
- assert(this.#_context, "AutoDisposable: use() called after dispose");
323
- return this.#_context.use(resource);
325
+ assert(this.__context, "AutoDisposable: use() called after dispose");
326
+ return this.__context.use(resource);
324
327
  }
325
328
  };
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,71 +0,0 @@
1
- import type { Result } from "@bodil/opt";
2
- /** Executor function for an {@link AbortablePromise}. */
3
- export type AbortableExecutor<A, E> = (
4
- /** Call this function to resolve the promise. */
5
- resolve: (value: A | PromiseLike<A>) => void,
6
- /** Call this function to reject the promise. */
7
- reject: (error: E) => void,
8
- /**
9
- * The {@link AbortSignal} governing this promise. It should be passed on
10
- * to any jobs launched by this function.
11
- */
12
- abort: AbortSignal) => void;
13
- /**
14
- * A promise that can be aborted using an {@link AbortSignal}.
15
- *
16
- * @template A The type of the resolved value of this promise.
17
- * @template E The type of the rejected value of this promise. Defaults to
18
- * {@link Error}, and it's usually best to keep it that way.
19
- */
20
- export declare class AbortablePromise<A, E = Error> extends Promise<A> implements Disposable {
21
- #private;
22
- /**
23
- * Create a new {@link AbortablePromise} using an {@link AbortableExecutor}
24
- * function and an optional {@link AbortSignal}.
25
- *
26
- * @param executor A function which receives two callbacks `resolve` and
27
- * `reject` used to resolve or reject the promise, and an
28
- * {@link AbortSignal} which should be passed on to any abortable jobs
29
- * triggered by the function.
30
- * @param abort An optional {@link AbortSignal} which can be used to abort
31
- * the promise externally instead of calling its `abort()` method.
32
- */
33
- static run<A, E = Error>(executor: AbortableExecutor<A, E>, abort?: AbortSignal): AbortablePromise<A, E>;
34
- /**
35
- * Wrap any {@link PromiseLike} in an {@link AbortablePromise}.
36
- *
37
- * This will make the promise resolution abortable, but it has no way of
38
- * aborting the promise while it's running.
39
- */
40
- static from<A, E = Error>(promise: PromiseLike<A>, abort?: AbortSignal): AbortablePromise<A, E>;
41
- static resolve<A, E = Error>(value?: A | PromiseLike<A>): AbortablePromise<Awaited<A>, E>;
42
- static reject<A = never, E = Error>(reason?: any): AbortablePromise<A, E>;
43
- static allAbortable<A extends ReadonlyArray<AbortablePromise<any>>>(executor: (signal: AbortSignal) => A, abort?: AbortSignal): AbortablePromise<{
44
- -readonly [P in keyof A]: Awaited<A[P]>;
45
- }>;
46
- static raceAbortable<A extends AbortablePromise<any>>(executor: (abort: AbortSignal) => ReadonlyArray<A>, abort?: AbortSignal): AbortablePromise<A extends PromiseLike<infer T> ? T : never>;
47
- private constructor();
48
- /**
49
- * Abort this promise.
50
- */
51
- abort(reason?: string): void;
52
- /**
53
- * The {@link AbortSignal} attached to this promise.
54
- */
55
- get signal(): AbortSignal;
56
- /**
57
- * True if the promise has been aborted.
58
- */
59
- get aborted(): boolean;
60
- /**
61
- * Convert this promise into a promise that returns a {@link Result}.
62
- *
63
- * If the promise throws, it will return an {@link Err} instead of
64
- * rejecting.
65
- */
66
- result(): AbortablePromise<Result<A, E>, never>;
67
- [Symbol.dispose](): void;
68
- then<TResult1 = A, TResult2 = never>(onfulfilled?: ((value: A) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: E) => TResult2 | PromiseLike<TResult2>) | null): AbortablePromise<TResult1 | TResult2, E>;
69
- catch<TResult = never>(onrejected?: ((reason: E) => TResult | PromiseLike<TResult>) | null): AbortablePromise<A | TResult, E>;
70
- finally(onfinally?: (() => void) | null): AbortablePromise<A, E>;
71
- }
@@ -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 +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
- };
@@ -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";
@@ -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";
@@ -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 {};
@@ -1,138 +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
- declare class DisposableContextNative implements DisposableContext {
81
- #private;
82
- dispose: () => void;
83
- [Symbol.dispose](): void;
84
- use(resource: null): null;
85
- use(resource: undefined): undefined;
86
- use(resource: Disposifiable): Disposable;
87
- use(resource: Disposifiable | undefined): Disposable | undefined;
88
- use(resource: Disposifiable | null | undefined): Disposable | null | undefined;
89
- adopt<A>(value: A, onDispose: (value: A) => void): A;
90
- }
91
- declare class DisposableContextPolyfill implements DisposableContext {
92
- #private;
93
- dispose: () => void;
94
- [Symbol.dispose](): void;
95
- use(resource: null): null;
96
- use(resource: undefined): undefined;
97
- use(resource: Disposifiable): Disposable;
98
- use(resource: Disposifiable | undefined): Disposable | undefined;
99
- use(resource: Disposifiable | null | undefined): Disposable | null | undefined;
100
- adopt<A>(value: A, onDispose: (value: A) => void): A;
101
- }
102
- /**
103
- * A reentrant version of {@link DisposableStack}.
104
- *
105
- * This maintains a list of {@link Disposable}s, added with the
106
- * {@link DisposableContext.use} method, which will all be disposed when you
107
- * dispose of the {@link DisposableContext} itself.
108
- *
109
- * Where this differs from {@link DisposableStack} is that disposing it only
110
- * resets it after disposing of its dependents, and you can reuse it as many
111
- * times as you like. This is very handy for managing lifecycle resources, eg. a
112
- * web component can allocate resources in its `connectedCallback` method and
113
- * during its connected lifecycle phase which can all be disposed in
114
- * `disconnectedCallback` with a single call to
115
- * {@link DisposableContext.dispose}, and it's instantly ready to go again on
116
- * reconnect.
117
- *
118
- * @class
119
- */
120
- export declare const DisposableContext: typeof DisposableContextNative | typeof DisposableContextPolyfill;
121
- /**
122
- * A class mixin which provides a {@link Disposable} implementation.
123
- *
124
- * The `use(resource)` method can be used to register {@link Disposifiable}
125
- * resources which will be disposed when the object's dispose method is called.
126
- */
127
- export declare const AutoDisposable: <C extends Constructor<object>>(superclass: C) => {
128
- new (...arguments_: any[]): {
129
- "__#private@#_context"?: DisposableContext;
130
- use(resource: null): null;
131
- use(resource: undefined): undefined;
132
- use(resource: Disposifiable): Disposable;
133
- use(resource: Disposifiable | undefined): Disposable | undefined;
134
- use(resource: Disposifiable | null | undefined): Disposable | null | undefined;
135
- [Symbol.dispose](): void;
136
- };
137
- } & C;
138
- export {};
@@ -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;
package/dist/index.d.ts DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * My personal JavaScript standard library.
3
- * @module
4
- */
5
- import * as assert from "./assert";
6
- import * as async from "./async";
7
- import * as collections from "./collections";
8
- import * as decorators from "./decorators";
9
- import * as disposable from "./disposable";
10
- import * as fun from "./fun";
11
- import * as order from "./order";
12
- import * as time from "./time";
13
- import * as types from "./types";
14
- export { assert, async, collections, decorators, disposable, fun, order, time, types };
package/dist/order.d.ts DELETED
@@ -1,55 +0,0 @@
1
- /**
2
- * Sorting and ordering.
3
- * @module
4
- */
5
- import { type Option } from "@bodil/opt";
6
- export declare enum Cmp {
7
- /** Less than. */
8
- LT = -1,
9
- /** Equal to. */
10
- EQ = 0,
11
- /** Greater than. */
12
- GT = 1
13
- }
14
- /**
15
- * An order function is a function which is used to compare two items, returning
16
- * a {@link Cmp} to describe the first item in relation to the second, eg.
17
- * {@link Cmp.GT} says the first item is greater than the second item.
18
- */
19
- export type OrderFn<A> = (left: A, right: A) => Cmp;
20
- /**
21
- * The set of types which can be compared using the `<` and `>` operators.
22
- */
23
- export type OperatorComparable = number | string | bigint | Date;
24
- /**
25
- * An order function which sorts {@link OperatorComparable} items in ascending
26
- * order.
27
- */
28
- export declare function ascending<A extends OperatorComparable>(left: A, right: A): Cmp;
29
- /**
30
- * An order function which sorts {@link OperatorComparable} items in descending
31
- * order.
32
- */
33
- export declare function descending<A extends OperatorComparable>(left: A, right: A): Cmp;
34
- /**
35
- * Take an order function and invert its order.
36
- */
37
- export declare function reverse<T>(fn: OrderFn<T>): OrderFn<T>;
38
- /**
39
- * Given a value, a sorted array and a comparison function by which the array
40
- * has been sorted, find the lowest index at which the value could be inserted
41
- * while maintaining sort order.
42
- */
43
- export declare function bisectLow<A>(cmp: OrderFn<A>, array: Array<A>, key: A): number;
44
- /**
45
- * Given a value, a sorted array and a comparison function by which the array
46
- * has been sorted, find the highest index at which the value could be inserted
47
- * while maintaining sort order.
48
- */
49
- export declare function bisectHigh<A>(cmp: OrderFn<A>, array: Array<A>, key: A): number;
50
- /**
51
- * Given a value, a sorted array and a comparison function by which the array
52
- * has been sorted, find the index of the specific value if it exists in the
53
- * array.
54
- */
55
- export declare function find<A>(cmp: OrderFn<A>, array: Array<A>, key: A): Option<number>;
@@ -1 +0,0 @@
1
- import "@bodil/opt-vitest";
package/dist/time.d.ts DELETED
@@ -1,80 +0,0 @@
1
- /**
2
- * Utilities for working with {@link Temporal}.
3
- * @module
4
- */
5
- /**
6
- * Test if the given {@link Temporal.Instant} comes before a certain moment
7
- * in time.
8
- *
9
- * If `other` is unspecified, compare with the current time.
10
- *
11
- * If `other` is a {@link Temporal.Duration}, compare with that duration
12
- * subtracted from the current time.
13
- *
14
- * If `other` is a {@link Temporal.Instant}, compare with that instant.
15
- *
16
- * @example
17
- * time.isBefore(instant) // is `instant` in the past?
18
- * time.isBefore(instant, otherInstant) // is `instant` before `otherInstant`?
19
- * time.isBefore(instant, duration) // is `instant` more than `duration` ago?
20
- */
21
- export declare function isBefore(instant: Temporal.Instant, other?: Temporal.Instant | Temporal.Duration): boolean;
22
- /**
23
- * Test if the given {@link Temporal.Instant} comes after a certain moment in
24
- * time.
25
- *
26
- * If `other` is unspecified, compare with the current time.
27
- *
28
- * If `other` is a {@link Temporal.Duration}, compare with that duration added
29
- * to the current time.
30
- *
31
- * If `other` is a {@link Temporal.Instant}, compare with that instant.
32
- *
33
- * @example
34
- * time.isAfter(instant) // is `instant` in the future?
35
- * time.isAfter(instant, otherInstant) // is `instant` after `otherInstant`?
36
- * time.isAfter(instant, duration) // is `instant` more than `duration` into the future?
37
- */
38
- export declare function isAfter(instant: Temporal.Instant, other?: Temporal.Instant | Temporal.Duration): boolean;
39
- /**
40
- * Find the shortest duration or earliest time given a series of
41
- * {@link Temporal.Duration}s or {@link Temporal.Instant}s.
42
- */
43
- export declare function min<T extends Temporal.Duration | Temporal.Instant>(...rest: Array<T>): T;
44
- /**
45
- * Find the longest duration or latest time given a series of
46
- * {@link Temporal.Duration}s or {@link Temporal.Instant}s.
47
- */
48
- export declare function max<T extends Temporal.Duration | Temporal.Instant>(...rest: Array<T>): T;
49
- /**
50
- * The current time as a {@link Temporal.Instant}.
51
- *
52
- * A shorthand for `Temporal.Now.instant()`.
53
- */
54
- export declare function now(): Temporal.Instant;
55
- /**
56
- * The current time as a {@link Temporal.ZonedDateTime}.
57
- *
58
- * A shorthand for `Temporal.Now.zonedDateTimeISO()`.
59
- */
60
- export declare function nowZ(): Temporal.ZonedDateTime;
61
- /**
62
- * Construct a duration of the given number of days.
63
- */
64
- export declare function days(days: number): Temporal.Duration;
65
- /**
66
- * Construct a duration of the given number of hours.
67
- */
68
- export declare function hours(hours: number): Temporal.Duration;
69
- /**
70
- * Construct a duration of the given number of minutes.
71
- */
72
- export declare function minutes(minutes: number): Temporal.Duration;
73
- /**
74
- * Construct a duration of the given number of seconds.
75
- */
76
- export declare function seconds(seconds: number): Temporal.Duration;
77
- /**
78
- * Construct a duration of the given number of milliseconds.
79
- */
80
- export declare function millis(milliseconds: number): Temporal.Duration;
@@ -1 +0,0 @@
1
- import "temporal-polyfill/global";
package/dist/types.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Utility types.
3
- * @module
4
- */
5
- /**
6
- * Constructs a type by excluding `undefined` from `T`.
7
- *
8
- * This is like {@link NonNullable} but it only removes `undefined`, not `null`.
9
- */
10
- export type Present<T> = T extends undefined ? never : T;
11
- /**
12
- * Interface for classes which implement equality checking.
13
- */
14
- export interface Equals {
15
- /** Tests whether a given value is equal to this value. */
16
- equals(other: unknown): boolean;
17
- }