method ReplSession.preview
ReplSession.preview(
input: string,
depth?: number
): Promise<string>

What the input WOULD evaluate to, or '' where it cannot be known without doing something.

depth is how far into a composite to render, for a caller that wants the whole of a value rather than the line-long summary a prompt has room for.

V8 refuses to run anything with a side effect for this: an assignment, a declaration, a call that mutates. That refusal is the feature, and it is why three different commands can afford to call it — an answer offered before Enter has to be free, and deleteEverything() typed at a prompt must not delete everything because it was typed.

The three: the right-margin preview, on every keystroke, at the default depth; .view, at a depth deep enough to render the whole of a value; and .copy, which puts that text on the clipboard. depth is the only thing that differs between them.

Parameters

input: string
optional
depth: number

Return Type

Promise<string>

Usage

import { type ReplSession } from "lib/repl/session.ts";