當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript semver.validRange函數代碼示例

本文整理匯總了TypeScript中semver.validRange函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript validRange函數的具體用法?TypeScript validRange怎麽用?TypeScript validRange使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了validRange函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: angularMajorCompatGuarantee

export function angularMajorCompatGuarantee(range: string) {
  let newRange = semver.validRange(range);
  if (!newRange) {
    return range;
  }
  let major = 1;
  while (!semver.gtr(major + '.0.0', newRange)) {
    major++;
    if (major >= 99) {
      // Use original range if it supports a major this high
      // Range is most likely unbounded (e.g., >=5.0.0)
      return newRange;
    }
  }

  // Add the major version as compatible with the angular compatible, with all minors. This is
  // already one major above the greatest supported, because we increment `major` before checking.
  // We add minors like this because a minor beta is still compatible with a minor non-beta.
  newRange = range;
  for (let minor = 0; minor < 20; minor++) {
    newRange += ` || ^${major}.${minor}.0-alpha.0 `;
  }

  return semver.validRange(newRange) || range;
}
開發者ID:angular,項目名稱:angular-cli,代碼行數:25,代碼來源:index.ts

示例2: while

  '@angular/core': (range: string) => {
    range = semver.validRange(range);
    let major = 1;
    while (!semver.gtr(major + '.0.0', range)) {
      major++;
      if (major >= 99) {
        throw new SchematicsException(`Invalid range: ${JSON.stringify(range)}`);
      }
    }

    // Add the major version as compatible with the angular compatible. This is already one
    // major above the greatest supported, because we increment `major` before checking.
    return semver.validRange(`^${major}.0.0-rc.0 || ${range}`) || range;
  },
開發者ID:iwe7,項目名稱:devkit,代碼行數:14,代碼來源:index.ts

示例3: _getVersionFromNpmPackage

function _getVersionFromNpmPackage(json: JsonObject, version: string, loose: boolean): string {
  const distTags = json['dist-tags'] as JsonObject;
  if (distTags && distTags[version]) {
    return (loose ? '~' : '') + distTags[version] as string;
  } else {
    if (!semver.validRange(version)) {
      throw new SchematicsException(`Invalid range or version: "${version}".`);
    }
    if (semver.valid(version) && loose) {
      version = '~' + version;
    }

    const packageVersions = Object.keys(json['versions'] as JsonObject);
    const maybeMatch = semver.maxSatisfying(packageVersions, version);

    if (!maybeMatch) {
      throw new SchematicsException(
        `Version "${version}" has no satisfying version for package ${json['name']}`,
      );
    }

    const maybeOperator = version.match(/^[~^]/);
    if (version == '*') {
      return maybeMatch;
    } else if (maybeOperator) {
      return maybeOperator[0] + maybeMatch;
    } else {
      return (loose ? '~' : '') + maybeMatch;
    }
  }
}
開發者ID:fmalcher,項目名稱:angular-cli,代碼行數:31,代碼來源:npm.ts

示例4: match

export function match(range: string, versions: string[], tags: Dictionary<string> = {}): string {
    if (Semver.validRange(range)) {
        versions = versions.sort(Semver.rcompare);

        let latest = tags['latest'] || versions[0];

        for (let version of versions) {
            if (Semver.gte(latest, version) && Semver.satisfies(version, range)) {
                return version;
            }
        }

        for (let version of versions) {
            if (Semver.satisfies(version, range)) {
                return version;
            }
        }

        if (range === '*') {
            return latest;
        }

        return undefined;
    } else {
        // Otherwise, treat it as a tag (according to NPM source code).
        return hasOwnProperty.call(tags, range) ? tags[range] : undefined;
    }
}
開發者ID:vilic,項目名稱:semver-match,代碼行數:28,代碼來源:index.ts

示例5: getVersion

