function latestMaybeSemVer(versions, pre) {
  let version = ''

  if (!pre) {
    // remove pre-releases from array
    versions = versions.filter(version => !/\d+-\w+/.test(version))
  }
  try {
    // coerce to string then lowercase otherwise alpha > RC
    version = versions.sort((a, b) =>
      semver.compareBuild(
        `${a}`.toLowerCase(),
        `${b}`.toLowerCase(),
        /* loose */ true,
      ),
    )[versions.length - 1]
  } catch (e) {
    version = latestDottedVersion(versions)
  }
  return version
}
Finds the largest version number lexicographically or semantically from an array of strings representing version numbers and returns it as a string.
latestMaybeSemVer() is used for versions that match some kind of dotted version pattern.

@param {string[]} versions - The array of version numbers to compare
@param {boolean} pre - Whether to include pre-release versions or not
@returns {string|undefined} The largest version number as a string, or undefined if the array is empty
@example
latestMaybeSemVer(['1.2.3', '1.2.4', '1.3', '2.0'], false) // returns '2.0' because it is the largest version number and pre-release versions are excluded.
latestMaybeSemVer(['1.2.3', '1.2.4', '1.3', '2.0'], true) // returns '2.0' because pre-release versions are included but none of them are present in the array.
latestMaybeSemVer(['1.2.3', '1.2.4', '1.3-alpha', '2.0-beta'], false) // returns '1.2.4' because pre-release versions are excluded and it is the largest version number among the remaining ones.
latestMaybeSemVer(['1.2.3', '1.2.4', '1.3-alpha', '2.0-beta'], true) // returns '2.0-beta' because pre-release versions are included and it is the largest version number.