shelving 1.89.4 → 1.89.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.
- package/package.json +1 -1
- package/util/debug.d.ts +5 -6
- package/util/debug.js +29 -16
package/package.json
CHANGED
package/util/debug.d.ts
CHANGED
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
import type { ImmutableArray } from "./array.js";
|
|
3
3
|
import type { ImmutableMap } from "./map.js";
|
|
4
4
|
import type { ImmutableSet } from "./set.js";
|
|
5
|
-
import type { ImmutableObject } from "./object.js";
|
|
6
5
|
/** Debug a random value as a string. */
|
|
7
|
-
export declare function debug(value: unknown): string;
|
|
6
|
+
export declare function debug(value: unknown, depth?: number): string;
|
|
8
7
|
/** Debug a string. */
|
|
9
8
|
export declare const debugString: (value: string) => string;
|
|
10
9
|
/** Debug an array. */
|
|
11
|
-
export declare function debugArray(value: ImmutableArray): string;
|
|
10
|
+
export declare function debugArray(value: ImmutableArray, depth?: number): string;
|
|
12
11
|
/** Debug a set. */
|
|
13
|
-
export declare function debugSet(value: ImmutableSet): string;
|
|
12
|
+
export declare function debugSet(value: ImmutableSet, depth?: number): string;
|
|
14
13
|
/** Debug a map. */
|
|
15
|
-
export declare function debugMap(value: ImmutableMap): string;
|
|
14
|
+
export declare function debugMap(value: ImmutableMap, depth?: number): string;
|
|
16
15
|
/** Debug an object. */
|
|
17
|
-
export declare function debugObject(value:
|
|
16
|
+
export declare function debugObject(value: object, depth?: number): string;
|
package/util/debug.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-control-regex */
|
|
2
2
|
/** Debug a random value as a string. */
|
|
3
|
-
export function debug(value) {
|
|
3
|
+
export function debug(value, depth = 1) {
|
|
4
4
|
if (value === null)
|
|
5
5
|
return "null";
|
|
6
6
|
if (value === undefined)
|
|
@@ -21,12 +21,12 @@ export function debug(value) {
|
|
|
21
21
|
if (value instanceof Error)
|
|
22
22
|
return value.toString();
|
|
23
23
|
if (value instanceof Array)
|
|
24
|
-
return debugArray(value);
|
|
24
|
+
return debugArray(value, depth);
|
|
25
25
|
if (value instanceof Map)
|
|
26
|
-
return debugMap(value);
|
|
26
|
+
return debugMap(value, depth);
|
|
27
27
|
if (value instanceof Set)
|
|
28
|
-
return debugSet(value);
|
|
29
|
-
return debugObject(value);
|
|
28
|
+
return debugSet(value, depth);
|
|
29
|
+
return debugObject(value, depth);
|
|
30
30
|
}
|
|
31
31
|
return typeof value;
|
|
32
32
|
}
|
|
@@ -36,29 +36,42 @@ const ESCAPE_REGEXP = /[\x00-\x08\x0B-\x1F\x7F-\x9F"\\]/g; // Match control char
|
|
|
36
36
|
const ESCAPE_LIST = { '"': '\\"', "\\": "\\\\", "\r": "\\r", "\n": "\\n", "\t": "\\t", "\b": "\\b", "\f": "\\f", "\v": "\\v" };
|
|
37
37
|
const _escapeChar = (char) => ESCAPE_LIST[char] || `\\x${char.charCodeAt(0).toString(16).padStart(2, "00")}`;
|
|
38
38
|
/** Debug an array. */
|
|
39
|
-
export function debugArray(value) {
|
|
39
|
+
export function debugArray(value, depth = 1) {
|
|
40
40
|
const prototype = Object.getPrototypeOf(value);
|
|
41
41
|
const name = prototype === Array.prototype ? "" : prototype.constructor.name || "";
|
|
42
|
-
|
|
42
|
+
const items = depth > 0 && value.length ? value.map(v => debug(v, depth - 1)).join(",\n\t") : "";
|
|
43
|
+
return `${name ? `${name} ` : ""}${value.length ? `[\n\t${items}\n]` : "[]"}`;
|
|
43
44
|
}
|
|
44
45
|
/** Debug a set. */
|
|
45
|
-
export function debugSet(value) {
|
|
46
|
+
export function debugSet(value, depth = 1) {
|
|
46
47
|
const prototype = Object.getPrototypeOf(value);
|
|
47
48
|
const name = prototype === Set.prototype ? "" : prototype.constructor.name || "Set";
|
|
48
|
-
|
|
49
|
+
const items = depth > 0 && value.size
|
|
50
|
+
? Array.from(value)
|
|
51
|
+
.map(v => debug(v, depth - 1))
|
|
52
|
+
.join(",\n\t")
|
|
53
|
+
: "";
|
|
54
|
+
return `${name}(value.size) ${items ? `{\n\t${items}\n}` : "{}"}`;
|
|
49
55
|
}
|
|
50
56
|
/** Debug a map. */
|
|
51
|
-
export function debugMap(value) {
|
|
57
|
+
export function debugMap(value, depth = 1) {
|
|
52
58
|
const prototype = Object.getPrototypeOf(value);
|
|
53
59
|
const name = prototype === Map.prototype ? "" : prototype.constructor.name || "Map";
|
|
54
|
-
|
|
60
|
+
const entries = depth > 0 && value.size
|
|
61
|
+
? Array.from(value)
|
|
62
|
+
.map(([k, v]) => `${debug(k)}: ${debug(v, depth - 1)}`)
|
|
63
|
+
.join(",\n\t")
|
|
64
|
+
: "";
|
|
65
|
+
return `${name}(value.size) ${entries ? `{\n\t${entries}\n}` : "{}"}`;
|
|
55
66
|
}
|
|
56
67
|
/** Debug an object. */
|
|
57
|
-
export function debugObject(value) {
|
|
68
|
+
export function debugObject(value, depth = 1) {
|
|
58
69
|
const prototype = Object.getPrototypeOf(value);
|
|
59
70
|
const name = prototype === Object.prototype ? "" : prototype.constructor.name || "";
|
|
60
|
-
const
|
|
61
|
-
|
|
71
|
+
const entries = depth > 0
|
|
72
|
+
? Object.entries(value)
|
|
73
|
+
.map(([k, v]) => `${debug(k)}: ${debug(v, depth - 1)}`)
|
|
74
|
+
.join(",\n\t")
|
|
75
|
+
: "";
|
|
76
|
+
return `${name ? `${name} ` : ""}${entries ? `{\n\t${entries}\n}` : "{}"}`;
|
|
62
77
|
}
|
|
63
|
-
/** Debug a prop. */
|
|
64
|
-
const _debugProp = ([key, value]) => `${debug(key)}: ${debug(value)}`;
|