@bodil/core 0.5.3 → 0.5.4

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 (74) hide show
  1. package/package.json +1 -1
  2. package/src/disposable.ts +25 -22
  3. package/dist/assert.d.ts +0 -93
  4. package/dist/assert.js +0 -217
  5. package/dist/assert.js.map +0 -1
  6. package/dist/assert.test.d.ts +0 -1
  7. package/dist/assert.test.js +0 -51
  8. package/dist/assert.test.js.map +0 -1
  9. package/dist/async/abortable-promise.d.ts +0 -71
  10. package/dist/async/abortable-promise.js +0 -203
  11. package/dist/async/abortable-promise.js.map +0 -1
  12. package/dist/async/abortable-promise.test.d.ts +0 -1
  13. package/dist/async/abortable-promise.test.js +0 -134
  14. package/dist/async/abortable-promise.test.js.map +0 -1
  15. package/dist/async/emitter.d.ts +0 -10
  16. package/dist/async/emitter.js +0 -22
  17. package/dist/async/emitter.js.map +0 -1
  18. package/dist/async/emitter.test.d.ts +0 -1
  19. package/dist/async/emitter.test.js +0 -49
  20. package/dist/async/emitter.test.js.map +0 -1
  21. package/dist/async.d.ts +0 -28
  22. package/dist/async.js +0 -52
  23. package/dist/async.js.map +0 -1
  24. package/dist/collections/lfu-cache.d.ts +0 -45
  25. package/dist/collections/lfu-cache.js +0 -107
  26. package/dist/collections/lfu-cache.js.map +0 -1
  27. package/dist/collections/lfu-cache.test.d.ts +0 -1
  28. package/dist/collections/lfu-cache.test.js +0 -29
  29. package/dist/collections/lfu-cache.test.js.map +0 -1
  30. package/dist/collections/linked-list.d.ts +0 -47
  31. package/dist/collections/linked-list.js +0 -129
  32. package/dist/collections/linked-list.js.map +0 -1
  33. package/dist/collections/lru-cache.d.ts +0 -45
  34. package/dist/collections/lru-cache.js +0 -84
  35. package/dist/collections/lru-cache.js.map +0 -1
  36. package/dist/collections/lru-cache.test.d.ts +0 -1
  37. package/dist/collections/lru-cache.test.js +0 -27
  38. package/dist/collections/lru-cache.test.js.map +0 -1
  39. package/dist/collections.d.ts +0 -7
  40. package/dist/collections.js +0 -8
  41. package/dist/collections.js.map +0 -1
  42. package/dist/decorators.d.ts +0 -12
  43. package/dist/decorators.js +0 -28
  44. package/dist/decorators.js.map +0 -1
  45. package/dist/decorators.test.d.ts +0 -1
  46. package/dist/decorators.test.js +0 -71
  47. package/dist/decorators.test.js.map +0 -1
  48. package/dist/disposable.d.ts +0 -138
  49. package/dist/disposable.js +0 -250
  50. package/dist/disposable.js.map +0 -1
  51. package/dist/disposable.test.d.ts +0 -1
  52. package/dist/disposable.test.js +0 -54
  53. package/dist/disposable.test.js.map +0 -1
  54. package/dist/fun.d.ts +0 -40
  55. package/dist/fun.js +0 -40
  56. package/dist/fun.js.map +0 -1
  57. package/dist/index.d.ts +0 -14
  58. package/dist/index.js +0 -15
  59. package/dist/index.js.map +0 -1
  60. package/dist/order.d.ts +0 -55
  61. package/dist/order.js +0 -98
  62. package/dist/order.js.map +0 -1
  63. package/dist/order.test.d.ts +0 -1
  64. package/dist/order.test.js +0 -63
  65. package/dist/order.test.js.map +0 -1
  66. package/dist/time.d.ts +0 -80
  67. package/dist/time.js +0 -130
  68. package/dist/time.js.map +0 -1
  69. package/dist/time.test.d.ts +0 -1
  70. package/dist/time.test.js +0 -38
  71. package/dist/time.test.js.map +0 -1
  72. package/dist/types.d.ts +0 -17
  73. package/dist/types.js +0 -6
  74. package/dist/types.js.map +0 -1
