UNPKG

rawsql-ts

Version:

[beta]High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.

61 lines (60 loc) 2.42 kB
export type NewlineLogicalName = 'lf' | 'crlf' | 'cr'; export type NewlineOption = NewlineLogicalName | '\n' | '\r\n' | '\r' | ' '; export type IndentCharLogicalName = 'space' | 'tab'; export type IndentCharOption = IndentCharLogicalName | string; export type CommaBreakStyle = 'none' | 'before' | 'after'; /** * SqlPrintHelper provides utility methods for SQL pretty printing. */ export declare class LinePrinter { indentChar: IndentCharOption; indentSize: number; newline: NewlineOption; commaBreak: CommaBreakStyle; lines: PrintLine[]; /** * @param indentChar Character used for indentation (default: ' ') // Accepts logical names like 'space'/'tab' * @param indentSize Number of indentChar per level (default: 0) * @param newline Newline string (default: '\r\n') // Accepts logical names like 'lf'/'crlf'/'cr' * @param commaBreak Comma break style (default: 'none') */ constructor(indentChar?: IndentCharOption, indentSize?: number, newline?: NewlineOption, commaBreak?: CommaBreakStyle); print(): string; /** * Returns the indent string for a given level. * @param level Indentation level */ private indent; /** * Appends a newline token to the given tokens array if newline is set, or adds an empty line if tokens is empty. * @param tokens Array of token objects with 'level' and 'text' property * @param level Indentation level */ appendNewline(level: number): void; /** * Appends text to the last element of tokens array. * @param tokens Array of token objects with 'text' property * @param text Text to append */ appendText(text: string): void; trimTrailingWhitespaceFromPreviousLine(): void; /** * Cleans up the current line for comma formatting. * For 'after' and 'none' comma styles, removes empty line when a comma is being added. * @param text The text being processed * @returns true if cleanup was performed, false otherwise */ cleanupLine(text: string): boolean; private lineHasTrailingComment; getCurrentLine(): PrintLine; /** * Checks if the current line is empty (has no text content) * @returns true if current line is empty, false otherwise */ isCurrentLineEmpty(): boolean; } export declare class PrintLine { level: number; text: string; constructor(level: number, text: string); }