Skip to content

Utilities

API reference for utility functions and hooks.

exportToCSV

Export data to CSV format.

Signature

tsx
function exportToCSV<T>(
  data: T[],
  columns: ColumnDef<T>[],
  options?: CSVExportOptions
): string | void

Parameters

ParameterTypeDescription
dataT[]Array of data objects to export
columnsColumnDef<T>[]Column definitions (determines fields and headers)
optionsCSVExportOptionsExport options

Options

tsx
interface CSVExportOptions {
  filename?: string;       // Default: 'export.csv'
  delimiter?: string;      // Default: ','
  includeHeaders?: boolean; // Default: true
  download?: boolean;      // Default: true
}

Returns

  • When download: true (default): Returns void, triggers browser download
  • When download: false: Returns CSV string

Examples

tsx
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 });

formatPrice

Format a number as a price string.

Signature

tsx
function formatPrice(value: number, decimals?: number): string

Parameters

ParameterTypeDefaultDescription
valuenumberrequiredThe price value
decimalsnumber2Decimal places

Examples

tsx
import { formatPrice } from '@askturret/grid';

formatPrice(1234.5);      // '1,234.50'
formatPrice(1234.5678, 4); // '1,234.5678'
formatPrice(-50.5);       // '-50.50'

formatQuantity

Format a number as a quantity string with thousands separators.

Signature

tsx
function formatQuantity(value: number, decimals?: number): string

Parameters

ParameterTypeDefaultDescription
valuenumberrequiredThe quantity value
decimalsnumber0Decimal places

Examples

tsx
import { formatQuantity } from '@askturret/grid';

formatQuantity(1000);     // '1,000'
formatQuantity(1234567);  // '1,234,567'
formatQuantity(100.5, 2); // '100.50'

formatPnL

Format a number as P&L with sign prefix.

Signature

tsx
function formatPnL(value: number, decimals?: number): string

Parameters

ParameterTypeDefaultDescription
valuenumberrequiredThe P&L value
decimalsnumber2Decimal places

Examples

tsx
import { formatPnL } from '@askturret/grid';

formatPnL(100.5);   // '+100.50'
formatPnL(-50.25);  // '-50.25'
formatPnL(0);       // '0.00'

useAdaptiveFlash

Hook for FPS-aware flash highlighting control.

Signature

tsx
function useAdaptiveFlash(): {
  enabled: boolean;
  fps: number;
}

Returns

PropertyTypeDescription
enabledbooleanWhether flash effects should be shown
fpsnumberCurrent frames per second

Behavior

  • Disables flash when FPS drops below 55
  • Re-enables flash when FPS recovers above 58
  • Updates every second

Example

tsx
import { useAdaptiveFlash } from '@askturret/grid';

function PerformanceMonitor() {
  const { enabled, fps } = useAdaptiveFlash();

  return (
    <div>
      FPS: {fps} | Flash: {enabled ? 'ON' : 'OFF'}
    </div>
  );
}

initWasm

Initialize the WASM core module.

Signature

tsx
function initWasm(): Promise<void>

Description

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

Example

tsx
import { initWasm } from '@askturret/grid';

// In app initialization
async function init() {
  await initWasm();
  // WASM is now ready
}

Notes

  • 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

All types are exported from the main package:

tsx
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

tsx
interface SortState {
  field: string;
  direction: 'asc' | 'desc';
}

OrderBookData

tsx
interface OrderBookData {
  bids: OrderBookLevel[];
  asks: OrderBookLevel[];
}

interface OrderBookLevel {
  price: number;
  size: number;
  orders?: number;
}

Trade

tsx
interface Trade {
  id: string;
  price: number;
  size: number;
  time: number;
  side: 'buy' | 'sell';
}

LadderLevel

tsx
interface LadderLevel {
  price: number;
  bidSize: number;
  askSize: number;
}

Position

tsx
interface Position {
  entryPrice: number;
  quantity: number;
  side: 'long' | 'short';
}

MoverItem

tsx
interface MoverItem {
  symbol: string;
  price: number;
  change: number;
  changePercent: number;
}

Released under the MIT License.