app/lib/search/sort.mjs
24 lines and 3 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| parseSort | 11 to 13 | 2 | 100% | OkCRAP 2 | No data: no mutants in this code |
| applySort | 24 to 27 | 2 | 100% | OkCRAP 2 | No data: no mutants in this code |
| <anonymous:26> | 26 to 26 | 3 | 100% | OkCRAP 3 | No data: no mutants in this code |
Imports
It imports no other module of this repo. Imported by app/lib/search/search.server.ts.
Source
// Relevance stays the default: the best pages here are old papers, which a date-first list buries.
/**
* @typedef {"relevance" | "date"} SearchSort
*/
/**
* @param {string | null | undefined} value
* @returns {SearchSort}
*/
export function parseSort(value) {
return value === "date" ? "date" : "relevance";
}
/**
* Undated rows sort last via -Infinity, not 0, which would misplace a pre-epoch date. The caller
* paginates after sorting, since sorting one page of ten reads as a broken list.
*
* @template {{ publishAt: number | null }} T
* @param {T[]} hits
* @param {SearchSort} sort
* @returns {T[]}
*/
export function applySort(hits, sort) {
if (sort !== "date") return hits;
return [...hits].sort((a, b) => (b.publishAt ?? -Infinity) - (a.publishAt ?? -Infinity));
}