Skip to main content
Deno 2 is finally 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.28.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