parseSortParam
function parseSortParam(input): object;Defined in: filters/sort.ts:29
Sort helpers (pure, no validation library). The Sort model lives in
./types.ts; the valibot schema is in @xtandard/lib/filters/valibot. Field
names are public — the per-adapter column allow-list maps them to columns, so
a client can never sort by a column that isn’t declared sortable.
Parse a compact sort query param: "createdAt:desc,name:asc". Empty/absent
input → []. The direction is asc or desc in any case (ASC works) and
defaults to desc when missing ("name" or "name:"). A malformed entry is
dropped: an unknown direction (up, a typo), a blank field, or extra :
parts. Unknown field names are kept here and dropped later by the adapter’s
column allow-list.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
{ value: string | null | undefined; } |
input.value |
string | null | undefined |
Returns
Section titled “Returns”object
| Name | Type | Defined in |
|---|---|---|
sort |
Sort |
filters/sort.ts:29 |
Example
Section titled “Example”import { parseSortParam } from "@xtandard/lib/filters";
parseSortParam({ value: "createdAt:desc,name:asc" });// → { sort: [{ field: "createdAt", dir: "desc" }, { field: "name", dir: "asc" }] }
parseSortParam({ value: "name,price:ASC,:asc,id:up" });// → { sort: [{ field: "name", dir: "desc" }, { field: "price", dir: "asc" }] }
parseSortParam({ value: null }); // → { sort: [] }