function withLineNumbers
withLineNumbers(
contents: string,
file: string,
palette: Theme
): string

A file with its lines numbered, the way anybody quoting one writes them down.

1 | let something = 'something';
2 | function me() {

Numbers are right-aligned to the longest of them, so the gutter is a straight edge and the code starts in one column rather than drifting at line 100.

Exported for its own test — .cat is its only caller, and a unit test can hand it two strings instead of a terminal and a file on disk.

import { withLineNumbers } from './cat.ts';

const plain = { painter: () => (text: string) => text };
withLineNumbers('a\nb', 'x.txt', plain); // '1 | a\n2 | b' — the gutter is themed too

Parameters

contents: string
file: string
palette: Theme

Return Type

string

Usage

import { withLineNumbers } from "lib/commands/repl/commands/cat.ts";