function stringToVersion(verStr: string): Version {
  const versionParts = verStr.match(VERSION_RE);
  if (versionParts == null) {
    throw new Error(
      `${verStr} is a malformed version string. Expected a version formatted ` +
        'as `' +
        VERSION_RE.toString() +
        '`',
    );
  }
  const [
    _1,
    range,
    majorStr,
    minorStr,
    patchStr,
    prerel,
    _2,
    upperRange,
    upperMajor,
    upperMinor,
    upperPatch,
    upperPrerel,
  ] = versionParts;
  if (range != null && range !== '>=' && range !== '<=') {
    throw new Error(`'${verStr}': Invalid version range: ${range}`);
  }
  if (upperRange != null && upperRange !== '>=' && upperRange !== '<=') {
    throw new Error(
      `'${verStr}': Invalid version upper-bound range: ${upperRange}`,
    );
  }

  const major = _validateVersionNumberPart(verStr, 'major', majorStr);
  const minor =
    minorStr !== 'x'
      ? _validateVersionNumberPart(verStr, 'minor', minorStr)
      : minorStr;
  const patch =
    patchStr !== 'x'
      ? _validateVersionNumberPart(verStr, 'patch', patchStr)
      : patchStr;

  const upperBound = upperMajor
    ? {
        range: upperRange,
        major: _validateVersionNumberPart(
          verStr,
          'upper-bound major',
          upperMajor,
        ),
        minor:
          upperMinor !== 'x'
            ? _validateVersionNumberPart(
                verStr,
                'upper-bound minor',
                upperMinor,
              )
            : upperMinor,
        patch:
          upperPatch !== 'x'
            ? _validateVersionNumberPart(
                verStr,
                'upper-bound patch',
                upperPatch,
              )
            : upperPatch,
        prerel: upperPrerel.substr(1),
      }
    : undefined;

  if (range === '<=' && ((major === minor) === patch) === 0) {
    throw new Error(
      `It doesn't make sense to have a version range of '<=v0.0.0'!`,
    );
  }

  return {
    range,
    major,
    minor,
    patch,
    prerel: prerel != null ? prerel.substr(1) : prerel,
    upperBound,
  };
}
Find the highest compatible explicit version based on a version range
of a flow-typed definition
ie: a type definition is 1.2.x, and the upper bound of that would be 1.3.0