standalone.d.ts 1.4 KB

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