SortByField
cartographer / sortByField
Function: sortByField()
Section titled “Function: sortByField()”sortByField(
items,fieldKey,descending,fieldType):CatalogItem[]
Defined in: queries/queryFunctions.ts:493
Sort items by a field with type-aware comparison.
Handles null values gracefully (sorts to end). Supports string, number, and date field types.
Parameters
Section titled “Parameters”Array of items to sort
fieldKey
Section titled “fieldKey”string
Field key to sort by
descending
Section titled “descending”boolean = false
Sort order (default: false for ascending)
fieldType
Section titled “fieldType”string = 'string'
Type for comparison: ‘string’, ‘number’, or ‘date’ (default: ‘string’)
Returns
Section titled “Returns”- New sorted array (original array not mutated)
Example
Section titled “Example”const byYear = sortByField(items, 'year', true, 'number'); // Descending by year