async function getVersion(pkg: string, specifier: string) {
  let key = JSON.stringify([pkg, specifier]);
  if (versionCache.has(key)) {
    return versionCache.get(key);
  }
  if (semver.validRange(specifier) === null) {
    // We have a tag, with possibly a range specifier, such as ^latest
    let match = specifier.match(tags);
    if (match === null) {
      throw Error(`Invalid version specifier: ${specifier}`);
    }

    // Look up the actual version corresponding to the tag
    let { version } = await packageJson(pkg, { version: match[2] });
    specifier = match[1] + version;
  }
  versionCache.set(key, specifier);
  return specifier;
}
開發者ID:vidartf,項目名稱:jupyterlab,代碼行數:19,代碼來源:update-dependency.ts

示例6: makeCaretRange

function makeCaretRange(dependencies: { [key: string]: string }, name: string) {
  const version = dependencies[name]

  if (typeof version === 'undefined') {
    console.error(chalk.red(`Missing ${name} dependency in package.json`))
    process.exit(1)
  }

  let patchedVersion = `^${version}`

  if (!semver.validRange(patchedVersion)) {
    console.error(
      `Unable to patch ${name} dependency version because version ${chalk.red(
        version
      )} will ` + `become invalid ${chalk.red(patchedVersion)}`
    )
    patchedVersion = version
  }

  dependencies[name] = patchedVersion
}
開發者ID:aranja,項目名稱:tux,代碼行數:21,代碼來源:new.ts

示例7: getWarningForPluginCore

	private getWarningForPluginCore(localPlugin: string, localPluginVersion: string, devicePluginVersion: string, deviceId: string): string {
		this.$logger.trace(`Comparing plugin ${localPlugin} with localPluginVersion ${localPluginVersion} and devicePluginVersion ${devicePluginVersion}`);

		if (!devicePluginVersion) {
			return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, deviceId);
		}

		const shouldSkipCheck = !semver.valid(localPluginVersion) && !semver.validRange(localPluginVersion);
		if (shouldSkipCheck) {
			return null;
		}

		const localPluginVersionData = semver.coerce(localPluginVersion);
		const devicePluginVersionData = semver.coerce(devicePluginVersion);

		if (localPluginVersionData.major !== devicePluginVersionData.major) {
			return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
		} else if (localPluginVersionData.minor > devicePluginVersionData.minor) {
			return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
		}

		return null;
	}
開發者ID:NativeScript,項目名稱:nativescript-cli,代碼行數:23,代碼來源:preview-app-plugins-service.ts

示例8:

bool = semver.gte(v1, v2, loose);
bool = semver.lt(v1, v2, loose);
bool = semver.lte(v1, v2, loose);
bool = semver.eq(v1, v2, loose);
bool = semver.neq(v1, v2, loose);
bool = semver.cmp(v1, op, v2, loose);
comparatorResult = semver.compare(v1, v2, loose);
comparatorResult = semver.rcompare(v1, v2, loose);
comparatorResult = semver.compareIdentifiers(str, str);
comparatorResult = semver.rcompareIdentifiers(str, str);
versionsArr = semver.sort(['', new semver.SemVer('')]);
versionsArr = semver.rsort(['', new semver.SemVer('')]);
diff = semver.diff(v1, v2, loose);

// Ranges
str = semver.validRange(str, loose);
bool = semver.satisfies(version, str, loose);
str = semver.maxSatisfying(versions, str, loose);
str = semver.minSatisfying(versions, str, loose);
bool = semver.gtr(version, str, loose);
bool = semver.ltr(version, str, loose);
bool = semver.outside(version, str, '<', loose);
bool = semver.intersects(str, str, loose);

let ver = new semver.SemVer(str, bool);
str = ver.raw;
bool = ver.loose;
str = ver.format();
str = ver.inspect();
str = ver.toString();
開發者ID:PriceSpider-NeuIntel,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:semver-tests.ts

示例9: isValidVersion

	protected isValidVersion(version: string): string {
		return semver.valid(version) || semver.validRange(version);
	}
開發者ID:NativeScript,項目名稱:nativescript-cli,代碼行數:3,代碼來源:version-validator-helper.ts


注:本文中的semver.validRange函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。