Add line numbers
Aa TextAdd line numbers to a code snippet
$ echo "const x = 1;
const y = 2;
return x + y;" | number-lines (input, opts = {}) => {
const start = parseInt(opts.start) || 1;
const lines = input.split("\n");
const pad = String(lines.length + start - 1).length;
return lines
.map((l, i) => `${String(i + start).padStart(pad, " ")} ${l}`)
.join("\n");
}