shortId function

String shortId(
  1. String id, [
  2. int length = 8
])

Derives a short, human-friendly handle from a full id.

Strips any hyphens (so a canonical UUID collapses to hex) and takes the first length characters. Short ids are display-only and resolved by unambiguous prefix against the owner's session set, so collisions are detected and rejected rather than silently mishandled.

Implementation

String shortId(String id, [int length = 8]) {
  final compact = id.replaceAll('-', '');
  return compact.length <= length ? compact : compact.substring(0, length);
}