Code Frame API
Last updated:
Code Frame API
codeFrame(source, location, options?)
Generate code frame showing error location.
Parameters:
source(string): Source codelocation(object): Error locationstart.line(number): Start linestart.column(number): Start columnend(object, optional): End location
options(object, optional):linesAbove(number): Lines above errorlinesBelow(number): Lines below errormessage(string): Error message
Returns: Formatted code frame string
Example:
const frame = codeFrame(source, {
start: { line: 2, column: 10 },
end: { line: 2, column: 15 }
}, {
linesAbove: 2,
linesBelow: 2,
message: "Unexpected token"
});