compareNatural(): compare text the way people expect
compareNatural(x, y) compares strings using natural ordering. Rather than comparing every character literally, it recognizes number runs, so “chapter 2” sorts before “chapter 10”.
Where it helps
Natural comparison is ideal for filenames, version-like labels, invoice identifiers, and numbered headings. A plain lexical order would place 10 before 2 because “1” precedes “2”; natural order treats the embedded digits as numbers.
Related comparisons
Use compareText() when text collation is the primary concern, and compare() for general values. Feed a comparator into sorting workflows with sort(). For exact identity rather than ordering, use equalText or equal.
Practical cautions
Natural ordering is a presentation rule, not a numeric parser. Leading zeros, punctuation, case, and locale can still matter. Normalize labels first when a reproducible cross-system order is required.