foldFlowLines.d.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. export declare const FOLD_FLOW = "flow";
  2. export declare const FOLD_BLOCK = "block";
  3. export declare const FOLD_QUOTED = "quoted";
  4. /**
  5. * `'block'` prevents more-indented lines from being folded;
  6. * `'quoted'` allows for `\` escapes, including escaped newlines
  7. */
  8. export type FoldMode = 'flow' | 'block' | 'quoted';
  9. export interface FoldOptions {
  10. /**
  11. * Accounts for leading contents on the first line, defaulting to
  12. * `indent.length`
  13. */
  14. indentAtStart?: number;
  15. /** Default: `80` */
  16. lineWidth?: number;
  17. /**
  18. * Allow highly indented lines to stretch the line width or indent content
  19. * from the start.
  20. *
  21. * Default: `20`
  22. */
  23. minContentWidth?: number;
  24. /** Called once if the text is folded */
  25. onFold?: () => void;
  26. /** Called once if any line of text exceeds lineWidth characters */
  27. onOverflow?: () => void;
  28. }
  29. /**
  30. * Tries to keep input at up to `lineWidth` characters, splitting only on spaces
  31. * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
  32. * terminated with `\n` and started with `indent`.
  33. */
  34. export declare function foldFlowLines(text: string, indent: string, mode?: FoldMode, { indentAtStart, lineWidth, minContentWidth, onFold, onOverflow }?: FoldOptions): string;