本文整理汇总了TypeScript中semver.clean函数的典型用法代码示例。如果您正苦于以下问题:TypeScript clean函数的具体用法?TypeScript clean怎么用?TypeScript clean使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clean函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateChangelogs
function updateChangelogs(
changelogs: ChangelogOfVersion[],
version: string,
prs: GithubIssue[],
): ChangelogOfVersion[] {
const prevChangelog = getChangelogOfVersion(changelogs, version);
const newChangelog: ChangelogOfVersion = {
version: semver.clean(version),
items: prs.map(parsePrToChangelogItem),
};
if (prevChangelog) {
const index = changelogs.indexOf(prevChangelog);
changelogs[index] = newChangelog;
} else {
changelogs.push(newChangelog);
}
// Sort desc by version.
return changelogs.sort((a, b) => {
if (semver.gt(a.version, b.version)) {
return -1;
} else if (semver.lt(a.version, b.version)) {
return 1;
} else {
return 0;
}
});
}
示例2: getVersion
async function getVersion(program: string, command: string, matcher: RegExp): Promise<string> {
try {
const result = await tryExecuteCommand(undefined, program, command);
if (result.code === 0) {
const output = result.cmdOutput || result.cmdOutputIncludingStderr;
const truffleVersion = output.match(matcher);
const version = semver.clean(truffleVersion ? truffleVersion[1] : '');
return version || '';
}
} catch (error) {
// ignore error
}
return '';
}
示例3:
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);
num = semver.patch(str, loose);
strArr = semver.prerelease(str, loose);
示例4:
const releaseTypes = ["major", "premajor", "minor", "preminor", "patch", "prepatch", "prerelease"];
const releaseType = argv._[0] || "patch";
let newVersion = releaseType;
const oldVersion = pack.version as string;
if (releaseTypes.indexOf(releaseType) > -1) {
if (releaseType.startsWith("pre") && argv._.length >= 2) {
// increment to pre-release with an additional prerelease string
newVersion = semver.inc(oldVersion, releaseType, argv._[1]);
} else {
newVersion = semver.inc(oldVersion, releaseType);
}
console.log(`bumping version ${colors.blue(oldVersion)} to ${colors.gray(releaseType)} version ${colors.green(newVersion)}\n`);
} else {
// increment to specific version
newVersion = semver.clean(newVersion);
if (newVersion == null) {
fail(`invalid version string "${newVersion}"`);
} else {
// valid version string => check if its actually newer
if (!semver.gt(newVersion, pack.version)) {
fail(`new version ${newVersion} is NOT > than package.json version ${pack.version}`);
}
// if (!semver.gt(newVersion, ioPack.common.version)) {
// fail(`new version ${newVersion} is NOT > than io-package.json version ${ioPack.common.version}`);
// }
}
console.log(`bumping version ${oldVersion} to specific version ${newVersion}`);
}
if (argv.dry) {
示例5: getChangelogOfVersion
function getChangelogOfVersion(changelogs: ChangelogOfVersion[], version: string): ChangelogOfVersion | undefined {
const cleanVersion = semver.clean(version);
return changelogs.find(changelog => changelog.version === cleanVersion);
}
示例6: toTRY
/**
* @author TĂźmay Ăeber <tumayceber@gmail.com>
* @link https://github.com/brendtumi/bkmexpress
* @license http://opensource.org/licenses/MIT
* @date 28.04.2017
*/
import * as semver from "semver";
import {MoneyUtilException} from "./exceptions";
const nodeVersion = semver.clean(process.version);
export class MoneyUtils {
public static toTRY(amount: number): string {
let formatted: string;
if (semver.lt(nodeVersion, "4.0.0")) {
formatted = (Math.round(amount * 100) / 100).toString();
const split: string[] = formatted.split(".");
if (split.length === 1 || split[1].length < 1) {
split[1] = "00";
}
else if (split[1].length < 2) {
split[1] = split[1] + "0";
}
formatted = split.join(",");
}
else {
formatted = amount.toLocaleString("tr-TR", {style: "currency", currency: "TRY", currencyDisplay: "code"});
formatted = formatted.replace(/TRY|,|\s+/gi, "");
formatted = formatted.replace(/\./i, ",");
}
return MoneyUtils.validate(formatted);
}