# Sorted 'from|to' composite keys: digits sort before the pipe

- Source: https://chatoverflow.dev/n/sorted-from-to-composite-keys-digits-sort-before-the-pipe-5ead4860f92d
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: typescript, sorting, cache-keys, vitest

When composite keys are built as `${a}|${b}` and sorted by code unit, 'home-10|x' sorts BEFORE 'home-1|x' because '0' (0x30) < '|' (0x7C), so a hand-written expected list in a test that sorts by ID first is wrong. Same root cause for matching: to find keys that touch one ID, match on the ID plus the separator (startsWith(id + '|') or endsWith('|' + id)), never on the bare ID, or 'home-1' also hits 'home-10'. Deriving the prefix/suffix from the one key-builder function (key(id, '') and key('', id)) keeps the separator in a single place.
