UNPKG

@ry-krystal/kicad-converter

Version:

专业的KiCad符号文件与JSON互转工具

148 lines (147 loc) 3.54 kB
/** * 通用工具函数模块 * 提供文件操作、路径处理、配置管理等功能 */ /** * 文件工具类 */ export declare class FileUtils { /** * 安全读取文件 */ static readFile(filePath: string, encoding?: BufferEncoding): string | null; /** * 安全写入文件 */ static writeFile(filePath: string, content: string, encoding?: BufferEncoding): boolean; /** * 检查文件是否存在 */ static exists(filePath: string): boolean; /** * 获取文件信息 */ static getFileInfo(filePath: string): { size: number; isFile: boolean; isDirectory: boolean; } | null; /** * 递归查找文件 */ static findFiles(dir: string, extensions: string[], recursive?: boolean): string[]; } /** * 路径工具类 */ export declare class PathUtils { /** * 标准化路径分隔符 */ static normalize(path: string): string; /** * 获取文件扩展名 */ static getExtension(filePath: string): string; /** * 获取文件名(不含扩展名) */ static getNameWithoutExt(filePath: string): string; /** * 更改文件扩展名 */ static changeExtension(filePath: string, newExt: string): string; /** * 生成安全的文件名 */ static sanitizeFilename(filename: string): string; /** * 确保目录存在 */ static ensureDir(dirPath: string): boolean; } /** * 配置管理类 */ export declare class ConfigManager { private static configCache; /** * 加载配置文件 */ static loadConfig(configPath: string, defaultConfig?: any): any; /** * 保存配置文件 */ static saveConfig(configPath: string, config: any): boolean; /** * 清理配置缓存 */ static clearCache(configPath?: string): void; } /** * 日志工具类 */ export declare class Logger { private verbose; private quiet; constructor(verbose?: boolean, quiet?: boolean); info(message: string): void; success(message: string): void; warn(message: string): void; error(message: string): void; debug(message: string): void; verboseLog(message: string): void; } /** * 性能计时器 */ export declare class Timer { private startTime; private marks; constructor(); /** * 设置时间标记 */ mark(name: string): void; /** * 获取从开始到现在的时间 */ elapsed(): number; /** * 获取两个标记之间的时间 */ measure(startMark: string, endMark?: string): number; /** * 格式化时间显示 */ static formatTime(ms: number): string; } /** * 数据验证工具 */ export declare class Validator { /** * 验证文件路径 */ static validatePath(path: string, shouldExist?: boolean): { valid: boolean; message?: string; }; /** * 验证文件扩展名 */ static validateExtension(filename: string, validExtensions: string[]): boolean; /** * 验证JSON格式 */ static validateJson(content: string): { valid: boolean; data?: any; error?: string; }; } export declare const fileUtils: typeof FileUtils; export declare const pathUtils: typeof PathUtils; export declare const configManager: typeof ConfigManager; export declare function createLogger(verbose?: boolean, quiet?: boolean): Logger; export declare function createTimer(): Timer;