function commentAbove
commentAbove(
source: string,
line: number
): string[]

The comment written directly above a line, with its markers taken off.

Directly above, with nothing between: a comment separated from what it describes by a blank line is describing something else. Both spellings, since a codebase has both — a /** … *\/ block, or a run of // lines.

import { commentAbove } from './docs.ts';

commentAbove('// what it does\nexport const a = 1;', 2); // ['what it does']
commentAbove('const a = 1;\nconst b = 2;', 2); // [] — nothing is being said about it

Parameters

source: string
line: number

Return Type

string[]

Usage

import { commentAbove } from "lib/repl/docs.ts";