@regele/devtools
Version:
A collection of developer utilities for code processing and text analysis
108 lines (107 loc) • 2.89 kB
TypeScript
import { FileType, FormattingOptions } from './utils';
import { FileOptions, FileResult } from './cli/fileUtils';
declare global {
interface Window {
prettier?: any;
prettierPlugins?: Record<string, any>;
}
}
/**
* Code Beautifier class for formatting code
*/
export declare class Beautifier {
private options;
private prettier;
/**
* Create a new Beautifier instance
*
* @param options - Formatting options
* @param prettier - Optional prettier instance
*/
constructor(options?: Partial<FormattingOptions>, prettier?: any);
/**
* Format code using Prettier if available, or fallback to simple formatting
*
* @param code - The code to format
* @param fileType - The file type or language
* @returns Formatted code
*/
format(code: string, fileType?: FileType | string): Promise<string>;
/**
* Format code using provided Prettier instance
*
* @param code - The code to format
* @param fileType - The file type
* @returns Formatted code
*/
private formatWithPrettier;
/**
* Format code using browser-loaded Prettier
*
* @param code - The code to format
* @param fileType - The file type
* @returns Formatted code
*/
private formatWithBrowserPrettier;
/**
* Get the appropriate Prettier parser for a file type
*
* @param fileType - The file type
* @returns The parser name
*/
private getPrettierParser;
/**
* Format code using simple formatters when Prettier is not available
*
* @param code - The code to format
* @returns Formatted code
*/
private formatWithSimpleFormatters;
/**
* Basic code indentation
*
* @param code - The code to indent
* @returns Indented code
*/
private indentCode;
/**
* Format quotes in code
*
* @param code - The code to format
* @returns Formatted code
*/
private formatQuotes;
/**
* Format semicolons in code
*
* @param code - The code to format
* @returns Formatted code
*/
private formatSemicolons;
/**
* Update formatting options
*
* @param options - New options to apply
*/
updateOptions(options: Partial<FormattingOptions>): void;
/**
* Get current formatting options
*
* @returns The current options
*/
getOptions(): FormattingOptions;
/**
* Set Prettier instance
*
* @param prettier - Prettier instance to use
*/
setPrettier(prettier: any): void;
/**
* Format multiple files
*
* @param patterns - Glob patterns to match files
* @param options - File options
* @returns Results of the operations
*/
formatFiles(patterns: string | string[], options?: FileOptions): Promise<FileResult[]>;
}