padEnd Aligns Report Columns
padEnd left-aligns names while padStart right-aligns numbers, producing fixed-width report columns; over-wide values are never truncated.
Code
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 999999Inside 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
Duration HumanizerTurn a number of seconds into a readable duration such as 1 day, 2 hours, 3 minutes, and show the equivalent in minutes and hours.Git Conventional Commit BuilderBuild and validate Conventional Commits v1.0.0 messages with type, scope, breaking markers, 72-char subject counter, body, footers, and git CLI command.Glob Pattern TesterCompile glob patterns with *, **, ?, character classes, and braces into regex and test them against a list of candidate file paths.Indentation ConverterConvert leading indentation between tabs and spaces at a chosen width, leaving inner content untouched.
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`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.