@theredhead — Frontend Library - v1.0.0
    Preparing search index...
    • Compiles a SortState into a comparator function for use with ISortableDatasource.sortBy().

      The comparator performs locale-aware string comparison by default, treating all values as strings. Numeric and date comparisons are not supported — if you need custom comparison logic, pass a custom comparator directly to the datasource.

      Type Parameters

      • T extends Record<string, unknown>

      Parameters

      • state: SortState | null | undefined

        The sort state (key and direction), or null/undefined for no sorting.

      Returns ((a: T, b: T) => number) | null

      A comparator function (a, b) => number, or null if state is null/undefined.

      import { toComparator } from '@theredhead/lucid-kit';
      import { SortableArrayDatasource } from '@theredhead/lucid-foundation';

      const ds = new SortableArrayDatasource(items);
      const state = { key: 'name', direction: 'asc' };
      ds.applyComparator(toComparator(state));