@dxos/util 0.8.4-main.72ec0f3 → 0.8.4-main.7ace549

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/util",
3
- "version": "0.8.4-main.72ec0f3",
3
+ "version": "0.8.4-main.7ace549",
4
4
  "description": "Temporary bucket for misc functions, which should graduate into separate packages.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -29,15 +29,15 @@
29
29
  "dependencies": {
30
30
  "lodash.get": "^4.4.2",
31
31
  "lodash.set": "^4.3.2",
32
- "@dxos/debug": "0.8.4-main.72ec0f3",
33
- "@dxos/invariant": "0.8.4-main.72ec0f3",
34
- "@dxos/node-std": "0.8.4-main.72ec0f3",
35
- "@dxos/keys": "0.8.4-main.72ec0f3"
32
+ "@dxos/debug": "0.8.4-main.7ace549",
33
+ "@dxos/invariant": "0.8.4-main.7ace549",
34
+ "@dxos/keys": "0.8.4-main.7ace549",
35
+ "@dxos/node-std": "0.8.4-main.7ace549"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/lodash.get": "^4.4.9",
39
39
  "@types/lodash.set": "^4.3.9",
40
- "@dxos/crypto": "0.8.4-main.72ec0f3"
40
+ "@dxos/crypto": "0.8.4-main.7ace549"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Formats an error with its cause chain.
3
+ */
4
+ //
5
+ // Copyright 2025 DXOS.org
6
+ //
7
+
8
+ export const formatErrorWithCauses = (error: Error): string => {
9
+ const lines: string[] = [];
10
+ let current: Error | undefined = error;
11
+ let level = 0;
12
+
13
+ while (current) {
14
+ const prefix = level === 0 ? '' : `Caused by: `;
15
+ lines.push(prefix + (current.stack ?? String(current)));
16
+ if (!(current.cause instanceof Error)) break;
17
+ current = current.cause;
18
+ level += 1;
19
+ }
20
+
21
+ return lines.join('\n\n');
22
+ };
package/src/index.ts CHANGED
@@ -54,3 +54,4 @@ export * from './uint8array';
54
54
  export * from './unit';
55
55
  export * from './url';
56
56
  export * from './weak';
57
+ export * from './error-format';
package/src/types.ts CHANGED
@@ -12,6 +12,14 @@ export type MaybePromise<T> = T | Promise<T>;
12
12
 
13
13
  export type GuardedType<T> = T extends (value: any) => value is infer R ? R : never;
14
14
 
15
+ export type ToMutable<T> = T extends object
16
+ ? { -readonly [K in keyof T]: T[K] extends readonly (infer U)[] ? U[] : T[K] }
17
+ : T;
18
+
19
+ export type Intersection<Types extends readonly unknown[]> = Types extends [infer First, ...infer Rest]
20
+ ? First & Intersection<Rest>
21
+ : unknown;
22
+
15
23
  export type DeepReadonly<T> = {
16
24
  readonly [P in keyof T]: T[P] extends Record<string, any>
17
25
  ? DeepReadonly<T[P]>
package/src/unit.ts CHANGED
@@ -42,6 +42,7 @@ export const Unit: Record<string, UnitFormat> = {
42
42
  Gigabyte: createFormat({ symbol: 'GB', quotient: 1_000 * 1_000 * 1_000, precision: 2 }),
43
43
  Megabyte: createFormat({ symbol: 'MB', quotient: 1_000 * 1_000, precision: 2 }),
44
44
  Kilobyte: createFormat({ symbol: 'KB', quotient: 1_000, precision: 2 }),
45
+ Byte: createFormat({ symbol: 'B', quotient: 1 }),
45
46
 
46
47
  // Time.
47
48
  Hour: createFormat({ symbol: 'h', quotient: MS_HOURS }),