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


TypeScript semver.parse函數代碼示例

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


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

示例1: getNextVersionNumber

export function getNextVersionNumber(
  version: string,
  channel: Channel
): string {
  const semanticVersion = parse(version)

  if (semanticVersion == null) {
    throw new Error(`Unable to parse input '${version}' into version`)
  }

  switch (channel) {
    case 'production':
      if (isBetaTag(semanticVersion)) {
        throw new Error(
          `Unable to draft production release using beta version '${version}'`
        )
      }

      if (isTestTag(semanticVersion)) {
        throw new Error(
          `Unable to draft production release using test version '${version}'`
        )
      }

      const nextVersion = inc(version, 'patch')
      if (nextVersion == null) {
        throw new Error(
          `Unable to increment next production version from release version '${version}'`
        )
      }

      return nextVersion

    case 'beta':
      if (isTestTag(semanticVersion)) {
        throw new Error(
          `Unable to draft beta release using test version '${version}'`
        )
      }

      const betaNumber = tryGetBetaNumber(semanticVersion)

      if (betaNumber) {
        return semanticVersion.version.replace(
          `-beta${betaNumber}`,
          `-beta${betaNumber + 1}`
        )
      } else {
        const nextVersion = inc(semanticVersion, 'patch')
        const firstBeta = `${nextVersion}-beta1`
        return firstBeta
      }

    default:
      throw new Error(
        `Resolving the next version is not implemented for channel ${channel}`
      )
  }
}
開發者ID:ghmoore,項目名稱:desktop,代碼行數:59,代碼來源:version.ts

示例2: require

 nvim.channelId.then(async channelId => {
   if (isTest) nvim.command(`let g:coc_node_channel_id = ${channelId}`, true)
   let json = require('../package.json')
   let { major, minor, patch } = semver.parse(json.version)
   nvim.setClientInfo('coc', { major, minor, patch }, 'remote', {}, {})
   let entered = await nvim.getVvar('vim_did_enter')
   if (entered && !initialized) {
     initialized = true
     await plugin.init()
   }
 }).catch(e => {
開發者ID:demelev,項目名稱:coc.nvim,代碼行數:11,代碼來源:attach.ts

示例3: ghGot

    .then(([body, markdown]) => {
      const json = body.body;

      const maybeRelease = json.find((x: JsonObject) => x.tag_name == args.to);
      const id = maybeRelease ? `/${maybeRelease.id}` : '';

      const semversion = (args.to && semver.parse(args.to)) || { prerelease: '' };

      return ghGot('repos/angular/angular-cli/releases' + id, {
        body: {
          body: markdown,
          draft: !maybeRelease,
          name: args.to,
          prerelease: semversion.prerelease.length > 0,
          tag_name: args.to,
          ...(toSha ? { target_commitish: toSha } : {}),
        },
        token: githubToken,
      });
    });
開發者ID:fmalcher,項目名稱:angular-cli,代碼行數:20,代碼來源:changelog.ts

示例4: main

async function main() {
  const json = require('../package.json');

  // determine commit from either circle ci or last git commit
  let commit = process.env.CIRCLE_SHA1;
  if (!commit) {
    const lastCommit = await execute('git rev-parse HEAD');
    commit = lastCommit.toString().trim();
  }

  // shorten commit
  commit = commit!.slice(0, 7);

  // construct new version from base version 2.0.0 to become 2.0.0+dev.shortsha
  const version: SemVer = parse(json.version)!;
  const newVersion = `${version.major}.${version.minor}.${version.patch}-dev.master-${commit}`;

  console.log('publishing new version', newVersion);

  // run through all our packages and push them to npm
  await publishAllPackagesToNpm(newVersion, 'dev');
}
開發者ID:LucasFrecia,項目名稱:store,代碼行數:22,代碼來源:publish-dev-builds.ts

示例5:

let op: semver.Operator = '';
let arr: any[];
let exp: RegExp;
let strArr: string[] | null;
let numArr: string[];
let comparatorResult: -1 | 0 | 1;
let versionsArr: Array<string | semver.SemVer>;

let v1: string = '';
let v2: string = '';
let version: string = '';
let versions: string[] = [];
let loose: boolean = true;
let sem: semver.SemVer | null;

sem = semver.parse(str);
strn = semver.valid(str);
strn = semver.clean(str);

strn = semver.valid(str, loose);
strn = semver.clean(str, loose);
strn = semver.inc(str, "major", loose);
strn = semver.inc(str, "premajor", loose);
strn = semver.inc(str, "minor", loose);
strn = semver.inc(str, "preminor", loose);
strn = semver.inc(str, "patch", loose);
strn = semver.inc(str, "prepatch", loose);
strn = semver.inc(str, "prerelease", loose);
strn = semver.inc(str, "prerelease", loose, "alpha");
num = semver.major(str, loose);
num = semver.minor(str, loose);
開發者ID:PriceSpider-NeuIntel,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:semver-tests.ts


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