alexbruf/elm-table/1.0.0

Table.SortFn

Built-in sort functions, ported from row-sorting/sortFns.ts.

A SortFn compares two cell values in ascending order. Descending order is applied by the sorted row model. Each sort fn carries an optional resolveDataValue normaliser that runs on both values before comparison, which is how the built-ins lowercase text or turn dates into timestamps.

Type

type SortFn

An ascending comparison on cell values plus its value normaliser.

Built-ins

Natural sort, case-insensitive: item2 before item10.

Natural sort, case-sensitive.

Plain lexicographic sort, case-insensitive.

Plain lexicographic sort, case-sensitive.

Chronological sort on Date values (and numeric timestamps).

Date values become millisecond timestamps first; anything else is compared with JavaScript's relational rules, so two strings compare as strings and everything else compares numerically.

Direct comparison with no normalisation.

Building your own

custom : (Value -> Value -> Order) -> SortFn

Build a sort fn from a comparison. Use withResolveDataValue to add a normaliser.

Replace the normaliser that runs on both values before comparison.

Applying

compare : SortFn -> Value -> Value -> Order

Compare two raw cell values: both are passed through the normaliser, then the comparison runs.

Run only the normaliser.

Chunking

splitAlphaNumeric : String -> List String

The Elm counterpart of splitting a string with TanStack's reSplitAlphaNumeric regex (/([0-9]+)/gm): runs of digits become their own segments, and the empty segments JavaScript leaves at the boundaries are kept.

splitAlphaNumeric "apple" == [ "apple" ]


splitAlphaNumeric "item10" == [ "item", "10", "" ]


splitAlphaNumeric "10abc" == [ "", "10", "abc" ]


splitAlphaNumeric "" == [ "" ]