Parses and compares semantic versions, computes next dev/preview/stable releases, and asserts releasability. Reuse for release automation and version bumping in CI scripts.
// Source: https://github.com/lidge-jun/opencodex | License: MIT | Copyright 2026 opencodex contributors
// Provided via justclaw.it.com; keep this notice with the code.
export interface ParsedVersion {
major: number;
minor: number;
patch: number;
prerelease: readonly string[] | null;
}
export type ReleaseBumpKind = "patch" | "minor" | "major";
const VERSION_PATTERN = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
/** Optional leading v, optional prerelease, optional (ignored) build metadata. */
export function parseVersion(raw: string): ParsedVersion | null {
const match = VERSION_PATTERN.exec(raw.trim());
if (!match) return null;
return {
major: Number(match[1]),
minor: Number(match[2]),
patch: Numb
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key