Utilities
Utilities
Section titled “Utilities”API reference for utility functions and hooks.
exportToCSV
Section titled “exportToCSV”Export data to CSV format.
Signature
Section titled “Signature”function exportToCSV<T>( data: T[], columns: ColumnDef<T>[], options?: CSVExportOptions): string | voidParameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | T[] | Array of data objects to export |
columns | ColumnDef<T>[] | Column definitions (determines fields and headers) |
options | CSVExportOptions | Export options |
Options
Section titled “Options”interface CSVExportOptions { filename?: string; // Default: 'export.csv' delimiter?: string; // Default: ',' includeHeaders?: boolean; // Default: true download?: boolean; // Default: true}Returns
Section titled “Returns”- When
download: true(default): Returnsvoid, triggers browser download - When
download: false: Returns CSV string
Examples
Section titled “Examples”import { exportToCSV } from '@askturret/grid';
// Download CSVexportToCSV(data, columns, { filename: 'users.csv' });
// Get CSV stringconst csv = exportToCSV(data, columns, { download: false });
// Custom delimiterexportToCSV(data, columns, { delimiter: ';' });
// Without headersexportToCSV(data, columns, { includeHeaders: false });formatPrice
Section titled “formatPrice”Format a number as a price string.
Signature
Section titled “Signature”function formatPrice(value: number, decimals?: number): stringParameters
Section titled “Parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
value | number | required | The price value |
decimals | number | 2 | Decimal places |
Examples
Section titled “Examples”import { formatPrice } from '@askturret/grid';
formatPrice(1234.5); // '1,234.50'formatPrice(1234.5678, 4); // '1,234.5678'formatPrice(-50.5); // '-50.50'formatQuantity
Section titled “formatQuantity”Format a number as a quantity string with thousands separators.
Signature
Section titled “Signature”function formatQuantity(value: number, decimals?: number): stringParameters
Section titled “Parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
value | number | required | The quantity value |
decimals | number | 0 | Decimal places |
Examples
Section titled “Examples”import { formatQuantity } from '@askturret/grid';
formatQuantity(1000); // '1,000'formatQuantity(1234567); // '1,234,567'formatQuantity(100.5, 2); // '100.50'formatPnL
Section titled “formatPnL”Format a number as P&L with sign prefix.
Signature
Section titled “Signature”function formatPnL(value: number, decimals?: number): stringParameters
Section titled “Parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
value | number | required | The P&L value |
decimals | number | 2 | Decimal places |
Examples
Section titled “Examples”import { formatPnL } from '@askturret/grid';
formatPnL(100.5); // '+100.50'formatPnL(-50.25); // '-50.25'formatPnL(0); // '0.00'useAdaptiveFlash
Section titled “useAdaptiveFlash”Hook for FPS-aware flash highlighting control.
Signature
Section titled “Signature”function useAdaptiveFlash(): { enabled: boolean; fps: number;}Returns
Section titled “Returns”| Property | Type | Description |
|---|---|---|
enabled | boolean | Whether flash effects should be shown |
fps | number | Current frames per second |
Behavior
Section titled “Behavior”- Disables flash when FPS drops below 55
- Re-enables flash when FPS recovers above 58
- Updates every second
Example
Section titled “Example”import { useAdaptiveFlash } from '@askturret/grid';
function PerformanceMonitor() { const { enabled, fps } = useAdaptiveFlash();
return ( <div> FPS: {fps} | Flash: {enabled ? 'ON' : 'OFF'} </div> );}initWasm
Section titled “initWasm”Initialize the WASM core module.
Signature
Section titled “Signature”function initWasm(): Promise<void>Description
Section titled “Description”Initializes the optional WASM core for accelerated sorting and filtering. Call this at app startup for immediate availability.
Example
Section titled “Example”import { initWasm } from '@askturret/grid';
// In app initializationasync function init() { await initWasm(); // WASM is now ready}- Returns immediately if WASM is already initialized
- Returns immediately if WASM core is not installed
- Grid automatically calls this on first use if not pre-initialized
Exported Types
Section titled “Exported Types”All types are exported from the main package:
import type { // DataGrid DataGridProps, ColumnDef, SortState,
// OrderBook OrderBookProps, OrderBookData, OrderBookLevel,
// TimeSales TimeSalesProps, Trade,
// PositionLadder PositionLadderProps, LadderLevel, Position,
// TopMovers TopMoversProps, MoverItem,
// Utilities CSVExportOptions,} from '@askturret/grid';SortState
Section titled “SortState”interface SortState { field: string; direction: 'asc' | 'desc';}OrderBookData
Section titled “OrderBookData”interface OrderBookData { bids: OrderBookLevel[]; asks: OrderBookLevel[];}
interface OrderBookLevel { price: number; size: number; orders?: number;}interface Trade { id: string; price: number; size: number; time: number; side: 'buy' | 'sell';}LadderLevel
Section titled “LadderLevel”interface LadderLevel { price: number; bidSize: number; askSize: number;}Position
Section titled “Position”interface Position { entryPrice: number; quantity: number; side: 'long' | 'short';}MoverItem
Section titled “MoverItem”interface MoverItem { symbol: string; price: number; change: number; changePercent: number;}