function blockAt
blockAt(
source: string,
line: number
): string

A whole declaration — its first line through the } that closes it.

Counted from tokens, so a brace inside a string or a comment in the body does not end it early. A declaration with no body at all is the line it is written on.

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

blockAt('function a() {\n  return 1;\n}\nconst b = 2;', 1); // 'function a() {\n  return 1;\n}'
blockAt('const b = 2;', 1); // 'const b = 2;'

Parameters

source: string
line: number

Return Type

string

Usage

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