shelving 1.120.0 → 1.121.1
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/{change → db}/Change.d.ts +6 -1
- package/{change → db}/Change.js +9 -0
- package/db/{LoggedProvider.d.ts → ChangesProvider.d.ts} +5 -5
- package/db/{LoggedProvider.js → ChangesProvider.js} +12 -12
- package/db/index.d.ts +2 -1
- package/db/index.js +3 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +1 -3
- package/util/array.d.ts +2 -4
- package/util/array.js +6 -4
- package/util/async.d.ts +2 -2
- package/util/async.js +6 -2
- package/util/boolean.d.ts +5 -5
- package/util/boolean.js +15 -5
- package/util/class.d.ts +2 -2
- package/util/class.js +6 -2
- package/util/color.d.ts +1 -1
- package/util/color.js +9 -3
- package/util/data.d.ts +1 -1
- package/util/data.js +3 -1
- package/util/dictionary.d.ts +2 -2
- package/util/dictionary.js +6 -2
- package/util/dispose.d.ts +1 -1
- package/util/dispose.js +3 -1
- package/util/entry.d.ts +2 -2
- package/util/entry.js +6 -2
- package/util/equal.d.ts +16 -16
- package/util/equal.js +48 -16
- package/util/error.d.ts +1 -1
- package/util/error.js +4 -2
- package/util/function.d.ts +3 -3
- package/util/function.js +9 -3
- package/util/hydrate.js +4 -2
- package/util/jsx.d.ts +2 -2
- package/util/jsx.js +6 -2
- package/util/map.d.ts +2 -2
- package/util/map.js +6 -2
- package/util/merge.d.ts +1 -1
- package/util/merge.js +3 -1
- package/util/null.d.ts +5 -5
- package/util/null.js +15 -5
- package/util/number.d.ts +6 -6
- package/util/number.js +18 -6
- package/util/object.d.ts +1 -1
- package/util/object.js +3 -1
- package/util/optional.d.ts +1 -1
- package/util/optional.js +3 -1
- package/util/path.d.ts +2 -2
- package/util/path.js +6 -2
- package/util/query.d.ts +1 -1
- package/util/query.js +3 -1
- package/util/random.d.ts +4 -4
- package/util/random.js +15 -5
- package/util/regexp.d.ts +5 -6
- package/util/regexp.js +15 -5
- package/util/sequence.d.ts +1 -1
- package/util/sequence.js +3 -1
- package/util/serialise.js +12 -8
- package/util/set.d.ts +2 -2
- package/util/set.js +6 -2
- package/util/sort.d.ts +1 -1
- package/util/sort.js +3 -1
- package/util/string.d.ts +26 -16
- package/util/string.js +65 -34
- package/util/time.d.ts +6 -6
- package/util/time.js +21 -7
- package/util/undefined.d.ts +3 -3
- package/util/undefined.js +6 -2
- package/util/units.js +3 -1
- package/util/url.d.ts +1 -1
- package/util/url.js +3 -1
- package/util/validate.d.ts +1 -1
- package/util/validate.js +3 -1
- package/change/index.d.ts +0 -1
- package/change/index.js +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { AsyncProvider, Provider } from "
|
|
1
|
+
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
2
2
|
import type { ImmutableArray } from "../util/array.js";
|
|
3
3
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
4
|
import type { ItemQuery } from "../util/item.js";
|
|
5
5
|
import type { Updates } from "../util/update.js";
|
|
6
|
+
import { type Optional } from "../util/optional.js";
|
|
6
7
|
/** A change to a database. */
|
|
7
8
|
export interface Change {
|
|
8
9
|
readonly action: string;
|
|
@@ -66,5 +67,9 @@ export type DatabaseChange<T extends Database> = ItemAddChange<T, DataKey<T>> |
|
|
|
66
67
|
export type DatabaseChanges<T extends Database> = ImmutableArray<DatabaseChange<T>>;
|
|
67
68
|
/** Write a single change to a synchronous provider and return an array of the changes that were written. */
|
|
68
69
|
export declare function writeChange<T extends Database>(provider: Provider<T>, change: DatabaseChange<T>): DatabaseChange<T>;
|
|
70
|
+
/** Write a set of changes to a synchronous provider. */
|
|
71
|
+
export declare function writeChanges<T extends Database>(provider: Provider<T>, ...changes: Optional<DatabaseChange<T>>[]): DatabaseChanges<T>;
|
|
69
72
|
/** Write a single change to an asynchronous provider and return the change that was written. */
|
|
70
73
|
export declare function writeAsyncChange<T extends Database>(provider: AsyncProvider<T>, change: DatabaseChange<T>): Promise<DatabaseChange<T>>;
|
|
74
|
+
/** Write a set of changes to an asynchronous provider. */
|
|
75
|
+
export declare function writeAsyncChanges<T extends Database>(provider: AsyncProvider<T>, ...changes: Optional<DatabaseChange<T>>[]): Promise<DatabaseChanges<T>>;
|
package/{change → db}/Change.js
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { notOptional } from "../util/optional.js";
|
|
1
2
|
/** Write a single change to a synchronous provider and return an array of the changes that were written. */
|
|
2
3
|
export function writeChange(provider, change) {
|
|
3
4
|
const { action, collection, id, query } = change;
|
|
@@ -23,6 +24,10 @@ export function writeChange(provider, change) {
|
|
|
23
24
|
}
|
|
24
25
|
return change;
|
|
25
26
|
}
|
|
27
|
+
/** Write a set of changes to a synchronous provider. */
|
|
28
|
+
export function writeChanges(provider, ...changes) {
|
|
29
|
+
return changes.filter(notOptional).map(change => writeChange(provider, change));
|
|
30
|
+
}
|
|
26
31
|
/** Write a single change to an asynchronous provider and return the change that was written. */
|
|
27
32
|
export async function writeAsyncChange(provider, change) {
|
|
28
33
|
const { collection, action, id, query } = change;
|
|
@@ -48,3 +53,7 @@ export async function writeAsyncChange(provider, change) {
|
|
|
48
53
|
}
|
|
49
54
|
return change;
|
|
50
55
|
}
|
|
56
|
+
/** Write a set of changes to an asynchronous provider. */
|
|
57
|
+
export function writeAsyncChanges(provider, ...changes) {
|
|
58
|
+
return Promise.all(changes.filter(notOptional).map(change => writeAsyncChange(provider, change)));
|
|
59
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { DatabaseChange, DatabaseChanges } from "
|
|
1
|
+
import type { DatabaseChange, DatabaseChanges } from "./Change.js";
|
|
2
2
|
import type { MutableArray } from "../util/array.js";
|
|
3
3
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
4
|
import type { ItemQuery } from "../util/item.js";
|
|
5
5
|
import type { Updates } from "../util/update.js";
|
|
6
6
|
import { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
7
|
-
/** Synchronous provider that keeps a log of any written changes to its `.
|
|
8
|
-
export declare class
|
|
9
|
-
get
|
|
10
|
-
readonly
|
|
7
|
+
/** Synchronous provider that keeps a log of any written changes to its `.changes` property. */
|
|
8
|
+
export declare class ChangesProvider<T extends Database> extends ThroughProvider<T> {
|
|
9
|
+
get changes(): DatabaseChanges<T>;
|
|
10
|
+
readonly _changes: MutableArray<DatabaseChange<T>>;
|
|
11
11
|
addItem<K extends DataKey<T>>(collection: K, data: T[K]): string;
|
|
12
12
|
setItem<K extends DataKey<T>>(collection: K, id: string, data: T[K]): void;
|
|
13
13
|
updateItem<K extends DataKey<T>>(collection: K, id: string, updates: Updates<T[K]>): void;
|
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
2
|
-
/** Synchronous provider that keeps a log of any written changes to its `.
|
|
3
|
-
export class
|
|
4
|
-
get
|
|
5
|
-
return this.
|
|
2
|
+
/** Synchronous provider that keeps a log of any written changes to its `.changes` property. */
|
|
3
|
+
export class ChangesProvider extends ThroughProvider {
|
|
4
|
+
get changes() {
|
|
5
|
+
return this._changes;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
_changes = [];
|
|
8
8
|
addItem(collection, data) {
|
|
9
9
|
const id = super.addItem(collection, data);
|
|
10
|
-
this.
|
|
10
|
+
this._changes.push({ action: "set", collection, id, data });
|
|
11
11
|
return id;
|
|
12
12
|
}
|
|
13
13
|
setItem(collection, id, data) {
|
|
14
14
|
super.setItem(collection, id, data);
|
|
15
|
-
this.
|
|
15
|
+
this._changes.push({ action: "set", collection, id, data });
|
|
16
16
|
}
|
|
17
17
|
updateItem(collection, id, updates) {
|
|
18
18
|
super.updateItem(collection, id, updates);
|
|
19
|
-
this.
|
|
19
|
+
this._changes.push({ action: "update", collection, id, updates });
|
|
20
20
|
}
|
|
21
21
|
deleteItem(collection, id) {
|
|
22
22
|
super.deleteItem(collection, id);
|
|
23
|
-
this.
|
|
23
|
+
this._changes.push({ action: "delete", collection, id });
|
|
24
24
|
}
|
|
25
25
|
setQuery(collection, query, data) {
|
|
26
26
|
super.setQuery(collection, query, data);
|
|
27
|
-
this.
|
|
27
|
+
this._changes.push({ action: "set", collection, query, data });
|
|
28
28
|
}
|
|
29
29
|
updateQuery(collection, query, updates) {
|
|
30
30
|
super.updateQuery(collection, query, updates);
|
|
31
|
-
this.
|
|
31
|
+
this._changes.push({ action: "update", collection, query, updates });
|
|
32
32
|
}
|
|
33
33
|
deleteQuery(collection, query) {
|
|
34
34
|
super.deleteQuery(collection, query);
|
|
35
|
-
this.
|
|
35
|
+
this._changes.push({ action: "delete", collection, query });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
/** Asynchronous provider that keeps a log of any written changes to its `.written` property. */
|
package/db/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export * from "./QueryStore.js";
|
|
|
3
3
|
export * from "./Provider.js";
|
|
4
4
|
export * from "./ThroughProvider.js";
|
|
5
5
|
export * from "./CacheProvider.js";
|
|
6
|
+
export * from "./ChangesProvider.js";
|
|
6
7
|
export * from "./DebugProvider.js";
|
|
7
|
-
export * from "./LoggedProvider.js";
|
|
8
8
|
export * from "./MemoryProvider.js";
|
|
9
9
|
export * from "./ValidationProvider.js";
|
|
10
|
+
export * from "./Change.js";
|
package/db/index.js
CHANGED
|
@@ -5,7 +5,9 @@ export * from "./QueryStore.js";
|
|
|
5
5
|
export * from "./Provider.js";
|
|
6
6
|
export * from "./ThroughProvider.js";
|
|
7
7
|
export * from "./CacheProvider.js";
|
|
8
|
+
export * from "./ChangesProvider.js";
|
|
8
9
|
export * from "./DebugProvider.js";
|
|
9
|
-
export * from "./LoggedProvider.js";
|
|
10
10
|
export * from "./MemoryProvider.js";
|
|
11
11
|
export * from "./ValidationProvider.js";
|
|
12
|
+
// Util.
|
|
13
|
+
export * from "./Change.js";
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.121.1",
|
|
15
15
|
"repository": "https://github.com/dhoulb/shelving",
|
|
16
16
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
17
17
|
"license": "0BSD",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"exports": {
|
|
23
23
|
".": "./index.js",
|
|
24
24
|
"./api": "./api/index.js",
|
|
25
|
-
"./change": "./change/index.js",
|
|
26
25
|
"./db": "./db/index.js",
|
|
27
26
|
"./error": "./error/index.js",
|
|
28
27
|
"./feedback": "./feedback/index.js",
|
|
@@ -31,7 +30,6 @@
|
|
|
31
30
|
"./firestore/server": "./firestore/server/index.js",
|
|
32
31
|
"./iterate": "./iterate/index.js",
|
|
33
32
|
"./markup": "./markup/index.js",
|
|
34
|
-
"./provider": "./provider/index.js",
|
|
35
33
|
"./react": "./react/index.js",
|
|
36
34
|
"./schema": "./schema/index.js",
|
|
37
35
|
"./sequence": "./sequence/index.js",
|
package/util/array.d.ts
CHANGED
|
@@ -13,11 +13,11 @@ export type ArrayItem<T extends ImmutableArray> = T[number];
|
|
|
13
13
|
/** Things that can be converted to arrays. */
|
|
14
14
|
export type PossibleArray<T> = ImmutableArray<T> | Iterable<T>;
|
|
15
15
|
/** Is an unknown value an array? */
|
|
16
|
-
export declare
|
|
16
|
+
export declare function isArray(value: unknown): value is ImmutableArray;
|
|
17
17
|
/** Assert that an unknown value is an array. */
|
|
18
18
|
export declare function assertArray<T>(arr: unknown): asserts arr is ImmutableArray<T>;
|
|
19
19
|
/** Is an unknown value an item in a specified array? */
|
|
20
|
-
export declare
|
|
20
|
+
export declare function isArrayItem<T>(arr: ImmutableArray<T>, item: unknown): item is T;
|
|
21
21
|
/** Assert that an unknown value is an item in a specified array. */
|
|
22
22
|
export declare function assertArrayItem<T>(arr: ImmutableArray<T>, item: unknown): asserts item is T;
|
|
23
23
|
/** Convert an iterable to an array (if its not already an array). */
|
|
@@ -28,8 +28,6 @@ export declare function withArrayItems<T>(arr: ImmutableArray<T>, ...items: T[])
|
|
|
28
28
|
export declare function pickArrayItems<T>(input: ImmutableArray<T> | Iterable<T>, ...pick: T[]): ImmutableArray<T>;
|
|
29
29
|
/** Remove multiple items from an array (immutably) and return a new array without those items (or the same array if no changes were made). */
|
|
30
30
|
export declare function omitArrayItems<T>(input: ImmutableArray<T> | Iterable<T>, ...omit: T[]): ImmutableArray<T>;
|
|
31
|
-
/** Clear an array (immutably) and return a new empty array (or the same array if no changes were made). */
|
|
32
|
-
export declare const clearArray: <T>(input: ImmutableArray<T>) => ImmutableArray<T>;
|
|
33
31
|
/** Toggle an item in and out of an array (immutably) and return a new array with or without the specified items (or the same array if no changes were made). */
|
|
34
32
|
export declare function toggleArrayItems<T>(input: ImmutableArray<T>, ...items: T[]): ImmutableArray<T>;
|
|
35
33
|
/** Get the first item from an array or iterable, or `undefined` if it didn't exist. */
|
package/util/array.js
CHANGED
|
@@ -3,14 +3,18 @@ import { ValueError } from "../error/ValueError.js";
|
|
|
3
3
|
import { omitItems, pickItems } from "./iterate.js";
|
|
4
4
|
import { formatRange } from "./number.js";
|
|
5
5
|
/** Is an unknown value an array? */
|
|
6
|
-
export
|
|
6
|
+
export function isArray(value) {
|
|
7
|
+
return Array.isArray(value);
|
|
8
|
+
}
|
|
7
9
|
/** Assert that an unknown value is an array. */
|
|
8
10
|
export function assertArray(arr) {
|
|
9
11
|
if (!isArray(arr))
|
|
10
12
|
throw new ValueError(`Must be array`, arr);
|
|
11
13
|
}
|
|
12
14
|
/** Is an unknown value an item in a specified array? */
|
|
13
|
-
export
|
|
15
|
+
export function isArrayItem(arr, item) {
|
|
16
|
+
return arr.includes(item);
|
|
17
|
+
}
|
|
14
18
|
/** Assert that an unknown value is an item in a specified array. */
|
|
15
19
|
export function assertArrayItem(arr, item) {
|
|
16
20
|
if (!isArrayItem(arr, item))
|
|
@@ -38,8 +42,6 @@ export function omitArrayItems(input, ...omit) {
|
|
|
38
42
|
const output = Array.from(omitItems(input, ...omit));
|
|
39
43
|
return isArray(input) && output.length === input.length ? input : output;
|
|
40
44
|
}
|
|
41
|
-
/** Clear an array (immutably) and return a new empty array (or the same array if no changes were made). */
|
|
42
|
-
export const clearArray = (input) => (input.length ? [] : input);
|
|
43
45
|
/** Toggle an item in and out of an array (immutably) and return a new array with or without the specified items (or the same array if no changes were made). */
|
|
44
46
|
export function toggleArrayItems(input, ...items) {
|
|
45
47
|
const extras = items.filter(_doesNotInclude, input);
|
package/util/async.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ValueCallback } from "./callback.js";
|
|
2
2
|
import type { Report } from "./error.js";
|
|
3
3
|
/** Is a value an asynchronous value implementing a `then()` function. */
|
|
4
|
-
export declare
|
|
4
|
+
export declare function isAsync<T>(value: PromiseLike<T> | T): value is PromiseLike<T>;
|
|
5
5
|
/** Is a value a synchronous value. */
|
|
6
|
-
export declare
|
|
6
|
+
export declare function notAsync<T>(value: PromiseLike<T> | T): value is T;
|
|
7
7
|
/**
|
|
8
8
|
* Throw the value if it's an async (promised) value.
|
|
9
9
|
* @returns Synchronous (not promised) value.
|
package/util/async.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { ValueError } from "../error/ValueError.js";
|
|
2
2
|
/** Is a value an asynchronous value implementing a `then()` function. */
|
|
3
|
-
export
|
|
3
|
+
export function isAsync(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
5
|
+
}
|
|
4
6
|
/** Is a value a synchronous value. */
|
|
5
|
-
export
|
|
7
|
+
export function notAsync(value) {
|
|
8
|
+
return !isAsync(value);
|
|
9
|
+
}
|
|
6
10
|
/**
|
|
7
11
|
* Throw the value if it's an async (promised) value.
|
|
8
12
|
* @returns Synchronous (not promised) value.
|
package/util/boolean.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/** Is a value a boolean? */
|
|
2
|
-
export declare
|
|
2
|
+
export declare function isBoolean(value: unknown): value is boolean;
|
|
3
3
|
/** Is a value true? */
|
|
4
|
-
export declare
|
|
4
|
+
export declare function isTrue(value: unknown): value is true;
|
|
5
5
|
/** Is a value false? */
|
|
6
|
-
export declare
|
|
6
|
+
export declare function isFalse(value: unknown): value is false;
|
|
7
7
|
/** Is a value truthy? */
|
|
8
|
-
export declare
|
|
8
|
+
export declare function isTruthy(value: unknown): boolean;
|
|
9
9
|
/** Is a value falsey? */
|
|
10
|
-
export declare
|
|
10
|
+
export declare function isFalsey(value: unknown): boolean;
|
|
11
11
|
/** Assert that a value is a boolean. */
|
|
12
12
|
export declare function assertBoolean(value: unknown): asserts value is boolean;
|
|
13
13
|
/** Assert that a value is true. */
|
package/util/boolean.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { ValueError } from "../error/ValueError.js";
|
|
2
2
|
/** Is a value a boolean? */
|
|
3
|
-
export
|
|
3
|
+
export function isBoolean(value) {
|
|
4
|
+
return typeof value === "boolean";
|
|
5
|
+
}
|
|
4
6
|
/** Is a value true? */
|
|
5
|
-
export
|
|
7
|
+
export function isTrue(value) {
|
|
8
|
+
return value === true;
|
|
9
|
+
}
|
|
6
10
|
/** Is a value false? */
|
|
7
|
-
export
|
|
11
|
+
export function isFalse(value) {
|
|
12
|
+
return value === false;
|
|
13
|
+
}
|
|
8
14
|
/** Is a value truthy? */
|
|
9
|
-
export
|
|
15
|
+
export function isTruthy(value) {
|
|
16
|
+
return !!value;
|
|
17
|
+
}
|
|
10
18
|
/** Is a value falsey? */
|
|
11
|
-
export
|
|
19
|
+
export function isFalsey(value) {
|
|
20
|
+
return !value;
|
|
21
|
+
}
|
|
12
22
|
/** Assert that a value is a boolean. */
|
|
13
23
|
export function assertBoolean(value) {
|
|
14
24
|
if (typeof value !== "boolean")
|
package/util/class.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export type AnyConstructor = new (...args: any) => any;
|
|
|
6
6
|
/** Class prototype that can be used with `instanceof`. */
|
|
7
7
|
export type Class<T> = new (...args: any) => T;
|
|
8
8
|
/** Is a given value a class constructor? */
|
|
9
|
-
export declare
|
|
9
|
+
export declare function isConstructor(value: unknown): value is AnyConstructor;
|
|
10
10
|
/** Is a value an instance of a class? */
|
|
11
|
-
export declare
|
|
11
|
+
export declare function isInstance<T>(value: unknown, type: Class<T>): value is T;
|
|
12
12
|
/** Assert that a value is an instance of something. */
|
|
13
13
|
export declare function assertInstance<T>(value: unknown, type: Class<T>): asserts value is T;
|
package/util/class.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { ValueError } from "../error/ValueError.js";
|
|
2
2
|
import { debug } from "./debug.js";
|
|
3
3
|
/** Is a given value a class constructor? */
|
|
4
|
-
export
|
|
4
|
+
export function isConstructor(value) {
|
|
5
|
+
return typeof value === "function" && value.toString().startsWith("class");
|
|
6
|
+
}
|
|
5
7
|
/** Is a value an instance of a class? */
|
|
6
|
-
export
|
|
8
|
+
export function isInstance(value, type) {
|
|
9
|
+
return value instanceof type;
|
|
10
|
+
}
|
|
7
11
|
/** Assert that a value is an instance of something. */
|
|
8
12
|
export function assertInstance(value, type) {
|
|
9
13
|
if (!(value instanceof type))
|
package/util/color.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare class Color {
|
|
|
26
26
|
toString(): string;
|
|
27
27
|
}
|
|
28
28
|
/** Is an unknown value a `Color` instance. */
|
|
29
|
-
export declare
|
|
29
|
+
export declare function isColor(value: unknown): value is Color;
|
|
30
30
|
/** Assert that an unknown value is a `Color` instance. */
|
|
31
31
|
export declare function assertColor(value: unknown): asserts value is Color;
|
|
32
32
|
/** Convert a possible color to a `Color` instance or `undefined` */
|
package/util/color.js
CHANGED
|
@@ -58,10 +58,16 @@ export class Color {
|
|
|
58
58
|
return this.rgba;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
function _parse(hex) {
|
|
62
|
+
return parseInt(hex.padStart(2, "00"), 16);
|
|
63
|
+
}
|
|
64
|
+
function _hex(channel) {
|
|
65
|
+
return channel.toString(16).padStart(2, "00");
|
|
66
|
+
}
|
|
63
67
|
/** Is an unknown value a `Color` instance. */
|
|
64
|
-
export
|
|
68
|
+
export function isColor(value) {
|
|
69
|
+
return value instanceof Color;
|
|
70
|
+
}
|
|
65
71
|
/** Assert that an unknown value is a `Color` instance. */
|
|
66
72
|
export function assertColor(value) {
|
|
67
73
|
if (!isColor(value))
|
package/util/data.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export type LeafProp<T extends Data> = {
|
|
|
44
44
|
readonly [K in DataKey<T>]: (T[K] extends Data ? LeafProp<T[K]> : readonly [null, T[K]]) extends infer E ? E extends readonly [infer KK, infer VV] ? readonly [KK extends string ? `${K}.${KK}` : K, VV] : never : never;
|
|
45
45
|
}[DataKey<T>];
|
|
46
46
|
/** Is an unknown value a data object? */
|
|
47
|
-
export declare
|
|
47
|
+
export declare function isData(value: unknown): value is Data;
|
|
48
48
|
/** Assert that an unknown value is a data object. */
|
|
49
49
|
export declare function assertData(value: unknown): asserts value is Data;
|
|
50
50
|
/** Is an unknown value the key for an own prop of a data object. */
|
package/util/data.js
CHANGED
|
@@ -2,7 +2,9 @@ import { ValueError } from "../error/ValueError.js";
|
|
|
2
2
|
import { isIterable } from "./iterate.js";
|
|
3
3
|
import { isObject, isPlainObject } from "./object.js";
|
|
4
4
|
/** Is an unknown value a data object? */
|
|
5
|
-
export
|
|
5
|
+
export function isData(value) {
|
|
6
|
+
return isPlainObject(value);
|
|
7
|
+
}
|
|
6
8
|
/** Assert that an unknown value is a data object. */
|
|
7
9
|
export function assertData(value) {
|
|
8
10
|
if (!isPlainObject(value))
|
package/util/dictionary.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type DictionaryValue<T extends ImmutableDictionary> = T[string];
|
|
|
13
13
|
/** Something that can be converted to a dictionary object. */
|
|
14
14
|
export type PossibleDictionary<T> = ImmutableDictionary<T> | Iterable<DictionaryItem<T>>;
|
|
15
15
|
/** Is an unknown value a dictionary object? */
|
|
16
|
-
export declare
|
|
16
|
+
export declare function isDictionary(value: unknown): value is ImmutableDictionary;
|
|
17
17
|
/** Assert that an unknown value is a dictionary object */
|
|
18
18
|
export declare function assertDictionary(value: unknown): asserts value is ImmutableDictionary;
|
|
19
19
|
/** turn a possible dictionary into a dictionary. */
|
|
@@ -22,7 +22,7 @@ export declare function getDictionary<T>(obj: PossibleDictionary<T>): ImmutableD
|
|
|
22
22
|
export declare function getDictionaryItems<T>(obj: ImmutableDictionary<T>): readonly DictionaryItem<T>[];
|
|
23
23
|
export declare function getDictionaryItems<T>(obj: PossibleDictionary<T>): Iterable<DictionaryItem<T>>;
|
|
24
24
|
/** Is an unknown value the key for an own prop of a dictionary. */
|
|
25
|
-
export declare
|
|
25
|
+
export declare function isDictionaryItem<T>(obj: ImmutableDictionary<T>, key: unknown): key is string;
|
|
26
26
|
/** Assert that an unknown value is the key for an own prop of a dictionary. */
|
|
27
27
|
export declare function assertDictionaryItem<T>(obj: ImmutableDictionary<T>, key: unknown): asserts key is string;
|
|
28
28
|
/** Get an item in a map or throw an error if it doesn't exist. */
|
package/util/dictionary.js
CHANGED
|
@@ -3,7 +3,9 @@ import { ValueError } from "../error/ValueError.js";
|
|
|
3
3
|
import { isIterable } from "./iterate.js";
|
|
4
4
|
import { deleteProps, isPlainObject, omitProps, pickProps, setProp, setProps, withProp, withProps } from "./object.js";
|
|
5
5
|
/** Is an unknown value a dictionary object? */
|
|
6
|
-
export
|
|
6
|
+
export function isDictionary(value) {
|
|
7
|
+
return isPlainObject(value);
|
|
8
|
+
}
|
|
7
9
|
/** Assert that an unknown value is a dictionary object */
|
|
8
10
|
export function assertDictionary(value) {
|
|
9
11
|
if (!isDictionary(value))
|
|
@@ -17,7 +19,9 @@ export function getDictionaryItems(obj) {
|
|
|
17
19
|
return isIterable(obj) ? obj : Object.entries(obj);
|
|
18
20
|
}
|
|
19
21
|
/** Is an unknown value the key for an own prop of a dictionary. */
|
|
20
|
-
export
|
|
22
|
+
export function isDictionaryItem(obj, key) {
|
|
23
|
+
return typeof key === "string" && Object.hasOwn(obj, key);
|
|
24
|
+
}
|
|
21
25
|
/** Assert that an unknown value is the key for an own prop of a dictionary. */
|
|
22
26
|
export function assertDictionaryItem(obj, key) {
|
|
23
27
|
if (!isDictionaryItem(obj, key))
|
package/util/dispose.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface Disposable {
|
|
|
18
18
|
/** Safely dispose a disposable. */
|
|
19
19
|
export declare function dispose(value: Disposable): void;
|
|
20
20
|
/** Is an unknown value a disposable object? */
|
|
21
|
-
export declare
|
|
21
|
+
export declare function isDisposable(v: unknown): v is Disposable;
|
|
22
22
|
/**
|
|
23
23
|
* Version of `Map` that is disposable.
|
|
24
24
|
* - If items are `Disposable` they are disposed when they're deleted from the map.
|
package/util/dispose.js
CHANGED
|
@@ -15,7 +15,9 @@ export function dispose(value) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
/** Is an unknown value a disposable object? */
|
|
18
|
-
export
|
|
18
|
+
export function isDisposable(v) {
|
|
19
|
+
return isObject(v) && typeof v[Symbol.dispose] === "function";
|
|
20
|
+
}
|
|
19
21
|
/**
|
|
20
22
|
* Version of `Map` that is disposable.
|
|
21
23
|
* - If items are `Disposable` they are disposed when they're deleted from the map.
|
package/util/entry.d.ts
CHANGED
|
@@ -16,9 +16,9 @@ export type EntryObject<T extends Entry<PropertyKey, unknown>> = {
|
|
|
16
16
|
readonly [E in T as E[0]]: E[1];
|
|
17
17
|
};
|
|
18
18
|
/** Extract the key from an object entry. */
|
|
19
|
-
export declare
|
|
19
|
+
export declare function getEntryKey<K, T>([k]: Entry<K, T>): K;
|
|
20
20
|
/** Extract the value from an object entry. */
|
|
21
|
-
export declare
|
|
21
|
+
export declare function getEntryValue<K, T>([, v]: Entry<K, T>): T;
|
|
22
22
|
/** Yield the keys of an iterable set of entries. */
|
|
23
23
|
export declare function getEntryKeys<K, T>(input: Iterable<Entry<K, T>>): Iterable<K>;
|
|
24
24
|
/** Yield the values of an iterable set of entries. */
|
package/util/entry.js
CHANGED
|
@@ -2,9 +2,13 @@ import { isArray } from "./array.js";
|
|
|
2
2
|
import { isIterable } from "./iterate.js";
|
|
3
3
|
import { isSet } from "./set.js";
|
|
4
4
|
/** Extract the key from an object entry. */
|
|
5
|
-
export
|
|
5
|
+
export function getEntryKey([k]) {
|
|
6
|
+
return k;
|
|
7
|
+
}
|
|
6
8
|
/** Extract the value from an object entry. */
|
|
7
|
-
export
|
|
9
|
+
export function getEntryValue([, v]) {
|
|
10
|
+
return v;
|
|
11
|
+
}
|
|
8
12
|
/** Yield the keys of an iterable set of entries. */
|
|
9
13
|
export function* getEntryKeys(input) {
|
|
10
14
|
for (const [k] of input)
|
package/util/equal.d.ts
CHANGED
|
@@ -3,31 +3,31 @@ import type { ImmutableMap } from "./map.js";
|
|
|
3
3
|
import type { Match } from "./match.js";
|
|
4
4
|
import type { ImmutableObject } from "./object.js";
|
|
5
5
|
/** Is unknown value `left` exactly equal to `right`? */
|
|
6
|
-
export declare
|
|
6
|
+
export declare function isEqual<T>(left: unknown, right: T): left is T;
|
|
7
7
|
/** Is unknown value `left` not exactly equal to `right`? */
|
|
8
|
-
export declare
|
|
8
|
+
export declare function notEqual<T, N>(left: T | N, right: N): left is T;
|
|
9
9
|
/** Is unknown value `left` less than `right`? */
|
|
10
|
-
export declare
|
|
10
|
+
export declare function isLess(left: unknown, right: unknown): boolean;
|
|
11
11
|
/** Is unknown value `left` less than or equal to `right`? */
|
|
12
|
-
export declare
|
|
12
|
+
export declare function isEqualLess(left: unknown, right: unknown): boolean;
|
|
13
13
|
/** Is unknown value `left` greater than `right`? */
|
|
14
|
-
export declare
|
|
14
|
+
export declare function isGreater(left: unknown, right: unknown): boolean;
|
|
15
15
|
/** Is unknown value `left` greater than or equal to `right`? */
|
|
16
|
-
export declare
|
|
16
|
+
export declare function isEqualGreater(left: unknown, right: unknown): boolean;
|
|
17
17
|
/**
|
|
18
18
|
* Are two unknown values shallowly equal?
|
|
19
19
|
* - If the values are both arrays/objects, see if the items/properties are **shallowly** equal with each other.
|
|
20
20
|
*/
|
|
21
|
-
export declare
|
|
21
|
+
export declare function isShallowEqual<T extends unknown>(left: unknown, right: T): left is T;
|
|
22
22
|
/** Are two unknown values not shallowly equal? */
|
|
23
|
-
export declare
|
|
23
|
+
export declare function notShallowEqual<T extends unknown>(left: unknown, right: T): left is T;
|
|
24
24
|
/**
|
|
25
25
|
* Are two unknown values deeply equal?
|
|
26
26
|
* - If the values are both arrays/objects, see if the items/properties are **deeply** equal with each other.
|
|
27
27
|
*/
|
|
28
|
-
export declare
|
|
28
|
+
export declare function isDeepEqual<T extends unknown>(left: unknown, right: T): left is T;
|
|
29
29
|
/** Are two unknown values not deeply equal? */
|
|
30
|
-
export declare
|
|
30
|
+
export declare function notDeepEqual<T extends unknown>(left: unknown, right: T): left is T;
|
|
31
31
|
/**
|
|
32
32
|
* Are two maps equal (based on their items).
|
|
33
33
|
*/
|
|
@@ -41,13 +41,13 @@ export declare function isMapEqual<T extends ImmutableMap>(left: ImmutableMap, r
|
|
|
41
41
|
*/
|
|
42
42
|
export declare function isArrayEqual<T extends ImmutableArray>(left: ImmutableArray, right: T, recursor?: Match): left is T;
|
|
43
43
|
/** Is unknown value `left` in array `right`? */
|
|
44
|
-
export declare
|
|
44
|
+
export declare function isInArray<R>(left: unknown, right: ImmutableArray<R>): left is R;
|
|
45
45
|
/** Is unknown value `left` not in array `right`? */
|
|
46
|
-
export declare
|
|
46
|
+
export declare function notInArray(left: unknown, right: ImmutableArray): boolean;
|
|
47
47
|
/** Is unknown value `left` an array including `right`? */
|
|
48
|
-
export declare
|
|
48
|
+
export declare function isArrayWith<T>(left: unknown, right: T): left is ImmutableArray<T>;
|
|
49
49
|
/** Is unknown value `left` not an array or does not include `right`? */
|
|
50
|
-
export declare
|
|
50
|
+
export declare function notArrayWith(left: unknown, right: unknown): boolean;
|
|
51
51
|
/**
|
|
52
52
|
* Are two objects equal based on their own props?
|
|
53
53
|
* - `left` must have every property present in `right`
|
|
@@ -69,6 +69,6 @@ export declare function isObjectEqual<T extends ImmutableObject>(left: Immutable
|
|
|
69
69
|
*/
|
|
70
70
|
export declare function isObjectMatch<L extends ImmutableObject, R extends ImmutableObject>(left: L | R, right: R, recursor?: Match): left is L & R;
|
|
71
71
|
/** Is unknown value `left` an object with every prop from `right`? */
|
|
72
|
-
export declare
|
|
72
|
+
export declare function isObjectWith(left: unknown, right: ImmutableObject): boolean;
|
|
73
73
|
/** Is unknown value `left` not an object or missing one or more props from `right`? */
|
|
74
|
-
export declare
|
|
74
|
+
export declare function notObjectWith(left: unknown, right: ImmutableObject): boolean;
|