Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/deno/std/prettier/vendor/standalone.d.ts>formatWithCursor

A modern runtime for JavaScript and TypeScript.
Go to Latest
function formatWithCursor
import { formatWithCursor } from "https://deno.land/x/deno@v0.23.0/std/prettier/vendor/standalone.d.ts";

formatWithCursor both formats the code, and translates a cursor position from unformatted code to formatted code. This is useful for editor integrations, to prevent the cursor from moving when code is formatted

The cursorOffset option should be provided, to specify where the cursor is. This option cannot be used with rangeStart and rangeEnd.

prettier.formatWithCursor(" 1", { cursorOffset: 2, parser: "babel" });

-> { formatted: '1;\n', cursorOffset: 1 }

Parameters

source: string
options: CursorOptions