UNPKG

@typespec/compiler

Version:

TypeSpec Compiler Preview

23 lines 973 B
import { ok } from "assert"; /** * Takes source code with a cursor position indicated by the given marker * ("┆" by default), and returns the source without the marker along with * the cursor position. */ export function extractCursor(sourceWithCursor, marker = "┆") { const pos = sourceWithCursor.indexOf(marker); ok(pos >= 0, "marker not found"); const source = sourceWithCursor.replace(marker, ""); return { source, pos }; } /** * Takes source code with start and end positions indicated by given marker * ("~~~" by default) and returns the source without the markers along with * the start and end positions. */ export function extractSquiggles(sourceWithSquiggles, marker = "~~~") { const { source: sourceWithoutFistSquiggle, pos } = extractCursor(sourceWithSquiggles, marker); const { source, pos: end } = extractCursor(sourceWithoutFistSquiggle, marker); return { source, pos, end }; } //# sourceMappingURL=source-utils.js.map