padEnd Aligns Report Columns

padEnd left-aligns names while padStart right-aligns numbers, producing fixed-width report columns; over-wide values are never truncated.

JavascriptCli Tooling

Code

javascriptsnippet
19 lines
const rows = [
  { service: "api", p95: 120 },
  { service: "billing", p95: 88 },
  { service: "web", p95: 1420 },
];

// 左列 padEnd 对齐,右列 padStart 靠右,表头同宽
const nameWidth = 12;
const valueWidth = 8;
console.log("service".padEnd(nameWidth) + "p95_ms".padStart(valueWidth));
for (const row of rows) {
  console.log(
    row.service.padEnd(nameWidth) +
    String(row.p95).padStart(valueWidth),
  );
}

// 超宽的值不会被截断,只影响该行总宽
console.log("very-long-service".padEnd(nameWidth) + "999999".padStart(valueWidth));

Output

Captured from a sandboxed run of this snippet in the build pipeline.

service       p95_ms
api              120
billing           88
web             1420
very-long-service  999999

Inside the snippet

Iteration happens inside for (const row of rows) — everything outside it runs once.

Everything operates on top-level bindings: rows, nameWidth, valueWidth.

Points of care

  • No package manager involved — every call resolves to a built-in API.

Putting it to use

The run emits 2 labeled sections — service, very-long-service — one per step.

Core lines

row.service.padEnd(nameWidth) +
String(row.p95).padStart(valueWidth),
);
const nameWidth = 12;
const valueWidth = 8;

Interactive Tools for This Topic

FAQ

What does the package manager see?
An empty dependency file. The snippet imports nothing that needs fetching. Its state lives in module-level bindings: `rows`, `nameWidth`, `valueWidth`.