How to use the semver.Range function in semver

To help you get started, we’ve selected a few semver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / semver_v5.1.x / test_semver.js View on Github external
semver.inc('1.2.3', 'major', 'beta');
semver.inc(new SemVer('1.2.3'), 'major', 'beta');
(semver.major('1.2.3'): number);
(semver.major(new SemVer('1.2.3')): number);
(semver.minor('1.2.3'): number);
(semver.minor(new SemVer('1.2.3')): number);
(semver.patch('1.2.3'): number);
(semver.patch(new SemVer('1.2.3')): number);
semver.sort(['9.8.7', new SemVer('1.2.3')]).forEach(x => console.log(x));
semver.rsort(['9.8.7', new SemVer('1.2.3')]).forEach(x => console.log(x));
semver.compareIdentifiers('9.8.7', new SemVer('1.2.3'));
semver.rcompareIdentifiers('9.8.7', new SemVer('1.2.3'));

semver.validRange('3.x || 4.x');
semver.validRange(new Range('3.x || 4.x'));
semver.satisfies('3.5.0', new Range('3.x || 4.x'));
semver.satisfies('3.5.0', '3.x || 4.x', true);
semver.maxSatisfying(['3.5.0', new SemVer('3.15.10')], '3.x || 4.x');
semver.gtr('3.5.0', '3.x || 4.x');
semver.gtr(new SemVer('3.5.0'), new Range('3.x || 4.x'));
semver.ltr('3.5.0', '3.x || 4.x');
semver.ltr(new SemVer('3.5.0'), new Range('3.x || 4.x'));
semver.outside('2.5.0', '3.x || 4.x', '<');
semver.outside(new SemVer('2.5.0'), new Range('3.x || 4.x'), '>', true);
semver.parse('3.5.2');
semver.parse('3.5.2', true);
semver.toComparators('3.x || 4.x');
semver.toComparators(new Range('3.x || 4.x'), true);

// $ExpectError
semver.cmp('1.2.3', '> ', '1.2.4');
github electrode-io / electrode-check-dependencies / check-dependencies.js View on Github external
const unsatisfyCommon = common.filter((n) => !isWml(n)).map((name) => {

    const want = component[name];
    const expected = check[name];
    const wantRange = new Semver.Range(want);

    // version must have a finite range.  ie: can't have * or latest
    // do not allow multiple ranges. ie: can't have ^1.0.0 || ^2.0.0
    if (!wantRange || !wantRange.range || wantRange.set.length !== 1) {
      return {name, want, expected};
    }

    const expectedRange = new Semver.Range(expected);
    const wantMax = wantRange.set[0][1].toString();
    const expectedMax = expectedRange.set[0][1].toString();

    // the max version in the range must equal
    // don't care about min version since NPM will always match latest available less than max
    if (wantMax !== expectedMax) {
      return {name, want, expected};
    }

    return undefined;

  }).filter(_.identity);
github parcel-bundler / parcel / packages / core / parcel-bundler / src / transforms / babel / babelrc.js View on Github external
async function inferBabelVersion(asset, plugins) {
  // Attempt to determine version based on dependencies of plugins
  let version;

  for (let pkg of plugins) {
    if (!pkg) {
      continue;
    }

    for (let name of CORE_DEPS) {
      let dep = getDependency(pkg, name);
      if (dep) {
        // Parse version range (ignore prerelease), and ensure it overlaps with the existing version (if any)
        let range = new semver.Range(dep.replace(/-.*(\s|\|\||$)?/, ''));
        if (version && !version.intersects(range)) {
          throw new Error(
            'Conflicting babel versions found in .babelrc. Make sure all of your plugins and presets depend on the same major version of babel.',
          );
        }

        version = range;
        break;
      }
    }
  }

  // Find the maximum major version allowed in the range and use that.
  // e.g. if ^6 || ^7 were specified, use 7.
  version = getMaxMajor(version);
  if (!version) {
github flow-typed / flow-typed / cli / src / lib / npm / npmLibDefs.js View on Github external
if (semver.valid(pkgSemver)) {
    // Test the single package version against the LibDef range
    return semver.satisfies(pkgSemver, libDefSemver);
  }

  if (semver.valid(libDefSemver)) {
    // Test the single LibDef version against the package range
    return semver.satisfies(libDefSemver, pkgSemver);
  }

  if (!(semver.validRange(pkgSemver) && semver.validRange(libDefSemver))) {
    return false;
  }

  const pkgRange = new semver.Range(pkgSemver);
  const libDefRange = new semver.Range(libDefSemver);

  if (libDefRange.set[0].length !== 2) {
    throw new Error(
      'Invalid npm libdef version! It appears to be a non-continugous range.',
    );
  }

  const libDefLower = getRangeLowerBound(libDefRange);
  const libDefUpper = getRangeUpperBound(libDefRange);

  const pkgBelowLower = semver.gtr(libDefLower, pkgSemver);
  const pkgAboveUpper = semver.ltr(libDefUpper, pkgSemver);
  if (pkgBelowLower || pkgAboveUpper) {
    return false;
  }
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / packageJsonDependency / index.ts View on Github external
context => {
            if (typeof context.packageName !== 'string') {
                throw new Error('invalid packageName')
            }
            if (typeof context.matchVersion !== 'string') {
                throw new Error('invalid matchVersion')
            }
            return {
                name: context.packageName,
                versionRange: context.matchVersion,
                parsedVersionRange: new semver.Range(context.matchVersion),
            }
        }
    )
github smclab / titaniumifier / lib / manifest.js View on Github external
function getMinSDK(titaniumsdk) {
  var range;

  try {
    range = semver.Range(titaniumsdk);
  }
  catch (e) {
    throw new Error(
      "Invalid SDK version '" + titaniumsdk + "'. Did you include '.GA' or" +
      " similar?");
  }

  var gteVersions = [];
  var minsdk;

  range.set.forEach(function (set) {
    set.forEach(function (comp) {
      if (comp.operator === '>=') {
        gteVersions.push(comp.semver.format());
      }
      else if (comp.operator === '>') {
github remoteinterview / zero / packages / parcel-bundler / mods / babelrc.js View on Github external
function getMaxMajor(version) {
  try {
    let range = new semver.Range(version);
    let sorted = range.set.sort((a, b) => a[0].semver.compare(b[0].semver));
    return semver.major(sorted.pop()[0].semver.version);
  } catch (err) {
    return null;
  }
}
github electron / electron-packager / src / infer.js View on Github external
function rangeFromElectronVersion (electronVersion) {
  try {
    return new semver.Range(electronVersion)
  } catch (error) {
    return null
  }
}
github parcel-bundler / parcel / packages / transformers / babel / src / utils.js View on Github external
export function getMinSemver(version: string) {
  try {
    let range = new semver.Range(version);
    let sorted = range.set.sort((a, b) => a[0].semver.compare(b[0].semver));
    return sorted[0][0].semver.version;
  } catch (err) {
    return null;
  }
}