// Ported from filius-ipad (GPLv2/GPLv3), ios/FiliusPad/TopologyEditor. // Swift orders identifiers by `UUID.uuidString`, which is upper case. Every // deterministic ordering in the runtime depends on it, so identifiers are // compared the same way here whatever case they were written in. /** A node, port, link or socket identifier: a UUID string. */ export type Id = string; /** `lhs.uuidString < rhs.uuidString` in Swift. */ export function idLess(lhs: Id, rhs: Id): boolean { return lhs.toUpperCase() < rhs.toUpperCase(); } /** Comparator for `Array.prototype.sort` with the Swift ordering. */ export function compareIds(lhs: Id, rhs: Id): number { const left = lhs.toUpperCase(); const right = rhs.toUpperCase(); return left < right ? -1 : left > right ? 1 : 0; }