import { ChartPoint, DateRange } from '../entities/chart-entities'; import { Option } from '@suntech-innovation/option'; import { MarketStatus } from '../../../entities'; /** * Safe version of ChartHelper methods using Option * This demonstrates how to replace unsafe operations with safe Option-based ones */ export declare class ChartSafeHelper { /** * Safe version of findClosesDatePoints - replaces unsafe array access */ static findClosesDatePoints(line: ChartPoint[], range: DateRange): Option; /** * Safe version of findClosestIndex - returns Option instead of null */ static findClosestIndex(line: number[], input: number): number; /** * Safe array head operation */ static safeHead(array: T[]): Option; /** * Safe array last operation */ static safeLast(array: T[]): Option; /** * Safe property access using Option */ static safeGet(obj: unknown, path: string | string[]): Option; /** * Safe price range calculation */ static setPaddingsForPriceSafe(range: { from?: number; to?: number; }): Option; /** * Safe status compaction */ static compactStatusesSafe(prices: ChartPoint[]): Option; /** * Safe range finder by status */ static findRangeByStatusSafe(line: ChartPoint[], status: MarketStatus): Option; /** * Safe canvas context operations */ static withCanvasContext(canvas: HTMLCanvasElement | null, operation: (ctx: CanvasRenderingContext2D) => T): Option; /** * Safe DOM element operations */ static withElement(elementId: string, operation: (element: HTMLElement) => T): Option; /** * Safe numeric operations with bounds checking */ static safeCalculate(a: unknown, b: unknown, operation: (x: number, y: number) => number): Option; /** * Safe line filtering for date range */ static filterLineForDateRangeSafe(line: ChartPoint[], range: DateRange): Option; /** * Safe array operations with error handling */ static processArraySafe(array: T[], processor: (item: T, index: number) => U | null | undefined): U[]; /** * Example of safe bet states processing */ static processBetStatesSafe(betStates: unknown[] | undefined): { firstState: Option; lastState: Option; validStates: unknown[]; }; /** * Safe position calculation using Option pattern * Returns value from 0 to 1 as percent of position * Replaces unsafe try-catch with explicit Option handling */ static getPositionSafe(value: number, range: DateRange, convert?: (i: number) => number): Option; /** * Safe position calculation with default fallback * Compatible with existing code that expects a number return */ static getPosition(value: number, range: DateRange, convert?: (i: number) => number): number; /** * Safe short number formatting * Replaces unsafe string operations with Option-based approach */ static shortNumberSafe(n: unknown): Option; /** * Safe grid step calculation * Returns None if calculation is invalid */ static getGridStepSafe(range: DateRange, available?: number[], limit?: number): Option; /** * Safe bounds checking for chart coordinates */ static isInBounds(x: number, y: number, bounds: { width: number; height: number; }): Option<{ x: number; y: number; }>; /** * Safe color validation and normalization */ static validateColor(color: unknown): Option; /** * Safe timestamp validation and conversion */ static validateTimestamp(timestamp: unknown): Option; /** * Safe chart point validation */ static validateChartPoint(point: unknown): Option; }