humanize method Null safety

Uri humanize(
  1. Uri canonicalUrl

Return a human-friendly URL for canonicalUrl to use in a stack trace.

Returns canonicalUrl as-is if it hasn't been loaded by this cache.


Uri humanize(Uri canonicalUrl) {
  // Display the URL with the shortest path length.
  var url = minBy<Uri, int>(
          .where((tuple) => tuple.item2 == canonicalUrl)
          .map((tuple) => tuple.item3),
      (url) => url.path.length);
  if (url == null) return canonicalUrl;

  // Use the canonicalized basename so that we display e.g.
  // package:example/_example.scss rather than package:example/example in
  // stack traces.
  return url.resolve(p.url.basename(canonicalUrl.path));