UNPKG

1.37 kBTypeScriptView Raw
1import { CursorOptions, CursorResult, Options, SupportInfo } from "./index.js";
2
3/**
4 * formatWithCursor both formats the code, and translates a cursor position from unformatted code to formatted code.
5 * This is useful for editor integrations, to prevent the cursor from moving when code is formatted
6 *
7 * The cursorOffset option should be provided, to specify where the cursor is.
8 *
9 * ```js
10 * await prettier.formatWithCursor(" 1", { cursorOffset: 2, parser: "babel" });
11 * ```
12 * `-> { formatted: "1;\n", cursorOffset: 1 }`
13 */
14export function formatWithCursor(
15 source: string,
16 options: CursorOptions,
17): Promise<CursorResult>;
18
19/**
20 * `format` is used to format text using Prettier. [Options](https://prettier.io/docs/en/options.html) may be provided to override the defaults.
21 */
22export function format(source: string, options?: Options): Promise<string>;
23
24/**
25 * `check` checks to see if the file has been formatted with Prettier given those options and returns a `Boolean`.
26 * This is similar to the `--list-different` parameter in the CLI and is useful for running Prettier in CI scenarios.
27 */
28export function check(source: string, options?: Options): Promise<boolean>;
29
30/**
31 * Returns an object representing the parsers, languages and file types Prettier supports for the current version.
32 */
33export function getSupportInfo(): Promise<SupportInfo>;