shelving 1.92.2 → 1.93.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/error/AssertionError.d.ts +5 -2
- package/error/AssertionError.js +11 -4
- package/feedback/Feedbacks.js +3 -1
- package/package.json +1 -1
- package/util/assert.d.ts +1 -1
- package/util/assert.js +2 -2
- package/util/debug.d.ts +2 -0
- package/util/debug.js +5 -0
- package/util/object.d.ts +4 -0
- package/util/object.js +4 -0
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
* Thrown if the program receives a value it didn't expect.
|
|
3
3
|
*
|
|
4
4
|
* @param message Message that explains why the thing happened.
|
|
5
|
-
* @param
|
|
5
|
+
* @param received The value that made the assertion fail.
|
|
6
|
+
* @param expected The value that made the assertion fail.
|
|
6
7
|
*/
|
|
7
8
|
export declare class AssertionError extends Error {
|
|
8
|
-
|
|
9
|
+
readonly received: unknown;
|
|
10
|
+
readonly expected: unknown;
|
|
11
|
+
constructor(message?: string, ...receivedExpected: readonly [received?: unknown, expected?: unknown]);
|
|
9
12
|
}
|
package/error/AssertionError.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import { debug } from "../util/debug.js";
|
|
1
|
+
import { debug, indent } from "../util/debug.js";
|
|
2
2
|
/**
|
|
3
3
|
* Thrown if the program receives a value it didn't expect.
|
|
4
4
|
*
|
|
5
5
|
* @param message Message that explains why the thing happened.
|
|
6
|
-
* @param
|
|
6
|
+
* @param received The value that made the assertion fail.
|
|
7
|
+
* @param expected The value that made the assertion fail.
|
|
7
8
|
*/
|
|
8
9
|
export class AssertionError extends Error {
|
|
9
|
-
constructor(message = "Failed assertion", ...
|
|
10
|
-
super(
|
|
10
|
+
constructor(message = "Failed assertion", ...receivedExpected) {
|
|
11
|
+
super(receivedExpected.length >= 2 //
|
|
12
|
+
? `${message}\nReceived:${indent(debug(receivedExpected[0]))}\nExpected:${indent(debug(receivedExpected[0]))}`
|
|
13
|
+
: receivedExpected.length >= 1
|
|
14
|
+
? `${message}\nReceived:${indent(debug(receivedExpected[0]))}`
|
|
15
|
+
: message);
|
|
16
|
+
this.received = receivedExpected[0];
|
|
17
|
+
this.expected = receivedExpected[1];
|
|
11
18
|
}
|
|
12
19
|
}
|
|
13
20
|
AssertionError.prototype.name = "AssertionError";
|
package/feedback/Feedbacks.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { indent } from "../util/debug.js";
|
|
1
2
|
import { getProp } from "../util/object.js";
|
|
2
3
|
import { mapDictionary } from "../util/transform.js";
|
|
3
4
|
import { Feedback } from "./Feedback.js";
|
|
@@ -8,7 +9,8 @@ export class Feedbacks extends Feedback {
|
|
|
8
9
|
return mapDictionary(this.feedbacks, getProp, "message");
|
|
9
10
|
}
|
|
10
11
|
constructor(feedbacks, value) {
|
|
11
|
-
super("
|
|
12
|
+
super(`${Object.entries(feedbacks).map(_mapMessages).join("\n")}`, value);
|
|
12
13
|
this.feedbacks = feedbacks;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
16
|
+
const _mapMessages = ([name, { message }]) => `${name}:${indent(message)}`;
|
package/package.json
CHANGED
package/util/assert.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Assert a boolean condition is true. */
|
|
2
|
-
export declare function assert(condition: unknown, ...
|
|
2
|
+
export declare function assert(condition: unknown, ...receivedExpected: [received?: unknown, expected?: unknown]): asserts condition;
|
|
3
3
|
/** Assert two values are equal. */
|
|
4
4
|
export declare function assertEqual<T>(left: T | unknown, right: T): asserts left is T;
|
|
5
5
|
/** Assert two values are equal. */
|
package/util/assert.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AssertionError } from "../error/AssertionError.js";
|
|
2
2
|
/** Assert a boolean condition is true. */
|
|
3
|
-
export function assert(condition, ...
|
|
3
|
+
export function assert(condition, ...receivedExpected) {
|
|
4
4
|
if (!condition)
|
|
5
|
-
throw new AssertionError(`Must assert`, ...
|
|
5
|
+
throw new AssertionError(`Must assert`, ...receivedExpected);
|
|
6
6
|
}
|
|
7
7
|
/** Assert two values are equal. */
|
|
8
8
|
export function assertEqual(left, right) {
|
package/util/debug.d.ts
CHANGED
|
@@ -14,3 +14,5 @@ export declare function debugSet(value: ImmutableSet, depth?: number): string;
|
|
|
14
14
|
export declare function debugMap(value: ImmutableMap, depth?: number): string;
|
|
15
15
|
/** Debug an object. */
|
|
16
16
|
export declare function debugObject(value: object, depth?: number): string;
|
|
17
|
+
/** If a string is multiline, push it onto the next line and prepend a tab to each line.. */
|
|
18
|
+
export declare function indent(str: string): string;
|
package/util/debug.js
CHANGED
|
@@ -75,3 +75,8 @@ export function debugObject(value, depth = 1) {
|
|
|
75
75
|
: "";
|
|
76
76
|
return `${name ? `${name} ` : ""}${entries ? `{\n\t${entries}\n}` : "{}"}`;
|
|
77
77
|
}
|
|
78
|
+
/** If a string is multiline, push it onto the next line and prepend a tab to each line.. */
|
|
79
|
+
export function indent(str) {
|
|
80
|
+
const lines = str.split("\n");
|
|
81
|
+
return lines.length > 1 ? `\n${lines.join("\n\t")}` : ` ${str}`;
|
|
82
|
+
}
|
package/util/object.d.ts
CHANGED
|
@@ -77,6 +77,10 @@ export declare function getKeys<T>(obj: T | Partial<T>): ImmutableArray<Key<T>>;
|
|
|
77
77
|
export declare function getKeys<T>(obj: T | Partial<T> | Iterable<Key<T>>): Iterable<Key<T>>;
|
|
78
78
|
/** Extract the value of a named prop from an object. */
|
|
79
79
|
export declare function getProp<T, K extends Key<T>>(obj: T, key: K): T[K];
|
|
80
|
+
/** Create an object from a single prop. */
|
|
81
|
+
export declare function fromProp<K extends PropertyKey, V>(key: K, value: V): {
|
|
82
|
+
readonly [KK in K]: V;
|
|
83
|
+
};
|
|
80
84
|
/** Set a prop on an object (immutably) and return a new object including that prop. */
|
|
81
85
|
export declare function withProp<T extends ImmutableObject, K extends Key<T>>(input: T, key: K, value: T[K]): T;
|
|
82
86
|
/** Set several props on an object (immutably) and return a new object including those props. */
|
package/util/object.js
CHANGED
|
@@ -36,6 +36,10 @@ export function getKeys(obj) {
|
|
|
36
36
|
export function getProp(obj, key) {
|
|
37
37
|
return obj[key];
|
|
38
38
|
}
|
|
39
|
+
/** Create an object from a single prop. */
|
|
40
|
+
export function fromProp(key, value) {
|
|
41
|
+
return { [key]: value };
|
|
42
|
+
}
|
|
39
43
|
/** Set a prop on an object (immutably) and return a new object including that prop. */
|
|
40
44
|
export function withProp(input, key, value) {
|
|
41
45
|
return input[key] === value ? input : { __proto__: getPrototype(input), ...input, [key]: value };
|