{sort:values:type:unique:delimiter:limit:add}

Description

Sorts a delimited list of values and returns it as a string joined by the same delimiter. Supports six sort orders (numeric ascending is the default), optional de-duplication, optional truncation to the first N values, and an optional value to append when truncating. Sorting is value-based, so to sort items by a field, build the value list with another command first.

Parameters

values required default (empty string)

The delimiter-separated list of values to sort. With no delimiter set, parts are split on a hyphen. Empty or whitespace-only parts are kept as values.

type optional default (empty string)

Sort order. Empty or any unrecognized value sorts numerically ascending (the default). The recognized orders are: string (text, ascending, so 12 before 3), rnumeric (numeric, descending), rstring (text, descending), locale (text by the server locale, ascending), rlocale (locale, descending).

unique optional default (empty string)

Set to the literal 1 to remove duplicate values after sorting, keeping the first occurrence of each. Any other value leaves duplicates in place.

delimiter optional default - (a single hyphen)

Separator used both to split the input list and to join the sorted result. One delimiter governs input and output together.

limit optional default (empty string)

Keep only the first N values after sorting. Applied only when it is a non-negative whole number and the list holds more than N values; otherwise the whole list is returned.

add optional default (empty string)

When limit truncates the list, this extra value is appended as the final element, for example an ellipsis or a more link. Ignored when limit does not truncate.

Examples

test{sort:5-3-12-1}
Expected1-3-5-12
Actual1-3-5-12
With no order type given, sort compares values as numbers, ascending. This is the default.
test{sort:10-2-33-4:number}
Expected2-4-10-33
Actual2-4-10-33
Numeric sort orders the dash-separated values as numbers, so 33 comes after 10 (string sort would put 10 before 2).
test{sort:5-3-12-1:string}
Expected1-12-3-5
Actual1-12-3-5
With type string, values compare character by character, so 12 lands before 3. Use this when the parts are not numbers, or read it as the trap to avoid for numbers.
test{sort:5-3-12-1:rnumeric}
Expected12-5-3-1
Actual12-5-3-1
Type rnumeric sorts numerically, descending.
test{sort:cherry-apple-banana:string}
Expectedapple-banana-cherry
Actualapple-banana-cherry
Type string puts words in alphabetical order.
test{sort:apple-banana-cherry:rstring}
Expectedcherry-banana-apple
Actualcherry-banana-apple
Type rstring sorts text descending, Z to A.
test{sort:3-1-2-1-3::1}
Expected1-2-3
Actual1-2-3
The third parameter set to 1 removes duplicates after sorting. Here type is left empty (numeric).
test{sort:30,5,200:::,}
Expected5,30,200
Actual5,30,200
The fourth parameter changes the separator for both the input and the output. Here a comma replaces the default hyphen.
test{sort:5-3-12-1-9-7:::-:3}
Expected1-3-5
Actual1-3-5
The fifth parameter keeps only the first N values after sorting. Sorted ascending the list is 1-3-5-7-9-12; the first three are kept.
test{sort:5-3-12-1-9-7:::-:3:...}
Expected1-3-5-...
Actual1-3-5-...
The sixth parameter is appended after truncation, here three dots as a more marker. It is added only when limit actually trims the list.