@nomicfoundation/hardhat-utils 3.0.3 → 3.0.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.
@@ -7,28 +7,30 @@ export async function getDeepCloneFunction() {
7
7
  }
8
8
  return clone;
9
9
  }
10
- export function deepMergeImpl(target, source) {
10
+ export function deepMergeImpl(target, source, shouldOverwriteUndefined) {
11
11
  /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
12
- -- The result is expected to include properties from both target and source,
13
- but initially only target is spread in, so a cast is needed. */
12
+ -- Result will include properties from both T and S, but starts with only T */
14
13
  const result = { ...target };
15
- /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
16
- -- TypeScript cannot infer the correct union of string and symbol keys, but all keys come from U */
14
+ /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
15
+ -- All keys come from S, TypeScript can't infer the union of string and symbol keys */
17
16
  const keys = [
18
17
  ...Object.keys(source),
19
18
  ...Object.getOwnPropertySymbols(source),
20
19
  ];
21
20
  for (const key of keys) {
22
21
  if (isObject(source[key]) &&
23
- // Only merge recursively objects that are not class instances
22
+ // Only merge plain objects, not class instances
24
23
  Object.getPrototypeOf(source[key]) === Object.prototype) {
25
24
  /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
- -- The call signature expects the second argument to be of type U; the type is correct, but TypeScript can't infer it here. */
27
- result[key] = deepMergeImpl(result[key] ?? {}, source[key]);
25
+ -- result[key] will have the correct type after assignment but TS can't infer it */
26
+ result[key] = deepMergeImpl(result[key] ?? {},
27
+ /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
28
+ -- source[key] is known to be from S but TS can't infer it */
29
+ source[key], shouldOverwriteUndefined);
28
30
  }
29
- else {
31
+ else if (shouldOverwriteUndefined || source[key] !== undefined) {
30
32
  /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
31
- -- Cast required because TypeScript can't guarantee that a dynamic key from `U` exists in `T & U` or has the correct value type. */
33
+ -- result[key] will have the correct type after assignment but TS can't infer it */
32
34
  result[key] = source[key];
33
35
  }
34
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"lang.js","sourceRoot":"","sources":["../../../src/internal/lang.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,IAAI,KAAK,GAAoC,IAAI,CAAC;AAClD,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IAE/C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,KAAK,GAAG,IAAI,EAAE,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,MAAS,EACT,MAAS;IAET;;mEAE+D;IAC/D,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAW,CAAC;IAEtC;uGACmG;IACnG,MAAM,IAAI,GAAG;QACX,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;QACtB,GAAG,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC;KACtB,CAAC;IAEpB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IACE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,8DAA8D;YAC9D,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,SAAS,EACvD,CAAC;YACD;0IAC8H;YAC9H,MAAM,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,GAAG,CAAM,CACjC,CAAC;QACjC,CAAC;aAAM,CAAC;YACN;gJACoI;YACpI,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAsC,CAAC;QACjE,CAAC;IACH,CAAC;IA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AAG,MAAM,CAAC,GAAG,CAAsC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function panicErrorCodeToReason(errorCode: bigint): string | undefined;
2
+ //# sourceMappingURL=panic-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panic-errors.d.ts","sourceRoot":"","sources":["../../../src/internal/panic-errors.ts"],"names":[],"mappings":"AAAA,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAsB5E"}
@@ -0,0 +1,24 @@
1
+ export function panicErrorCodeToReason(errorCode) {
2
+ // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- we are only covering some of the integer range
3
+ switch (errorCode) {
4
+ case 0x1n:
5
+ return "Assertion error";
6
+ case 0x11n:
7
+ return "Arithmetic operation overflowed outside of an unchecked block";
8
+ case 0x12n:
9
+ return "Division or modulo division by zero";
10
+ case 0x21n:
11
+ return "Tried to convert a value into an enum, but the value was too big or negative";
12
+ case 0x22n:
13
+ return "Incorrectly encoded storage byte array";
14
+ case 0x31n:
15
+ return ".pop() was called on an empty array";
16
+ case 0x32n:
17
+ return "Array accessed at an out-of-bounds or negative index";
18
+ case 0x41n:
19
+ return "Too much memory was allocated, or an array was created that is too large";
20
+ case 0x51n:
21
+ return "Called a zero-initialized variable of internal function type";
22
+ }
23
+ }
24
+ //# sourceMappingURL=panic-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panic-errors.js","sourceRoot":"","sources":["../../../src/internal/panic-errors.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,sBAAsB,CAAC,SAAiB;IACtD,4HAA4H;IAC5H,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,IAAI;YACP,OAAO,iBAAiB,CAAC;QAC3B,KAAK,KAAK;YACR,OAAO,+DAA+D,CAAC;QACzE,KAAK,KAAK;YACR,OAAO,qCAAqC,CAAC;QAC/C,KAAK,KAAK;YACR,OAAO,8EAA8E,CAAC;QACxF,KAAK,KAAK;YACR,OAAO,wCAAwC,CAAC;QAClD,KAAK,KAAK;YACR,OAAO,qCAAqC,CAAC;QAC/C,KAAK,KAAK;YACR,OAAO,sDAAsD,CAAC;QAChE,KAAK,KAAK;YACR,OAAO,0EAA0E,CAAC;QACpF,KAAK,KAAK;YACR,OAAO,8DAA8D,CAAC;IAC1E,CAAC;AACH,CAAC"}
@@ -18,20 +18,28 @@ export declare function deepEqual<T>(x: T, y: T): Promise<boolean>;
18
18
  *
19
19
  * @remarks
20
20
  * - Arrays or `undefined` values are not valid inputs.
21
- * - Functions: If a function exists in both the target and source, the source function overwrites the target.
22
- * - Symbol properties: Symbol-keyed properties are merged just like string keys.
23
- * - Class instances: Class instances are not merged recursively. If a class instance exists in the source, it will replace the one in the target.
21
+ * - Functions: If a function exists in both the target and source, the source
22
+ * function overwrites the target.
23
+ * - Symbol properties: Symbol-keyed properties are merged just like string
24
+ * keys.
25
+ * - Class instances: Class instances are not merged recursively. If a class
26
+ * instance exists in the source, it will replace the one in the target.
24
27
  *
25
28
  * @param target The target object to merge into.
26
29
  * @param source The source object to merge from.
30
+ * @param shouldOverwriteUndefined If true, properties with `undefined` values
31
+ * in the source will overwrite those in the target. Default is true.
27
32
  * @returns A new object containing the deeply merged properties.
28
33
  *
29
34
  * @example
30
35
  * deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // => { a: { b: 1, c: 2 } }
31
36
  *
32
- * deepMerge({ a: { fn: () => "from target" } }, { a: { fn: () => "from source" } }) // => { a: { fn: () => "from source" } }
37
+ * deepMerge(
38
+ * { a: { fn: () => "from target" } },
39
+ * { a: { fn: () => "from source" } }
40
+ * ) // => { a: { fn: () => "from source" } }
33
41
  */
34
- export declare function deepMerge<T extends object, U extends object>(target: T, source: U): T & U;
42
+ export declare function deepMerge<T extends object, U extends object>(target: T, source: U, shouldOverwriteUndefined?: boolean): T & U;
35
43
  /**
36
44
  * Checks if a value is an object. This function returns false for arrays.
37
45
  *
@@ -1 +1 @@
1
- {"version":3,"file":"lang.d.ts","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIvD;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAI/D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC1D,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,CAAC,CAEP;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAE3C;AAED;;;;;GAKG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CA4BzE"}
1
+ {"version":3,"file":"lang.d.ts","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIvD;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAI/D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAC1D,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,EACT,wBAAwB,GAAE,OAAc,GACvC,CAAC,GAAG,CAAC,CAEP;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAE3C;AAED;;;;;GAKG;AACH,wBAAsB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CA4BzE"}
package/dist/src/lang.js CHANGED
@@ -25,21 +25,29 @@ export async function deepEqual(x, y) {
25
25
  *
26
26
  * @remarks
27
27
  * - Arrays or `undefined` values are not valid inputs.
28
- * - Functions: If a function exists in both the target and source, the source function overwrites the target.
29
- * - Symbol properties: Symbol-keyed properties are merged just like string keys.
30
- * - Class instances: Class instances are not merged recursively. If a class instance exists in the source, it will replace the one in the target.
28
+ * - Functions: If a function exists in both the target and source, the source
29
+ * function overwrites the target.
30
+ * - Symbol properties: Symbol-keyed properties are merged just like string
31
+ * keys.
32
+ * - Class instances: Class instances are not merged recursively. If a class
33
+ * instance exists in the source, it will replace the one in the target.
31
34
  *
32
35
  * @param target The target object to merge into.
33
36
  * @param source The source object to merge from.
37
+ * @param shouldOverwriteUndefined If true, properties with `undefined` values
38
+ * in the source will overwrite those in the target. Default is true.
34
39
  * @returns A new object containing the deeply merged properties.
35
40
  *
36
41
  * @example
37
42
  * deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // => { a: { b: 1, c: 2 } }
38
43
  *
39
- * deepMerge({ a: { fn: () => "from target" } }, { a: { fn: () => "from source" } }) // => { a: { fn: () => "from source" } }
44
+ * deepMerge(
45
+ * { a: { fn: () => "from target" } },
46
+ * { a: { fn: () => "from source" } }
47
+ * ) // => { a: { fn: () => "from source" } }
40
48
  */
41
- export function deepMerge(target, source) {
42
- return deepMergeImpl(target, source);
49
+ export function deepMerge(target, source, shouldOverwriteUndefined = true) {
50
+ return deepMergeImpl(target, source, shouldOverwriteUndefined);
43
51
  }
44
52
  /**
45
53
  * Checks if a value is an object. This function returns false for arrays.
@@ -1 +1 @@
1
- {"version":3,"file":"lang.js","sourceRoot":"","sources":["../../src/lang.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,KAAQ;IACzC,MAAM,UAAU,GAAG,MAAM,oBAAoB,EAAE,CAAC;IAEhD,OAAO,UAAU,CAAI,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAI,CAAI,EAAE,CAAI;IAC3C,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAE9D,OAAO,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,SAAS,CACvB,MAAS,EACT,MAAS;IAET,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAc;IAEd,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAe;IACzC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAA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C3F,MAAM,gBAAgB,GAAG;QACvB,aAAa;QACb,gBAAgB;QAChB,eAAe;QACf,sBAAsB;QACtB,gBAAgB;QAChB,UAAU;QACV,SAAS;KACV,CAAC;IAEF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,OAAO,GAAG,KAAK,UAAU,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACjE,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,2 +1,15 @@
1
+ /**
2
+ * Converts a Solidity panic error code into a human-readable revert message.
3
+ *
4
+ * Solidity defines a set of standardized panic codes (0x01, 0x11, etc.)
5
+ * that represent specific runtime errors (e.g. arithmetic overflow).
6
+ * This function looks up the corresponding reason string and formats it
7
+ * into a message similar to what clients like Hardhat or ethers.js display.
8
+ *
9
+ * @param errorCode The panic error code returned by the EVM as a bigint.
10
+ * @returns A formatted message string:
11
+ * - `"reverted with panic code <hex> (<reason>)"` if the code is recognized.
12
+ * - `"reverted with unknown panic code <hex>"` if the code is not recognized.
13
+ */
1
14
  export declare function panicErrorCodeToMessage(errorCode: bigint): string;
2
15
  //# sourceMappingURL=panic-errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"panic-errors.d.ts","sourceRoot":"","sources":["../../src/panic-errors.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAQjE"}
1
+ {"version":3,"file":"panic-errors.d.ts","sourceRoot":"","sources":["../../src/panic-errors.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAQjE"}
@@ -1,4 +1,18 @@
1
1
  import { numberToHexString } from "./hex.js";
2
+ import { panicErrorCodeToReason } from "./internal/panic-errors.js";
3
+ /**
4
+ * Converts a Solidity panic error code into a human-readable revert message.
5
+ *
6
+ * Solidity defines a set of standardized panic codes (0x01, 0x11, etc.)
7
+ * that represent specific runtime errors (e.g. arithmetic overflow).
8
+ * This function looks up the corresponding reason string and formats it
9
+ * into a message similar to what clients like Hardhat or ethers.js display.
10
+ *
11
+ * @param errorCode The panic error code returned by the EVM as a bigint.
12
+ * @returns A formatted message string:
13
+ * - `"reverted with panic code <hex> (<reason>)"` if the code is recognized.
14
+ * - `"reverted with unknown panic code <hex>"` if the code is not recognized.
15
+ */
2
16
  export function panicErrorCodeToMessage(errorCode) {
3
17
  const reason = panicErrorCodeToReason(errorCode);
4
18
  if (reason !== undefined) {
@@ -6,27 +20,4 @@ export function panicErrorCodeToMessage(errorCode) {
6
20
  }
7
21
  return `reverted with unknown panic code ${numberToHexString(errorCode)}`;
8
22
  }
9
- function panicErrorCodeToReason(errorCode) {
10
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- we are only covering some of the integer range
11
- switch (errorCode) {
12
- case 0x1n:
13
- return "Assertion error";
14
- case 0x11n:
15
- return "Arithmetic operation overflowed outside of an unchecked block";
16
- case 0x12n:
17
- return "Division or modulo division by zero";
18
- case 0x21n:
19
- return "Tried to convert a value into an enum, but the value was too big or negative";
20
- case 0x22n:
21
- return "Incorrectly encoded storage byte array";
22
- case 0x31n:
23
- return ".pop() was called on an empty array";
24
- case 0x32n:
25
- return "Array accessed at an out-of-bounds or negative index";
26
- case 0x41n:
27
- return "Too much memory was allocated, or an array was created that is too large";
28
- case 0x51n:
29
- return "Called a zero-initialized variable of internal function type";
30
- }
31
- }
32
23
  //# sourceMappingURL=panic-errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"panic-errors.js","sourceRoot":"","sources":["../../src/panic-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAA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,OAAO,oCAAoC,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;AAC5E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomicfoundation/hardhat-utils",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "description": "Utilities for Hardhat and its plugins",
5
5
  "homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-utils",
6
6
  "repository": {
@@ -23,6 +23,7 @@
23
23
  "./env": "./dist/src/env.js",
24
24
  "./error": "./dist/src/error.js",
25
25
  "./eth": "./dist/src/eth.js",
26
+ "./format": "./dist/src/format.js",
26
27
  "./fs": "./dist/src/fs.js",
27
28
  "./global-dir": "./dist/src/global-dir.js",
28
29
  "./hex": "./dist/src/hex.js",
package/src/format.ts ADDED
@@ -0,0 +1,267 @@
1
+ import {
2
+ getColumnWidths,
3
+ getContentWidth,
4
+ getHeadingWidth,
5
+ getStringWidth,
6
+ renderContentLine,
7
+ renderHeaderOpen,
8
+ renderRowSeparator,
9
+ renderSectionClose,
10
+ } from "./internal/format.js";
11
+
12
+ export type TableRow = string[];
13
+ export interface TableDivider {
14
+ type: "divider";
15
+ }
16
+ export type TableItem = TableRow | TableDivider;
17
+
18
+ export const divider: TableDivider = { type: "divider" };
19
+
20
+ /**
21
+ * Formats an array of rows and dividers into a table string.
22
+ *
23
+ * @param items An array of table rows (string arrays) and dividers.
24
+ * Dividers are objects with type: "divider" and will be rendered as table dividers.
25
+ * @returns The formatted table as a string, ready to be rendered.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * formatTable([
30
+ * ["Name", "Age"],
31
+ * divider,
32
+ * ["Alice", "30"],
33
+ * ["Bob", "25"],
34
+ * divider,
35
+ * ["Average", "27.5"]
36
+ * ]);
37
+ *
38
+ * // =>
39
+ * // | Name | Age |
40
+ * // | ------- | ---- |
41
+ * // | Alice | 30 |
42
+ * // | Bob | 25 |
43
+ * // | ------- | ---- |
44
+ * // | Average | 27.5 |
45
+ * ```
46
+ */
47
+ export function formatTable(items: TableItem[]): string {
48
+ const widths: number[] = [];
49
+ const dataRows: string[][] = [];
50
+
51
+ for (const item of items) {
52
+ if (Array.isArray(item)) {
53
+ dataRows.push([...item]);
54
+ }
55
+ }
56
+
57
+ // Calculate maximum width for each column
58
+ for (const row of dataRows) {
59
+ for (let i = 0; i < row.length; i++) {
60
+ while (i >= widths.length) {
61
+ widths.push(0);
62
+ }
63
+ widths[i] = Math.max(widths[i], getStringWidth(row[i]));
64
+ }
65
+ }
66
+
67
+ const dividerRow = widths.map((width) => "-".repeat(width));
68
+ const outputRows: string[][] = [];
69
+
70
+ for (const item of items) {
71
+ if (Array.isArray(item)) {
72
+ const row = [...item];
73
+ // Pad the row to match the number of columns
74
+ while (row.length < widths.length) {
75
+ row.push("");
76
+ }
77
+ outputRows.push(row);
78
+ } else {
79
+ outputRows.push([...dividerRow]);
80
+ }
81
+ }
82
+
83
+ outputRows.forEach((row) => {
84
+ for (let i = 0; i < row.length; i++) {
85
+ const displayWidth = getStringWidth(row[i]);
86
+ const actualLength = row[i].length;
87
+ // Adjust padding to account for difference between display width and actual length
88
+ row[i] = row[i].padEnd(widths[i] + actualLength - displayWidth);
89
+ }
90
+ });
91
+
92
+ return outputRows.map((row) => `| ${row.join(" | ")} |`).join("\n");
93
+ }
94
+
95
+ export interface TableTitleV2 {
96
+ type: "title";
97
+ text: string;
98
+ }
99
+
100
+ export interface TableSectionHeaderV2 {
101
+ type: "section-header";
102
+ text: string;
103
+ }
104
+
105
+ export interface TableHeaderV2 {
106
+ type: "header";
107
+ cells: string[];
108
+ }
109
+
110
+ export interface TableRowV2 {
111
+ type: "row";
112
+ cells: string[];
113
+ }
114
+
115
+ export type TableItemV2 =
116
+ | TableTitleV2
117
+ | TableSectionHeaderV2
118
+ | TableHeaderV2
119
+ | TableRowV2;
120
+
121
+ /**
122
+ * Formats an array of titles, section headers, headers, and rows into a table
123
+ * string with box-drawing characters.
124
+ *
125
+ * Features:
126
+ * - Titles are centered in a standalone box with double borders (╔═╗)
127
+ * - Section headers group related content with automatic closing
128
+ * - Headers and rows can have different numbers of cells
129
+ * - Rows with fewer cells than max columns are handled with special rendering
130
+ *
131
+ * @param items An array of table items (titles, section headers, headers, and rows).
132
+ * Sections are automatically closed when a new section-header or title appears, or
133
+ * at the end of the table.
134
+ * @returns The formatted table as a string, ready to be rendered.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * formatTableV2([
139
+ * { type: "title", text: "My Table" },
140
+ * { type: "section-header", text: "User Data" },
141
+ * { type: "header", cells: ["Name", "Age", "City"] },
142
+ * { type: "row", cells: ["Alice", "30", "NYC"] },
143
+ * { type: "row", cells: ["Bob", "25", "LA"] },
144
+ * { type: "section-header", text: "Summary" },
145
+ * { type: "header", cells: ["Total", "Count"] },
146
+ * { type: "row", cells: ["55", "2"] }
147
+ * ]);
148
+ *
149
+ * // =>
150
+ * // ╔═══════════════════╗
151
+ * // ║ My Table ║
152
+ * // ╚═══════════════════╝
153
+ * // ╔═══════════════════╗
154
+ * // ║ User Data ║
155
+ * // ╟───────┬─────┬─────╢
156
+ * // ║ Name │ Age │ City║
157
+ * // ╟───────┼─────┼─────╢
158
+ * // ║ Alice │ 30 │ NYC ║
159
+ * // ╟───────┼─────┼─────╢
160
+ * // ║ Bob │ 25 │ LA ║
161
+ * // ╚═══════╧═════╧═════╝
162
+ * // ╔═══════════════════╗
163
+ * // ║ Summary ║
164
+ * // ╟───────┬───────────╢
165
+ * // ║ Total │ Count ║
166
+ * // ╟───────┼───────────╢
167
+ * // ║ 55 │ 2 ║
168
+ * // ╚═══════╧═══════════╝
169
+ * ```
170
+ */
171
+ export function formatTableV2(items: TableItemV2[]): string {
172
+ if (items.length === 0) {
173
+ return "";
174
+ }
175
+
176
+ const columnWidths = getColumnWidths(items);
177
+ const contentWidth = getContentWidth(columnWidths);
178
+ const headingWidth = getHeadingWidth(items);
179
+
180
+ // If heading is wider than content, expand last column to fit
181
+ if (headingWidth > contentWidth && columnWidths.length > 0) {
182
+ const extraSpace = headingWidth - contentWidth;
183
+ columnWidths[columnWidths.length - 1] += extraSpace;
184
+ }
185
+
186
+ const tableWidth = Math.max(contentWidth, headingWidth);
187
+
188
+ const lines: string[] = [];
189
+ let previousCellCount = 0; // Keep track of previous row/header cell count
190
+ let inSection = false;
191
+
192
+ for (let i = 0; i < items.length; i++) {
193
+ const [previous, current] = [items[i - 1], items[i]];
194
+
195
+ if (current.type === "title") {
196
+ if (inSection) {
197
+ lines.push(renderSectionClose(columnWidths, previousCellCount));
198
+ inSection = false;
199
+ }
200
+
201
+ lines.push("╔" + "═".repeat(tableWidth) + "╗");
202
+ const titleDisplayWidth = getStringWidth(current.text);
203
+ const titleActualLength = current.text.length;
204
+ const centeredTitle = current.text
205
+ .padStart(
206
+ (tableWidth + titleDisplayWidth) / 2 +
207
+ (titleActualLength - titleDisplayWidth),
208
+ )
209
+ .padEnd(tableWidth + (titleActualLength - titleDisplayWidth));
210
+ lines.push("║" + centeredTitle + "║");
211
+ lines.push("╚" + "═".repeat(tableWidth) + "╝");
212
+ } else if (current.type === "section-header") {
213
+ if (inSection) {
214
+ lines.push(renderSectionClose(columnWidths, previousCellCount));
215
+ }
216
+
217
+ lines.push("╔" + "═".repeat(tableWidth) + "╗");
218
+ const headerDisplayWidth = getStringWidth(current.text);
219
+ const headerActualLength = current.text.length;
220
+ const paddedHeader = current.text.padEnd(
221
+ tableWidth - 2 + (headerActualLength - headerDisplayWidth),
222
+ );
223
+ lines.push("║ " + paddedHeader + " ║");
224
+ inSection = true;
225
+ } else if (current.type === "header") {
226
+ const currentCellCount = current.cells.length;
227
+ const innerJoiner =
228
+ previous !== undefined && previous.type === "section-header"
229
+ ? "┬"
230
+ : "┼";
231
+ const needsTransition =
232
+ previous !== undefined &&
233
+ previous.type !== "section-header" &&
234
+ currentCellCount < previousCellCount;
235
+
236
+ lines.push(
237
+ renderHeaderOpen(
238
+ columnWidths,
239
+ currentCellCount,
240
+ innerJoiner,
241
+ needsTransition,
242
+ ),
243
+ );
244
+ lines.push(
245
+ renderContentLine(current.cells, columnWidths, currentCellCount),
246
+ );
247
+ previousCellCount = currentCellCount;
248
+ } else if (current.type === "row") {
249
+ const currentCellCount = current.cells.length;
250
+
251
+ // Only add separator if previous wasn't a row
252
+ if (previous === undefined || previous.type !== "row") {
253
+ lines.push(renderRowSeparator(columnWidths, currentCellCount));
254
+ }
255
+ lines.push(
256
+ renderContentLine(current.cells, columnWidths, currentCellCount),
257
+ );
258
+ previousCellCount = currentCellCount;
259
+ }
260
+ }
261
+
262
+ if (inSection) {
263
+ lines.push(renderSectionClose(columnWidths, previousCellCount));
264
+ }
265
+
266
+ return lines.join("\n");
267
+ }