UNPKG

renovate

Version:

Automated dependency updates. Flexible so you don't need to be.

47 lines (46 loc) 1.7 kB
import { regEx } from "../../../util/regex.js"; //#region lib/modules/versioning/rust-release-channel/parse.ts /** * Parse a Rust toolchain string into a structured object. * * Supports the format: <channel>[-<date>][-<host>] * * @param input - The toolchain string to parse * @returns Parsed toolchain object, or null if the input is invalid * * @example * parse('stable') // { channel: 'stable' } * parse('1.82.0') // { channel: { major: 1, minor: 82, patch: 0 } } * parse('nightly-2025-11-24') // { channel: 'nightly', date: { year: 2025, month: 11, day: 24 } } * parse('invalid') // null */ function parse(input) { if (!input) return null; const match = regEx(/^(?<channel>stable|beta|nightly|(?<major>\d+)\.(?<minor>\d+)(?:\.(?<patch>\d+))?(?:-(?<beta>beta)(?:\.(?<betaNumber>\d+))?)?)(?:-(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}))?(?:-(?<host>.+))?$/).exec(input); if (!match?.groups) return null; const { channel: channelStr, major, minor, patch, beta, betaNumber, year, month, day, host } = match.groups; let channel; if (channelStr === "stable" || channelStr === "beta" || channelStr === "nightly") channel = channelStr; else { channel = { major: parseInt(major, 10), minor: parseInt(minor, 10) }; if (patch) channel.patch = parseInt(patch, 10); if (beta === "beta") { channel.prerelease = { name: "beta" }; if (betaNumber) channel.prerelease.number = parseInt(betaNumber, 10); } } const result = { channel }; if (year && month && day) result.date = { year: parseInt(year, 10), month: parseInt(month, 10), day: parseInt(day, 10) }; if (host) result.host = host; return result; } //#endregion export { parse }; //# sourceMappingURL=parse.js.map