@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
77 lines • 2.4 kB
TypeScript
/**
* Validate a template before processing
*
* Checks for common syntax errors and structural issues:
* - Unclosed directive blocks (@if without @endif)
* - Unclosed expression brackets
* - Invalid directive syntax
* - Nested quote issues
* - Security-related patterns
*
* @param template - The template string to validate
* @returns Validation result with errors and warnings
*
* @example
* ```typescript
* const result = validateTemplate(templateString)
* if (!result.valid) {
* console.error('Template errors:', result.errors)
* }
* ```
*/
export declare function validateTemplate(template: string): TemplateValidationResult;
/**
* Get line and column information for a position in the template
*
* @param template - The template string
* @param position - Character position
* @returns Line and column numbers (1-indexed)
*/
export declare function getPositionInfo(template: string, position: number): { line: number, column: number };
/**
* Validate a specific directive's syntax
*
* @param directiveName - Name of the directive (without @)
* @param content - Content between directive tags
* @param params - Parameters passed to the directive
* @returns Validation errors, if any
*/
export declare function validateDirective(directiveName: string, content: string, params: string[]): TemplateValidationError[];
/**
* Check if a template has any directives
*
* @param template - The template string
* @returns Whether the template contains any stx directives
*/
export declare function hasDirectives(template: string): boolean;
/**
* Extract all directive names used in a template
*
* @param template - The template string
* @returns Array of directive names (without @ prefix)
*/
export declare function extractDirectiveNames(template: string): string[];
/**
* Template Validation
*
* Provides validation utilities for stx templates before processing.
* Checks for common syntax errors, structural issues, and potential security problems.
*/
/**
* Template validation error
*/
export declare interface TemplateValidationError {
type: 'syntax' | 'directive' | 'expression' | 'structure'
message: string
line?: number
column?: number
suggestion?: string
}
/**
* Template validation result
*/
export declare interface TemplateValidationResult {
valid: boolean
errors: TemplateValidationError[]
warnings: TemplateValidationError[]
}