createSortByStringFn
Creates a sort function for objects by one or more string properties. When multiple properties are given the array is sorted by the first key; ties are broken by the second key, then the third, and so on.
Property values are coerced to strings via String() before comparison:
numbers sort as '0', '1', '42', etc. (lexicographic, not numeric);
use createSortByNumberFn for numeric properties.
Available since v1.9.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
property | keyof T | readonly keyof T[] | The property (or ordered list of properties) to sort by. Defaults to trying ‘value’, ‘label’, ‘title’, ‘description’ in that order. Pass `undefined` explicitly to use auto-detect; an empty array `[]` produces a stable no-op comparator (does **not** fall back to auto-detect). (optional) |
caseInsensitive | boolean | Whether to ignore case (default: false). Uses `Intl.Collator { sensitivity: ‘accent’ }`, which folds case but still distinguishes accented characters (é ≠ e). This differs from `createSortByNaturalFn(key, true)`, which also collapses diacritics. |
Returns
Section titled “Returns”SortFn<T> — Sort function
Examples
Section titled “Examples”Sort objects by string property
Section titled “Sort objects by string property”Use createSortByStringFn to sort objects by a specific string property.
Sort objects by multiple keys
Section titled “Sort objects by multiple keys”Pass an array of keys; ties on the first key are broken by the next.
Related Types
Section titled “Related Types”SortFn
Section titled “SortFn”Sort function type for arrays
