Home / Function/ formatTable() — astro Function Reference

formatTable() — astro Function Reference

Architecture documentation for the formatTable() function in index.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  b7a701fd_4441_5459_1118_014908ce259d["formatTable()"]
  f7d3fd10_bcd7_7c85_17b8_a4feb9026da8["index.ts"]
  b7a701fd_4441_5459_1118_014908ce259d -->|defined in| f7d3fd10_bcd7_7c85_17b8_a4feb9026da8
  f72816d7_841e_fbeb_de77_6ad73e837140["listPreferences()"]
  f72816d7_841e_fbeb_de77_6ad73e837140 -->|calls| b7a701fd_4441_5459_1118_014908ce259d
  a2c2e7e3_9b77_6370_f433_b592e516c189["prettyPrint()"]
  a2c2e7e3_9b77_6370_f433_b592e516c189 -->|calls| b7a701fd_4441_5459_1118_014908ce259d
  50b5948a_96b2_b389_2307_1539d52083ed["space()"]
  b7a701fd_4441_5459_1118_014908ce259d -->|calls| 50b5948a_96b2_b389_2307_1539d52083ed
  2293e4b2_08b0_47f9_c2cb_b32f623b2878["formatAnnotated()"]
  b7a701fd_4441_5459_1118_014908ce259d -->|calls| 2293e4b2_08b0_47f9_c2cb_b32f623b2878
  81afa77e_0702_34ae_6d58_ddb83c1b77d7["annotatedFormat()"]
  b7a701fd_4441_5459_1118_014908ce259d -->|calls| 81afa77e_0702_34ae_6d58_ddb83c1b77d7
  style b7a701fd_4441_5459_1118_014908ce259d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/cli/preferences/index.ts lines 336–375

function formatTable(object: Record<string, AnnotatedValue>, columnLabels: [string, string]) {
	const [colA, colB] = columnLabels;
	const colALength = [colA, ...Object.keys(object)].reduce(longest, 0) + 3;
	const colBLength = [colB, ...Object.values(object).map(annotatedFormat)].reduce(longest, 0) + 3;
	function formatRow(
		_i: number,
		a: string,
		b: AnnotatedValue,
		style: (value: string) => string = (v) => v.toString(),
	): string {
		return `${dim(chars.v)} ${style(a)} ${space(colALength - a.length - 2)} ${dim(
			chars.v,
		)} ${formatAnnotated(b, style)} ${space(colBLength - annotatedFormat(b).length - 3)} ${dim(
			chars.v,
		)}`;
	}
	const top = dim(
		`${chars.topLeft}${chars.h.repeat(colALength + 1)}${chars.hBottom}${chars.h.repeat(
			colBLength,
		)}${chars.topRight}`,
	);
	const bottom = dim(
		`${chars.bottomLeft}${chars.h.repeat(colALength + 1)}${chars.hTop}${chars.h.repeat(
			colBLength,
		)}${chars.bottomRight}`,
	);
	const divider = dim(
		`${chars.vRightThick}${chars.hThick.repeat(colALength + 1)}${
			chars.hThickCross
		}${chars.hThick.repeat(colBLength)}${chars.vLeftThick}`,
	);
	const rows: string[] = [top, formatRow(-1, colA, { value: colB, annotation: '' }, bold), divider];
	let i = 0;
	for (const [key, value] of Object.entries(object)) {
		rows.push(formatRow(i, key, value, (v) => formatWithOptions({ colors: true }, v)));
		i++;
	}
	rows.push(bottom);
	return rows.join('\n');
}

Domain

Subdomains

Frequently Asked Questions

What does formatTable() do?
formatTable() is a function in the astro codebase, defined in packages/astro/src/cli/preferences/index.ts.
Where is formatTable() defined?
formatTable() is defined in packages/astro/src/cli/preferences/index.ts at line 336.
What does formatTable() call?
formatTable() calls 3 function(s): annotatedFormat, formatAnnotated, space.
What calls formatTable()?
formatTable() is called by 2 function(s): listPreferences, prettyPrint.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free