keep-a-changelog
Version:
Node package to parse and generate changelogs following the [keepachangelog](https://keepachangelog.com/) format.
31 lines (30 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryParse = tryParse;
const parse_js_1 = require("./parse.js");
/**
* Returns the parsed SemVer, or `undefined` if it's not valid.
*
* @example Usage
* ```ts
* import { tryParse } from "@std/semver/try-parse";
* import { assertEquals } from "@std/assert";
*
* assertEquals(tryParse("1.2.3"), { major: 1, minor: 2, patch: 3, prerelease: [], build: [] });
* assertEquals(tryParse("1.2.3-alpha"), { major: 1, minor: 2, patch: 3, prerelease: ["alpha"], build: [] });
* assertEquals(tryParse("1.2.3+build"), { major: 1, minor: 2, patch: 3, prerelease: [], build: ["build"] });
* assertEquals(tryParse("1.2.3-alpha.1+build.1"), { major: 1, minor: 2, patch: 3, prerelease: ["alpha", 1], build: ["build", "1"] });
* assertEquals(tryParse(" invalid "), undefined);
* ```
*
* @param value The version string to parse
* @returns A valid SemVer or `undefined`
*/
function tryParse(value) {
try {
return (0, parse_js_1.parse)(value);
}
catch {
return undefined;
}
}