How to use the semver.coerce 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 DonJayamanne / pythonVSCode / src / client / common / utils / version.ts View on Github external
export function parseVersion(raw: string): semver.SemVer {
    raw = raw.replace(/\.00*(?=[1-9]|0\.)/, '.');
    const ver = semver.coerce(raw);
    if (ver === null || !semver.valid(ver)) {
        // tslint:disable-next-line: no-suspicious-comment
        // TODO: Raise an exception instead?
        return new semver.SemVer('0.0.0');
    }
    return ver;
}
export function parsePythonVersion(version: string): Version | undefined {
github microsoft / mixed-reality-extension-sdk / packages / sdk / src / utils / verifyClient.ts View on Github external
/*!
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */

import semver from 'semver';
import * as Constants from '../constants';
import { log } from '../log';

/*
 * Current SDK Version - Read from package.json.
 */
// tslint:disable-next-line:no-var-requires variable-name
const CurrentSDKVersion = semver.coerce(require('../../package.json').version);

/*
 * Minimum Supported Client Library version
 * As part of the manual SDK release procedures, this is reset to match CurrentSDKVersion Major.Minor if new functions
 * have been added that don't work on older clients (i.e. pretty much every release). Since host apps are required to
 * update client libraries regularly, this one is not a big deal to update.
 */
// tslint:disable-next-line:variable-name
const MinimumSupportedClientVersion = semver.coerce('0.14');

/**
 * @hidden
 * 'ws' middleware to validate the client protocol version when processing a connection upgrade request.
 * @param info 'ws' request information
 * @param cb 'ws' verification callback
 */
github naviapps / create-nw-react-app / packages / create-nw-react-app / createNwReactApp.js View on Github external
.then(({ isOnline, packageInfo, templateInfo }) => {
        let packageVersion = semver.coerce(packageInfo.version);

        // This environment variable can be removed post-release.
        const templatesVersionMinimum = process.env.CNRA_INTERNAL_TEST
          ? '3.2.0'
          : '3.3.0';

        // Assume compatibility if we can't test the version.
        if (!semver.valid(packageVersion)) {
          packageVersion = templatesVersionMinimum;
        }

        // Only support templates when used alongside new react-scripts versions.
        const supportsTemplates = semver.gte(
          packageVersion,
          templatesVersionMinimum
        );
github IBM-Blockchain / blockchain-vscode-extension / packages / blockchain-extension / extension / dependencies / DependencyManager.ts View on Github external
public async getDockerVersion(): Promise {
        try {
            const dockerResult: string = await CommandUtil.sendCommand('docker -v'); // Format: Docker version X.Y.Z-ce, build e68fc7a
            if (this.isCommandFound(dockerResult)) {
                const dockerMatchedVersion: string = dockerResult.match(/version (.*),/)[1]; // Format: X.Y.Z-ce "version 18.06.1-ce,"
                const dockerCleaned: string = semver.clean(dockerMatchedVersion, { loose: true });
                const dockerVersionCoerced: semver.SemVer = semver.coerce(dockerCleaned); // Format: X.Y.Z
                const dockerVersion: string = semver.valid(dockerVersionCoerced); // Returns version
                return dockerVersion;
            }
        } catch (error) {
            // Ignore
            return;
        }
    }
github openshift / console / frontend / public / components / image-stream.tsx View on Github external
return getBuilderTags(imageStream).sort(({ name: a }, { name: b }) => {
    const v1 = semver.coerce(a);
    const v2 = semver.coerce(b);
    if (!v1 && !v2) {
      return a.localeCompare(b);
    }
    if (!v1) {
      return 1;
    }
    if (!v2) {
      return -1;
    }
    return semver.rcompare(v1, v2);
  });
};
github rvpanoz / luna / app / components / pages / notifications / Notifications.js View on Github external
const allSelected = notifications.map((n, idx) => {
        const name = parseRequired(n.required, 0);
        const version = parseRequired(n.required, 1);
        const { raw } = semver.coerce(version) || 'latest';

        return {
          idx,
          name,
          version: raw
        };
      });
github release-it / release-it / lib / plugin / version / Version.js View on Github external
if (isValidVersion && semver.gte(increment, latestVersion)) {
      return increment;
    }

    const _isPreRelease = isPreRelease || (increment || '').startsWith('pre');
    if (_isPreRelease && latestIsPreRelease) {
      return semver.inc(latestVersion, 'prerelease', preReleaseId);
    }

    const normalizedType = releaseTypes.includes(increment) && _isPreRelease ? `pre${increment}` : increment;
    if (allReleaseTypes.includes(normalizedType)) {
      return semver.inc(latestVersion, normalizedType, preReleaseId);
    }

    const coercedVersion = !isValidVersion && semver.coerce(increment);
    if (coercedVersion) {
      this.log.warn(`Coerced invalid semver version "${increment}" into "${coercedVersion}".`);
      return coercedVersion.toString();
    }
  }
}
github cardstack / cardstack / packages / ethereum / cardstack / transaction-indexer.js View on Github external
async _indexAddressResource(batch, address, blockHeight, transactions = [], addressVersion='0.0') {
    if (!address) { return; }
    log.trace(`indexing address ${address} at block #${blockHeight} with version ${addressVersion} and transactions${JSON.stringify(transactions)}`);

    let addressResource;
    try {
      addressResource = await this.searchers.get(Session.INTERNAL_PRIVILEGED, 'local-hub', 'ethereum-addresses', address.toLowerCase());
    } catch (err) {
      if (err.status !== 404) { throw err; }
    }
    if (addressResource) {
      addressResource = addressResource.data;
      let { meta: { version } } = addressResource;
      if (version && lt(coerce(addressVersion), coerce(version))) {
        throw new Error(`Cannot index ethereum-addresses/${address} the address version '${addressVersion}' is less than currently indexed address document version '${version}'. Address versions is dervied from '.'.`);
      }
    } else {
      addressResource = {
        id: address.toLowerCase(),
        type: 'ethereum-addresses',
        attributes: {
          'ethereum-address': toChecksumAddress(address),
        },
        relationships: {
          transactions: { data: [] }
        },
      };
    }

    let updatedTransactions = addressResource.relationships.transactions.data.concat((transactions || []).map(({ type, id }) => {
github umijs / umi / packages / umi-plugin-auto-externals / src / util / getExternalData.ts View on Github external
keys.forEach(key => {
    if (res[key]) {
      return;
    }
    const semverIns = semver.coerce(pkg.dependencies && pkg.dependencies[key]);
    if (!semverIns) {
      error(`Can not find dependencies(${key}) version`);
    }
    res[key] = semverIns.version;
  });
  return res;
github dcos / dcos-ui / plugins / ui-update / notifications.ts View on Github external
filter(uiMetadata => {
          const { clientBuild, serverBuild } = uiMetadata;
          const coercedClientBuild = semver.coerce(clientBuild || "");
          const coercedServerBuild = semver.coerce(serverBuild || "");
          return (
            coercedClientBuild !== null &&
            coercedServerBuild !== null &&
            coercedClientBuild.raw !== coercedServerBuild.raw &&
            coercedClientBuild.raw !== LOCAL_DEV_VERSION
          );
        }),
        map(uiMetadata => {