Files
renovate[bot] c2aa761c1e chore(deps): update linters (main) (#41417)
* chore(deps): update linters

| datasource | package              | from   | to     |
| ---------- | -------------------- | ------ | ------ |
| npm        | @eslint/js           | 9.39.2 | 9.39.3 |
| npm        | eslint               | 9.39.2 | 9.39.3 |
| npm        | eslint-plugin-oxlint | 1.46.0 | 1.49.0 |
| npm        | oxlint               | 1.47.0 | 1.49.0 |
| npm        | typescript-eslint    | 8.55.0 | 8.56.0 |

* chore(deps): update linters

| datasource | package              | from   | to     |
| ---------- | -------------------- | ------ | ------ |
| npm        | @eslint/js           | 9.39.2 | 9.39.3 |
| npm        | eslint               | 9.39.2 | 9.39.3 |
| npm        | eslint-plugin-oxlint | 1.46.0 | 1.49.0 |
| npm        | oxlint               | 1.47.0 | 1.49.0 |
| npm        | typescript-eslint    | 8.55.0 | 8.56.0 |

* Radix rule has been deprecated

* fixup! Radix rule has been deprecated

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: secustor <sebastian@poxhofer.at>
2026-02-28 11:23:25 +00:00

88 lines
2.0 KiB
TypeScript

import { regEx } from '../../../util/regex.ts';
import type { ToolchainObject, VersionObject } from './types.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
*/
export function parse(input: string): ToolchainObject | null {
if (!input) {
return null;
}
// Format: <channel>[-<date>][-<host>]
// Single regex to parse the entire spec
const regex = 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>.+))?$/,
);
const match = regex.exec(input);
if (!match?.groups) {
return null;
}
const {
channel: channelStr,
major,
minor,
patch,
beta,
betaNumber,
year,
month,
day,
host,
} = match.groups;
let channel: 'stable' | 'beta' | 'nightly' | VersionObject;
if (
channelStr === 'stable' ||
channelStr === 'beta' ||
channelStr === 'nightly'
) {
channel = channelStr;
} else {
// Version channel
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: ToolchainObject = { 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;
}