How to use semver - 10 common examples

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.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');

// $ExpectError
semver.outside('1.2.3', '1.2', '> ');
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 flow-typed / flow-typed / definitions / npm / semver_v5.1.x / test_semver.js View on Github external
/* @flow */

import semver, {Comparator, Range, SemVer} from 'semver';

new SemVer('^3.2.0');

(semver.cmp('1.2.3', '>', '1.2.4'): boolean);

// Comparator
const comp = new Comparator('>=3.2.0');
comp.test('5.3.2');
(comp.operator: string);
(comp.value: string);

// comparator object as a ctor arg is okay
new Comparator(comp);

// static/exported properties
(semver.SEMVER_SPEC_VERSION: string);
semver.re.forEach(r => r.test('foo'));
semver.src.forEach(r => r.match(/foo/));
github PGBI / kong-dashboard / tests / cases / infinite-scrolling.spec.js View on Github external
function create150APIs() {
  if (semver.gte(process.env.KONG_VERSION, '0.15.0')) {
    return Promise.resolve(0); // legacy since 0.15.0
  }
  var promise = createAPI(0);

  for (var i = 1; i < 150; i++) {
    let n = i;
    promise = promise.then(() => {
      return createAPI(n);
    });
  }

  return promise;
}
github huncwotjs / huncwot / cli.js View on Github external
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const { valid, satisfies, validRange } = require('semver');
const {
  engines: { node: version }
} = require('./package.json');

const expected = validRange(version);
const actual = valid(process.version);

if (!satisfies(actual, expected)) {
  console.error(`Expected node ${expected}, but found ${actual}`);
  process.exit(1);
}

const _argv = require('yargs')
  .version()
  .usage('Usage: $0  [options]')
  .command(['new [dir]', 'init', 'n'], 'Create new project', require('./cli/init'))
  .example('$0 new my-project', 'Create and initialize `my-project` directory')
  .command(['setup [name]'], 'Setup an integration', require('./cli/setup'))
  .command(['start', 'start', 's'], 'Start the application', require('./cli/start'))
  .example('$0 start', 'Start the application')
  .command(['client', 'client', 'c'], 'Start only the client', require('./cli/client'))
  .example('$0 client', 'Start only the client')
  .command(['server [dir]', 'serve', 'se'], 'Serve the directory', require('./cli/server'))
  .example('$0 server --port 4000', 'Serve the directory at the port 4000')
github lightstep / lightstep-tracer-python / scripts / inc_version.js View on Github external
//
// Helper script to bump the version number
//
// TODO: a Node.js dependency in a Python package is not ideal.
//
var fs = require('fs');
var _ = require('underscore');

var version = (fs.readFileSync("VERSION", "utf8") || "1.0.0").replace(/\s+$/, "");
var newVersion = require("semver").inc(version, "patch");
fs.writeFileSync("VERSION", newVersion);
fs.writeFileSync("lightstep/version.py", "LIGHTSTEP_PYTHON_TRACER_VERSION=\"" + newVersion + "\"\n");

// Naive micro-sed on setup.py
var setuppy = _.map(fs.readFileSync("setup.py", "utf8").split("\n"), function(line) {
    return line.replace("'" + version + "'", "'" + newVersion + "'");
}).join("\n");
fs.writeFileSync("setup.py", setuppy);

console.log(version + " -> " + newVersion);
github ethereum / mist / modules / react / updater.js View on Github external
if (latestCached) {
      console.log('cache latest: ', latestCached.version);
      this.latestCached = latestCached;
      // notify that ui can be started
      this.emit('app-ready', latestCached.filePath, latestCached.version);
    } else {
      latestCached = {
        version: '0.0.0'
      };
    }
    // check remote repo for updates
    let latestBackend = await backend.getLatest();
    console.log('latest backend', latestBackend && latestBackend.version);
    if (
      latestBackend &&
      semver.gt(latestBackend.version, latestCached.version)
    ) {
      // -> update available
      this.emit('update-available', latestBackend);
      return latestBackend;
    }

    return null;
  }
  async checkIntegrity(release) {
github angular / angular-cli / packages / @angular / cli / upgrade / version.ts View on Github external
} catch (_) {
      console.error(bold(red(stripIndents`
        You seem to not be depending on "@angular/core". This is an error.
      `)));
      process.exit(2);
    }

    // Just check @angular/core.
    if (pkgJson && pkgJson['version']) {
      const v = new Version(pkgJson['version']);
      if (v.isLocal()) {
        console.warn(yellow('Using a local version of angular. Proceeding with care...'));
      } else {
        // Check if major is not 0, so that we stay compatible with local compiled versions
        // of angular.
        if (!v.isGreaterThanOrEqualTo(new SemVer('2.3.1')) && v.major != 0) {
          console.error(bold(red(stripIndents`
            This version of CLI is only compatible with angular version 2.3.1 or better. Please
            upgrade your angular version, e.g. by running:

            npm install @angular/core@latest
          ` + '\n')));
          process.exit(3);
        }
      }
    } else {
      console.error(bold(red(stripIndents`
        You seem to not be depending on "@angular/core". This is an error.
      `)));
      process.exit(2);
    }
  }
github adobe / coral-spectrum / coralui-gulp / tasks / release.js View on Github external
gulp.task('bump-version', function(cb) {
    function doVersionBump() {
      gulp.src([`${CWD}/package.json`, `${CWD}/package-lock.json`])
        .pipe(bump({version: releaseVersion}))
        .pipe(gulp.dest('./'))
        .pipe(git.commit(`releng - Release ${releaseVersion}`));
      
      cb();
    }
    
    const currentVersion = modulePackageJson.version;
    
    // Potential versions
    const patchVersion = semver.inc(currentVersion, 'patch');
    const minorVersion = semver.inc(currentVersion, 'minor');
    const majorVersion = semver.inc(currentVersion, 'major');
    const preVersion = semver.inc(currentVersion, 'prerelease', 'beta');
    const preMajorVersion = semver.inc(currentVersion, 'premajor', 'beta');
    const preMinorVersion = semver.inc(currentVersion, 'preminor', 'beta');
    const prePatchVersion = semver.inc(currentVersion, 'prepatch', 'beta');
    
    // Command line bump shortcuts
    if (gutil.env.pre) {
      releaseVersion = preVersion;
    }
    else if (gutil.env.patch) {
      releaseVersion = patchVersion;
    }
    else if (gutil.env.minor) {
      releaseVersion = minorVersion;
    }
github expo / expo-cli / packages / xdl / src / Simulator.ts View on Github external
console.error('No version number found from `xcodebuild -version`.');
      Logger.global.error(
        'Unable to check Xcode version. Command ran successfully but no version number was found.'
      );
      return false;
    }

    // we're cheating to use the semver lib, but it expects a proper patch version which xcode doesn't have
    const version = matches[0] + '.0';

    if (!semver.valid(version)) {
      console.error('Invalid version number found: ' + matches[0]);
      return false;
    }

    if (semver.lt(version, SUGGESTED_XCODE_VERSION)) {
      console.warn(
        `Found Xcode ${version}, which is older than the recommended Xcode ${SUGGESTED_XCODE_VERSION}.`
      );
    }
  } catch (e) {
    // how would this happen? presumably if Simulator id is found then xcodebuild is installed
    console.error(`Unable to check Xcode version: ${e}`);
    Logger.global.error(XCODE_NOT_INSTALLED_ERROR);
    return false;
  }

  // make sure we can run simctl
  try {
    await _xcrunAsync(['simctl', 'help']);
  } catch (e) {
    if (e.isXDLError) {