Skip to content

Utilities

API reference for utility functions and hooks.

Export data to CSV format.

function exportToCSV<T>(
data: T[],
columns: ColumnDef<T>[],
options?: CSVExportOptions
): string | void
ParameterTypeDescription
dataT[]Array of data objects to export
columnsColumnDef<T>[]Column definitions (determines fields and headers)
optionsCSVExportOptionsExport options
interface CSVExportOptions {
filename?: string; // Default: 'export.csv'
delimiter?: string; // Default: ','
includeHeaders?: boolean; // Default: true
download?: boolean; // Default: true
}
  • When download: true (default): Returns void, triggers browser download
  • When download: false: Returns CSV string
import { exportToCSV } from '@askturret/grid';
// Download CSV
exportToCSV(data, columns, { filename: 'users.csv' });
// Get CSV string
const csv = exportToCSV(data, columns, { download: false });
// Custom delimiter
exportToCSV(data, columns, { delimiter: ';' });
// Without headers
exportToCSV(data, columns, { includeHeaders: false });

Format a number as a price string.

function formatPrice(value: number, decimals?: number): string
ParameterTypeDefaultDescription
valuenumberrequiredThe price value
decimalsnumber2Decimal places
import { formatPrice } from '@askturret/grid';
formatPrice(1234.5); // '1,234.50'
formatPrice(1234.5678, 4); // '1,234.5678'
formatPrice(-50.5); // '-50.50'

Format a number as a quantity string with thousands separators.

function formatQuantity(value: number, decimals?: number): string
ParameterTypeDefaultDescription
valuenumberrequiredThe quantity value
decimalsnumber0Decimal places
import { formatQuantity } from '@askturret/grid';
formatQuantity(1000); // '1,000'
formatQuantity(1234567); // '1,234,567'
formatQuantity(100.5, 2); // '100.50'

Format a number as P&L with sign prefix.

function formatPnL(value: number, decimals?: number): string
ParameterTypeDefaultDescription
valuenumberrequiredThe P&L value
decimalsnumber2Decimal places
import { formatPnL } from '@askturret/grid';
formatPnL(100.5); // '+100.50'
formatPnL(-50.25); // '-50.25'
formatPnL(0); // '0.00'

Hook for FPS-aware flash highlighting control.

function useAdaptiveFlash(): {
enabled: boolean;
fps: number;
}
PropertyTypeDescription
enabledbooleanWhether flash effects should be shown
fpsnumberCurrent frames per second
  • Disables flash when FPS drops below 55
  • Re-enables flash when FPS recovers above 58
  • Updates every second
import { useAdaptiveFlash } from '@askturret/grid';
function PerformanceMonitor() {
const { enabled, fps } = useAdaptiveFlash();
return (
<div>
FPS: {fps} | Flash: {enabled ? 'ON' : 'OFF'}
</div>
);
}

Initialize the WASM core module.

function initWasm(): Promise<void>

Initializes the optional WASM core for accelerated sorting and filtering. Call this at app startup for immediate availability.

import { initWasm } from '@askturret/grid';
// In app initialization
async 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

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';
interface SortState {
field: string;
direction: 'asc' | 'desc';
}
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';
}
interface LadderLevel {
price: number;
bidSize: number;
askSize: number;
}
interface Position {
entryPrice: number;
quantity: number;
side: 'long' | 'short';
}
interface MoverItem {
symbol: string;
price: number;
change: number;
changePercent: number;
}