@@ -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,250 +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 { assert } from "./assert";
8
- // @ts-ignore polyfill Symbol.dispose if missing
9
- Symbol.dispose ??= Symbol.for("Symbol.dispose");
10
- /**
11
- * Test whether something implements {@link Disposable}.
12
- */
13
- export function isDisposable(value) {
14
- try {
15
- return typeof value[Symbol.dispose] === "function";
16
- }
17
- catch (_e) {
18
- return false;
19
- }
20
- }
21
- function extractDisposeFn(value) {
22
- if (typeof value === "function") {
23
- return value;
24
- }
25
- if (typeof value === "object") {
26
- if (typeof value[Symbol.dispose] === "function") {
27
- return value[Symbol.dispose].bind(value);
28
- }
29
- if (typeof value.unsubscribe === "function") {
30
- return value.unsubscribe.bind(value);
31
- }
32
- }
33
- throw new Error("toDisposable(): don't know how to convert given value to disposable");
34
- }
35
- /**
36
- * Construct a new {@link Disposable} out of any {@link Disposifiable}.
37
- *
38
- * This constructs a new object which implements {@link Disposable}, and nothing
39
- * else. The new object's dispose method will dispose of the original
40
- * {@link Disposifiable}, and ensure that this happens only once, regardless of
41
- * how many times the dispose method is called.
42
- */
43
- export function toDisposable(value) {
44
- let disposed = false;
45
- const disposeFn = extractDisposeFn(value);
46
- return {
47
- [Symbol.dispose]() {
48
- if (!disposed) {
49
- disposed = true;
50
- disposeFn();
51
- }
52
- },
53
- };
54
- }
55
- /**
56
- * Call {@link setTimeout} with the provided callback and return a
57
- * {@link Disposable} which will cancel the timeout when disposed.
58
- */
59
- export function timeout(fn, timeout) {
60
- let id = globalThis.setTimeout(() => {
61
- id = null;
62
- disposable[Symbol.dispose]();
63
- fn();
64
- }, typeof timeout === "number" ? timeout : timeout.total("milliseconds"));
65
- const disposable = toDisposable(() => {
66
- if (id !== null) {
67
- clearTimeout(id);
68
- }
69
- });
70
- return disposable;
71
- }
72
- /**
73
- * Call {@link setInterval} with the provided callback and return a
74
- * {@link Disposable} which will cancel the interval when disposed.
75
- */
76
- export function interval(fn, interval) {
77
- const id = globalThis.setInterval(fn, typeof interval === "number" ? interval : interval.total("milliseconds"));
78
- return toDisposable(() => {
79
- clearInterval(id);
80
- });
81
- }
82
- export function idleCallback(callback, options) {
83
- let id = globalThis.requestIdleCallback((deadline) => {
84
- id = null;
85
- disposable[Symbol.dispose]();
86
- callback(deadline);
87
- }, options);
88
- const disposable = toDisposable(() => {
89
- if (id !== null) {
90
- globalThis.cancelIdleCallback(id);
91
- }
92
- });
93
- return disposable;
94
- }
95
- /**
96
- * An implementation of {@link AbortController} which also implements
97
- * {@link Disposable}.
98
- *
99
- * Disposing the controller automatically triggers the abort signal.
100
- */
101
- export class DisposableAbortController {
102
- #controller = new AbortController();
103
- get signal() {
104
- return this.#controller.signal;
105
- }
106
- abort(reason) {
107
- this.#controller.abort(reason);
108
- this.#controller = new AbortController();
109
- }
110
- [Symbol.dispose]() {
111
- this.abort("disposed");
112
- }
113
- }
114
- /**
115
- * Create an {@link AbortController} which also implements {@link Disposable}.
116
- *
117
- * Disposing the controller automatically triggers the abort signal.
118
- *
119
- * @returns A {@link DisposableAbortController}.
120
- */
121
- export function abortController() {
122
- return new DisposableAbortController();
123
- }
124
- class DisposableContextNative {
125
- constructor() {
126
- this.#stack = new DisposableStack();
127
- this.dispose = this[Symbol.dispose];
128
- }
129
- #stack;
130
- [Symbol.dispose]() {
131
- try {
132
- this.#stack[Symbol.dispose]();
133
- }
134
- finally {
135
- this.#stack = new DisposableStack();
136
- }
137
- }
138
- use(resource) {
139
- if (resource === undefined || resource === null) {
140
- return resource;
141
- }
142
- if (isDisposable(resource)) {
143
- this.#stack.use(resource);
144
- return resource;
145
- }
146
- const dispose = extractDisposeFn(resource);
147
- const wrappedDisposable = {
148
- [Symbol.dispose]() {
149
- dispose();
150
- },
151
- };
152
- this.#stack.use(wrappedDisposable);
153
- return wrappedDisposable;
154
- }
155
- adopt(value, onDispose) {
156
- this.#stack.adopt(value, onDispose);
157
- return value;
158
- }
159
- }
160
- class DisposableContextPolyfill {
161
- constructor() {
162
- this.#disposables = new Set();
163
- this.dispose = this[Symbol.dispose];
164
- }
165
- #disposables;
166
- [Symbol.dispose]() {
167
- if (this.#disposables.size === 0) {
168
- return;
169
- }
170
- const errors = [];
171
- for (const disposable of Array.from(this.#disposables).reverse()) {
172
- try {
173
- disposable[Symbol.dispose]();
174
- }
175
- catch (e) {
176
- errors.push(e);
177
- }
178
- }
179
- assert(this.#disposables.size === 0, "DisposableContext: disposables remaining in context after dispose, this isn't supposed to happen");
180
- if (errors.length > 0) {
181
- throw errors.reduce((prev, next) => new SuppressedError(next, prev));
182
- }
183
- }
184
- use(resource) {
185
- if (resource === undefined || resource === null) {
186
- return resource;
187
- }
188
- let disposables = this.#disposables;
189
- const dispose = extractDisposeFn(resource);
190
- const wrappedDisposable = {
191
- [Symbol.dispose]() {
192
- try {
193
- if (disposables?.delete(wrappedDisposable) === true) {
194
- dispose();
195
- }
196
- }
197
- finally {
198
- disposables = undefined;
199
- }
200
- },
201
- };
202
- disposables.add(wrappedDisposable);
203
- return wrappedDisposable;
204
- }
205
- adopt(value, onDispose) {
206
- this.use(() => onDispose(value));
207
- return value;
208
- }
209
- }
210
- /**
211
- * A reentrant version of {@link DisposableStack}.
212
- *
213
- * This maintains a list of {@link Disposable}s, added with the
214
- * {@link DisposableContext.use} method, which will all be disposed when you
215
- * dispose of the {@link DisposableContext} itself.
216
- *
217
- * Where this differs from {@link DisposableStack} is that disposing it only
218
- * resets it after disposing of its dependents, and you can reuse it as many
219
- * times as you like. This is very handy for managing lifecycle resources, eg. a
220
- * web component can allocate resources in its `connectedCallback` method and
221
- * during its connected lifecycle phase which can all be disposed in
222
- * `disconnectedCallback` with a single call to
223
- * {@link DisposableContext.dispose}, and it's instantly ready to go again on
224
- * reconnect.
225
- *
226
- * @class
227
- */
228
- export const DisposableContext = Object.hasOwn(globalThis, "DisposableStack")
229
- ? DisposableContextNative
230
- : DisposableContextPolyfill;
231
- /**
232
- * A class mixin which provides a {@link Disposable} implementation.
233
- *
234
- * The `use(resource)` method can be used to register {@link Disposifiable}
235
- * resources which will be disposed when the object's dispose method is called.
236
- */
237
- export const AutoDisposable = (superclass) => class extends superclass {
238
- #_context = new DisposableContext();
239
- [Symbol.dispose]() {
240
- if (this.#_context !== undefined) {
241
- this.#_context.dispose();
242
- this.#_context = undefined;
243
- }
244
- }
245
- use(resource) {
246
- assert(this.#_context, "AutoDisposable: use() called after dispose");
247
- return this.#_context.use(resource);
248
- }
249
- };
250
- //# sourceMappingURL=disposable.js.map
@@ -1 +0,0 @@
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,OAAQ,KAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC;IACvE,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACV,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC;AAYD,SAAS,gBAAgB,CAAC,KAAoB;IAC1C,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,OAAQ,KAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,EAAE,CAAC;YAC9D,OAAQ,KAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,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BACd,CAAC;gBACL,CAAC;wBAAS,CAAC;oBACP,WAAW,GAAG,SAAS,CAAC;gBAC5B,CAAC;YACL,CAAC;SACJ,CAAC;QACF,WAAW,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACnC,OAAO,iBAAiB,CAAC;IAC7B,CAAC;IAED,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,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,CAAC;IACzE,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,yBAAyB,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAgC,UAAa,EAAE,EAAE,CAC3E,KAAM,SAAQ,UAAU;IACpB,SAAS,GAAuB,IAAI,iBAAiB,EAAE,CAAC;IAExD,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"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,54 +0,0 @@
1
- import { test, expect } from "vitest";
2
- import { DisposableContext } from "./disposable";
3
- test("disposes resources", () => {
4
- const context = new DisposableContext();
5
- let d1 = false;
6
- const r1 = () => {
7
- d1 = true;
8
- };
9
- let d2 = false;
10
- const r2 = {
11
- [Symbol.dispose]() {
12
- d2 = true;
13
- },
14
- };
15
- context.use(r1);
16
- expect(d1).equals(false);
17
- context.dispose();
18
- expect(d1).equals(true);
19
- d1 = false;
20
- context.use(r2);
21
- expect(d2).equals(false);
22
- context.dispose();
23
- expect(d2).equals(true);
24
- expect(d1).equals(false);
25
- });
26
- test("disposer errors", () => {
27
- const context = new DisposableContext();
28
- context.use(() => {
29
- throw new TypeError("welp");
30
- });
31
- expect(() => context.dispose()).toThrowError(TypeError);
32
- context.use(() => {
33
- throw new TypeError("welp");
34
- });
35
- context.use(() => {
36
- throw new TypeError("wolp");
37
- });
38
- expect(() => context.dispose()).toThrowError(SuppressedError);
39
- });
40
- test("using", () => {
41
- const called = [];
42
- {
43
- using context = new DisposableContext();
44
- context.use(() => called.push("welp"));
45
- }
46
- try {
47
- using context = new DisposableContext();
48
- context.use(() => called.push("wolp"));
49
- throw new Error("oops");
50
- }
51
- catch (_e) { }
52
- expect(called).deep.equals(["welp", "wolp"]);
53
- });
54
- //# sourceMappingURL=disposable.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"disposable.test.js","sourceRoot":"","sources":["../src/disposable.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAC5B,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACxC,IAAI,EAAE,GAAG,KAAK,CAAC;IACf,MAAM,EAAE,GAAG,GAAG,EAAE;QACZ,EAAE,GAAG,IAAI,CAAC;IACd,CAAC,CAAC;IACF,IAAI,EAAE,GAAG,KAAK,CAAC;IACf,MAAM,EAAE,GAAe;QACnB,CAAC,MAAM,CAAC,OAAO,CAAC;YACZ,EAAE,GAAG,IAAI,CAAC;QACd,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EH,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;IACf,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,CAAC;QACG,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC,CAAA,CAAC;IACf,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC"}
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/fun.js 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 function always(value) {
15
- return () => value;
16
- }
17
- /**
18
- * The identity function: it just returns its argument unchanged.
19
- *
20
- * @example
21
- * ```ts @import.meta.vitest
22
- * expect(id(1337)).toEqual(1337);
23
- * expect(id("Hello Joe!")).toEqual("Hello Joe!");
24
- * ```
25
- */
26
- export function id(value) {
27
- return value;
28
- }
29
- /**
30
- * A function which does nothing and returns `void`.
31
- */
32
- export function nop() {
33
- // nop
34
- }
35
- export function sum(a, b) {
36
- // @ts-ignore
37
- // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
38
- return a + b;
39
- }
40
- //# sourceMappingURL=fun.js.map
package/dist/fun.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"fun.js","sourceRoot":"","sources":["../src/fun.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CAAI,KAAQ;IAC9B,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;AACvB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,EAAE,CAAI,KAAQ;IAC1B,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,GAAG;IACf,MAAM;AACV,CAAC;AAcD,MAAM,UAAU,GAAG,CAAqC,CAAI,EAAE,CAAI;IAC9D,aAAa;IACb,qEAAqE;IACrE,OAAO,CAAC,GAAG,CAAC,CAAC;AACjB,CAAC"}
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/index.js DELETED
@@ -1,15 +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 };
15
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC"}
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>;