shortenUUID static method

String shortenUUID(
  1. String longId,
  2. Translator translator, [
  3. PaddingParams? paddingParams
])

Takes a UUID, strips the dashes, and translates.

Strips longId of dashes and passes it to the translator function to be converted into shortened form and returns the result.

Adds padding in front of the resulting short form if paddingParams has consistentLength set to true.

Implementation

static String shortenUUID(String longId, Translator translator,
    [PaddingParams? paddingParams]) {
  final translated = translator(longId.toLowerCase().replaceAll('-', ''));

  if (paddingParams == null || !paddingParams.consistentLength)
    return translated;

  return translated.padLeft(
    paddingParams.shortIdLength,
    paddingParams.paddingChar,
  );
}