Skip to main content

Module sort

Module sort 

Source
Expand description

Table sorting, ported from upstream’s table.ts.

Numbers compare numerically when both values parse, after removing grouping separators, so “9, 10, 100” and “12,480” sort as numbers. Other text compares naturally (digit runs by value) and without regard to case. Upstream uses the browser’s Intl.Collator in the table’s language for text; this port has no locale tailoring, so give accented or locale-sensitive columns an explicit sort key.

Enums§

SortDirection
Which way a column is sorted.

Functions§

as_number
A value as a number, ignoring spaces and commas used for grouping.
compare
Compare two sort keys as table.ts does: numerically when both are numbers.
next_direction
The direction a header press picks: a column sorted ascending flips to descending, anything else starts ascending.
order
Indices of keys in sorted order. Stable: equal keys keep their order, so sorting by one column after another groups within the earlier order.