generators/lib/drupalProjectVersion.js
function toMinorRange(version) {
    var regex = /^\d+\.\d+/;
    var range = version.match(regex);
    if (range) {
      return '^' + range[0];
    }
    else {
      var regex = /^\d+\.x/;
      var range = version.match(regex);
      if (range) {
        return range[0];
      }
    }

    return version;
  }
function toMinorRange(version) {
    var regex = /^\d+\.\d+/;
    var range = version.match(regex);
    if (range) {
      return '^' + range[0];
    }
    else {
      var regex = /^\d+\.x/;
      var range = version.match(regex);
      if (range) {
        return range[0];
      }
    }

    return version;
  }
function toMinorRange ( version ) { var regex = / ^\d+\.\d+ / ; var range = version . match ( regex ) ; if ( range ) { return '^' + range [ 0 ] ; } else { var regex = / ^\d+\.x / ; var range = version . match ( regex ) ; if ( range ) { return range [ 0 ] ; } } return version ; }
Convert a semantic version to a minor range.

In composer.json entries for Drupal core or other major projects, we often
want to designate the version similar to '^8.2'. This code converts version
strings that may have a pre-release suffix to such a range.

Furthermore, there are some edge cases wherein we may want to take a version
that is already a minor range, such as 8.x, and use it as is.
Convert a semantic version to a minor range .