@bodil/core 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assert.d.ts +13 -0
- package/dist/assert.js +5 -2
- package/dist/assert.js.map +1 -1
- package/dist/collections/linked-list.d.ts +7 -1
- package/dist/collections/linked-list.js +3 -0
- package/dist/collections/linked-list.js.map +1 -1
- package/dist/collections/lru-cache.d.ts +3 -0
- package/dist/collections/lru-cache.js.map +1 -1
- package/dist/decorators.d.ts +12 -0
- package/dist/decorators.js +28 -0
- package/dist/decorators.js.map +1 -0
- package/dist/decorators.test.d.ts +1 -0
- package/dist/decorators.test.js +71 -0
- package/dist/decorators.test.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +18 -10
- package/src/assert.ts +17 -4
- package/src/collections/linked-list.ts +9 -1
- package/src/collections/lru-cache.ts +3 -0
- package/src/decorators.test.ts +24 -0
- package/src/decorators.ts +32 -0
- package/src/index.ts +2 -1
package/dist/assert.d.ts
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
* Assertions and predicates.
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
+
interface ImportMetaEnv {
|
|
6
|
+
DEV?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
interface ImportMeta {
|
|
10
|
+
env?: ImportMetaEnv;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* The specific {@link Error} type thrown by assertions.
|
|
7
15
|
*/
|
|
@@ -74,7 +82,12 @@ export declare function isAsyncIterable(value: unknown): value is AsyncIterable<
|
|
|
74
82
|
/**
|
|
75
83
|
* Compares two values for deep equality.
|
|
76
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
|
+
*
|
|
77
89
|
* The implementation is a gently modified version of
|
|
78
90
|
* [fast-deep-equal](https://www.npmjs.com/package/fast-deep-equal).
|
|
79
91
|
*/
|
|
80
92
|
export declare function isDeepEqual(a: unknown, b: unknown): boolean;
|
|
93
|
+
export {};
|
package/dist/assert.js
CHANGED
|
@@ -20,8 +20,7 @@ export class AssertionError extends Error {
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
export function assert(assertion, message = "runtime assertion failed") {
|
|
23
|
-
if (import.meta.env === undefined ||
|
|
24
|
-
import.meta.env.DEV) {
|
|
23
|
+
if (import.meta.env === undefined || import.meta.env.DEV === true) {
|
|
25
24
|
if (assertion === false) {
|
|
26
25
|
throw new AssertionError(message);
|
|
27
26
|
}
|
|
@@ -110,6 +109,10 @@ export function isAsyncIterable(value) {
|
|
|
110
109
|
/**
|
|
111
110
|
* Compares two values for deep equality.
|
|
112
111
|
*
|
|
112
|
+
* Handles {@link Map}, {@link Set}, {@link ArrayBuffer}, {@link RegExp},
|
|
113
|
+
* {@link Equals} and objects with a `valueOf` or `toString` method in addition
|
|
114
|
+
* to the language built-ins.
|
|
115
|
+
*
|
|
113
116
|
* The implementation is a gently modified version of
|
|
114
117
|
* [fast-deep-equal](https://www.npmjs.com/package/fast-deep-equal).
|
|
115
118
|
*/
|
package/dist/assert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAClB,SAAkB,EAClB,UAAkB,0BAA0B;IAE5C,IAAI,MAAM,CAAC,IAAI,CAA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AC;YACnC,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,KAAK,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,GAAI,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC7B,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QAED,KAAK,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,GAAI,CAAC;YAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACpB,IAAI,CAAC,WAAW,CAAE,CAAS,CAAC,GAAG,CAAC,EAAG,CAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBACjD,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,oCAAoC;IACpC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for nodes in a {@link LinkedList}.
|
|
3
|
+
*/
|
|
1
4
|
export interface ListNode {
|
|
2
5
|
prev?: this;
|
|
3
6
|
next?: this;
|
|
@@ -37,5 +40,8 @@ export declare class LinkedList<Node extends ListNode> implements Iterable<Node>
|
|
|
37
40
|
* Remove the node at the tail of the list and return it.
|
|
38
41
|
*/
|
|
39
42
|
popTail(): Node | undefined;
|
|
40
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Iterate over the nodes in the list from head to tail.
|
|
45
|
+
*/
|
|
46
|
+
[Symbol.iterator]: () => IterableIterator<Node>;
|
|
41
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linked-list.js","sourceRoot":"","sources":["../../src/collections/linked-list.ts"],"names":[],"mappings":";AA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C;IAChB,CAAC;CAcJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lru-cache.js","sourceRoot":"","sources":["../../src/collections/lru-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAiB,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"lru-cache.js","sourceRoot":"","sources":["../../src/collections/lru-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAiB,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAuB7C;;;;;GAKG;AACH,MAAM,OAAO,QAAQ;IACR,MAAM,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,KAAK,GAAG,IAAI,UAAU,EAAiB,CAAC;IAC/B,QAAQ,CAAqB;IAEtC,YAAY,UAA8B,EAAE;QACxC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5B,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACZ,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,UAAU,EAAE,CAAC;IAClC,CAAC;IAED,aAAa,CAAC,KAAQ;QAClB,IAAI,IAAI,CAAC,QAAQ,CAAC,eAA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AC;YACJ,IAAI,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;YACtB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAE1B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,GAAG,CAAC,EAAE,CAAC;YACzD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACzC,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACpC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assorted decorators.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
const cachedValues = new WeakMap();
|
|
6
|
+
/**
|
|
7
|
+
* Decorate a getter to cache its result.
|
|
8
|
+
*
|
|
9
|
+
* Useful for deferring initialisation of a property until first access.
|
|
10
|
+
* Instead of `myProperty = new Thing();`,
|
|
11
|
+
* use `@cache get myProperty() { return new Thing(); }`.
|
|
12
|
+
*/
|
|
13
|
+
export function cache(getter, context) {
|
|
14
|
+
return function () {
|
|
15
|
+
let meta = cachedValues.get(this);
|
|
16
|
+
if (meta === undefined) {
|
|
17
|
+
meta = {};
|
|
18
|
+
cachedValues.set(this, meta);
|
|
19
|
+
}
|
|
20
|
+
if (Object.hasOwn(meta, context.name)) {
|
|
21
|
+
return meta[context.name];
|
|
22
|
+
}
|
|
23
|
+
const value = getter.call(this);
|
|
24
|
+
meta[context.name] = value;
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,YAAY,GAAG,IAAI,OAAO,EAA6C,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CACjB,MAAsB,EACtB,OAA0C;IAE1C,OAAO;QACH,IAAI,IAAI,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,IAAI,GAAG,EAAE,CAAC;YACV,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAM,CAAC;QACnC,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC3B,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
35
|
+
import { expect, test } from "vitest";
|
|
36
|
+
import { cache } from "./decorators";
|
|
37
|
+
test("@cache", () => {
|
|
38
|
+
let called = 0;
|
|
39
|
+
let CacheTest = (() => {
|
|
40
|
+
let _instanceExtraInitializers = [];
|
|
41
|
+
let _get_value_decorators;
|
|
42
|
+
return class CacheTest {
|
|
43
|
+
static {
|
|
44
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
45
|
+
_get_value_decorators = [cache];
|
|
46
|
+
__esDecorate(this, null, _get_value_decorators, { kind: "getter", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
47
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
48
|
+
}
|
|
49
|
+
get value() {
|
|
50
|
+
called++;
|
|
51
|
+
return 5;
|
|
52
|
+
}
|
|
53
|
+
constructor() {
|
|
54
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
})();
|
|
58
|
+
const t = new CacheTest();
|
|
59
|
+
// should not be called at construction
|
|
60
|
+
expect(called).toBe(0);
|
|
61
|
+
// should be called the first time the getter is accessed
|
|
62
|
+
expect(t.value).toBe(5);
|
|
63
|
+
expect(called).toBe(1);
|
|
64
|
+
// should not be called the second time the getter is accessed
|
|
65
|
+
expect(t.value).toBe(5);
|
|
66
|
+
expect(called).toBe(1);
|
|
67
|
+
// or the third, for good measure
|
|
68
|
+
expect(t.value).toBe(5);
|
|
69
|
+
expect(called).toBe(1);
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=decorators.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.test.js","sourceRoot":"","sources":["../src/decorators.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE;IAChB,IAAI,MAAM,GAAG,CAAC,CAAC;QACT,SAAS;;;qBAAT,SAAS;;;yCACV,KAAK;gBAAC,sKAAI,KAAK,6DAGf;;;YAHM,IAAI,KAAK;gBACZ,MAAM,EAAE,CAAC;gBACT,OAAO,CAAC,CAAC;YACb,CAAC;;gBAJC,mDAAS;;;;IAMf,MAAM,CAAC,GAAG,IAAI,SAAS,EAAE,CAAC;IAC1B,uCAAuC;IACvC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvB,yDAAyD;IACzD,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvB,8DAA8D;IAC9D,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvB,iCAAiC;IACjC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
import * as assert from "./assert";
|
|
6
6
|
import * as async from "./async";
|
|
7
7
|
import * as collections from "./collections";
|
|
8
|
+
import * as decorators from "./decorators";
|
|
8
9
|
import * as disposable from "./disposable";
|
|
9
10
|
import * as fun from "./fun";
|
|
10
11
|
import * as order from "./order";
|
|
11
12
|
import * as time from "./time";
|
|
12
13
|
import * as types from "./types";
|
|
13
|
-
export { assert, async, collections, disposable, fun, order, time, types };
|
|
14
|
+
export { assert, async, collections, decorators, disposable, fun, order, time, types };
|
package/dist/index.js
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
import * as assert from "./assert";
|
|
6
6
|
import * as async from "./async";
|
|
7
7
|
import * as collections from "./collections";
|
|
8
|
+
import * as decorators from "./decorators";
|
|
8
9
|
import * as disposable from "./disposable";
|
|
9
10
|
import * as fun from "./fun";
|
|
10
11
|
import * as order from "./order";
|
|
11
12
|
import * as time from "./time";
|
|
12
13
|
import * as types from "./types";
|
|
13
|
-
export { assert, async, collections, disposable, fun, order, time, types };
|
|
14
|
+
export { assert, async, collections, decorators, disposable, fun, order, time, types };
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,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,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC"}
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bodil/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "My TypeScript standard library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,6 +38,12 @@
|
|
|
38
38
|
"import": "./dist/collections.js"
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
+
"./decorators": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/decorators.d.ts",
|
|
44
|
+
"import": "./dist/decorators.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
41
47
|
"./disposable": {
|
|
42
48
|
"import": {
|
|
43
49
|
"types": "./dist/disposable.d.ts",
|
|
@@ -73,25 +79,27 @@
|
|
|
73
79
|
"access": "public"
|
|
74
80
|
},
|
|
75
81
|
"dependencies": {
|
|
76
|
-
"@bodil/opt": "^0.4.
|
|
77
|
-
"type-fest": "^5.
|
|
82
|
+
"@bodil/opt": "^0.4.3",
|
|
83
|
+
"type-fest": "^5.3.1"
|
|
78
84
|
},
|
|
79
85
|
"devDependencies": {
|
|
80
86
|
"@bodil/opt-vitest": "^1.1.0",
|
|
81
|
-
"@eslint/eslintrc": "^3.3.
|
|
82
|
-
"@eslint/js": "^9.39.
|
|
83
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
84
|
-
"@typescript-eslint/parser": "^8.
|
|
85
|
-
"
|
|
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",
|
|
91
|
+
"@typhonjs-typedoc/ts-lib-docs": "^2024.12.25",
|
|
92
|
+
"eslint": "^9.39.2",
|
|
86
93
|
"eslint-config-prettier": "^10.1.8",
|
|
87
94
|
"eslint-plugin-jsdoc": "^58.1.1",
|
|
88
95
|
"globals": "^16.5.0",
|
|
89
96
|
"npm-run-all2": "^8.0.4",
|
|
90
|
-
"prettier": "^3.
|
|
97
|
+
"prettier": "^3.7.4",
|
|
91
98
|
"temporal-polyfill": "^0.3.0",
|
|
92
|
-
"typedoc": "^0.28.
|
|
99
|
+
"typedoc": "^0.28.15",
|
|
93
100
|
"typedoc-plugin-extras": "^4.0.1",
|
|
94
101
|
"typedoc-plugin-mdn-links": "^5.0.10",
|
|
102
|
+
"typedoc-theme-fresh": "^0.2.3",
|
|
95
103
|
"typescript": "^5.9.3",
|
|
96
104
|
"vite-plugin-doctest": "^1.1.1",
|
|
97
105
|
"vitest": "^3.2.4"
|
package/src/assert.ts
CHANGED
|
@@ -3,8 +3,20 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
import type { Equals } from "./types";
|
|
6
8
|
import type { TypedArray } from "type-fest";
|
|
7
9
|
|
|
10
|
+
interface ImportMetaEnv {
|
|
11
|
+
DEV?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare global {
|
|
15
|
+
interface ImportMeta {
|
|
16
|
+
env?: ImportMetaEnv;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
/**
|
|
9
21
|
* The specific {@link Error} type thrown by assertions.
|
|
10
22
|
*/
|
|
@@ -26,10 +38,7 @@ export function assert(
|
|
|
26
38
|
assertion: unknown,
|
|
27
39
|
message: string = "runtime assertion failed"
|
|
28
40
|
): asserts assertion {
|
|
29
|
-
if (
|
|
30
|
-
(import.meta as unknown as { env: unknown }).env === undefined ||
|
|
31
|
-
(import.meta as unknown as { env: { DEV: boolean } }).env.DEV
|
|
32
|
-
) {
|
|
41
|
+
if (import.meta.env === undefined || import.meta.env.DEV === true) {
|
|
33
42
|
if (assertion === false) {
|
|
34
43
|
throw new AssertionError(message);
|
|
35
44
|
}
|
|
@@ -135,6 +144,10 @@ export function isAsyncIterable(value: unknown): value is AsyncIterable<unknown>
|
|
|
135
144
|
/**
|
|
136
145
|
* Compares two values for deep equality.
|
|
137
146
|
*
|
|
147
|
+
* Handles {@link Map}, {@link Set}, {@link ArrayBuffer}, {@link RegExp},
|
|
148
|
+
* {@link Equals} and objects with a `valueOf` or `toString` method in addition
|
|
149
|
+
* to the language built-ins.
|
|
150
|
+
*
|
|
138
151
|
* The implementation is a gently modified version of
|
|
139
152
|
* [fast-deep-equal](https://www.npmjs.com/package/fast-deep-equal).
|
|
140
153
|
*/
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { assert } from "@bodil/core/assert";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Interface for nodes in a {@link LinkedList}.
|
|
5
|
+
*/
|
|
3
6
|
export interface ListNode {
|
|
4
7
|
prev?: this;
|
|
5
8
|
next?: this;
|
|
@@ -121,7 +124,12 @@ export class LinkedList<Node extends ListNode> implements Iterable<Node> {
|
|
|
121
124
|
return node;
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Iterate over the nodes in the list from head to tail.
|
|
129
|
+
*/
|
|
130
|
+
[Symbol.iterator]: () => IterableIterator<Node> = function* (
|
|
131
|
+
this: LinkedList<Node>
|
|
132
|
+
): Generator<Node> {
|
|
125
133
|
let node = this.head;
|
|
126
134
|
while (node !== undefined) {
|
|
127
135
|
yield node;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { cache } from "./decorators";
|
|
3
|
+
|
|
4
|
+
test("@cache", () => {
|
|
5
|
+
let called = 0;
|
|
6
|
+
class CacheTest {
|
|
7
|
+
@cache get value() {
|
|
8
|
+
called++;
|
|
9
|
+
return 5;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const t = new CacheTest();
|
|
13
|
+
// should not be called at construction
|
|
14
|
+
expect(called).toBe(0);
|
|
15
|
+
// should be called the first time the getter is accessed
|
|
16
|
+
expect(t.value).toBe(5);
|
|
17
|
+
expect(called).toBe(1);
|
|
18
|
+
// should not be called the second time the getter is accessed
|
|
19
|
+
expect(t.value).toBe(5);
|
|
20
|
+
expect(called).toBe(1);
|
|
21
|
+
// or the third, for good measure
|
|
22
|
+
expect(t.value).toBe(5);
|
|
23
|
+
expect(called).toBe(1);
|
|
24
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assorted decorators.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const cachedValues = new WeakMap<WeakKey, Record<string | symbol, unknown>>();
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Decorate a getter to cache its result.
|
|
10
|
+
*
|
|
11
|
+
* Useful for deferring initialisation of a property until first access.
|
|
12
|
+
* Instead of `myProperty = new Thing();`,
|
|
13
|
+
* use `@cache get myProperty() { return new Thing(); }`.
|
|
14
|
+
*/
|
|
15
|
+
export function cache<C extends object, T>(
|
|
16
|
+
getter: (this: C) => T,
|
|
17
|
+
context: ClassGetterDecoratorContext<C, T>
|
|
18
|
+
): (this: C) => T {
|
|
19
|
+
return function (this: C): T {
|
|
20
|
+
let meta = cachedValues.get(this);
|
|
21
|
+
if (meta === undefined) {
|
|
22
|
+
meta = {};
|
|
23
|
+
cachedValues.set(this, meta);
|
|
24
|
+
}
|
|
25
|
+
if (Object.hasOwn(meta, context.name)) {
|
|
26
|
+
return meta[context.name] as T;
|
|
27
|
+
}
|
|
28
|
+
const value = getter.call(this);
|
|
29
|
+
meta[context.name] = value;
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
import * as assert from "./assert";
|
|
7
7
|
import * as async from "./async";
|
|
8
8
|
import * as collections from "./collections";
|
|
9
|
+
import * as decorators from "./decorators";
|
|
9
10
|
import * as disposable from "./disposable";
|
|
10
11
|
import * as fun from "./fun";
|
|
11
12
|
import * as order from "./order";
|
|
12
13
|
import * as time from "./time";
|
|
13
14
|
import * as types from "./types";
|
|
14
15
|
|
|
15
|
-
export { assert, async, collections, disposable, fun, order, time, types };
|
|
16
|
+
export { assert, async, collections, decorators, disposable, fun, order, time, types };
|