UNPKG

rawsql-ts

Version:

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

63 lines (62 loc) 2.17 kB
import { LineColumn } from './LexemeCursor'; /** * Utility functions for text position conversion and manipulation * * Provides centralized functionality for converting between different * position representations commonly used in text processing and SQL parsing. */ export declare class TextPositionUtils { /** * Convert line/column position to character offset * * @param text - Source text * @param position - Line/column position (1-based) * @returns Character offset (0-based) or -1 if invalid * * @example * ```typescript * const text = "SELECT id\nFROM users"; * const charOffset = TextPositionUtils.lineColumnToCharOffset(text, { line: 2, column: 1 }); * console.log(charOffset); // 10 (position of 'F' in 'FROM') * ``` */ static lineColumnToCharOffset(text: string, position: LineColumn): number; /** * Convert character offset to line/column position * * @param text - Source text * @param charOffset - Character offset (0-based) * @returns Line/column position (1-based) or null if invalid * * @example * ```typescript * const text = "SELECT id\nFROM users"; * const position = TextPositionUtils.charOffsetToLineColumn(text, 10); * console.log(position); // { line: 2, column: 1 } * ``` */ static charOffsetToLineColumn(text: string, charOffset: number): LineColumn | null; /** * Check if a position is within text bounds * * @param text - Source text * @param position - Line/column position (1-based) * @returns True if position is valid */ static isValidPosition(text: string, position: LineColumn): boolean; /** * Get the line at the specified line number * * @param text - Source text * @param lineNumber - Line number (1-based) * @returns Line content or null if invalid */ static getLine(text: string, lineNumber: number): string | null; /** * Get the total number of lines in text * * @param text - Source text * @returns Number of lines */ static getLineCount(text: string): number; }