Files
Sergei Zharinov 930cf6633c refactor: Rewrite imports with .ts extensions (#40700)
fix: Additional vi.mock path corrections and prettier formatting
2026-01-26 22:48:17 +00:00

22 lines
626 B
TypeScript

import { regEx } from '../../../util/regex.ts';
import type { Range } from './types.ts';
// This range format was chosen because it is common in the ecosystem
const gteAndLtRange = regEx(/>=(?<lower>[\d.]+)&&<(?<upper>[\d.]+)/);
const ltAndGteRange = regEx(/<(?<upper>[\d.]+)&&>=(?<lower>[\d.]+)/);
export function parseRange(input: string): Range | null {
const noSpaces = input.replaceAll(' ', '');
let m = gteAndLtRange.exec(noSpaces);
if (!m?.groups) {
m = ltAndGteRange.exec(noSpaces);
if (!m?.groups) {
return null;
}
}
return {
lower: m.groups.lower,
upper: m.groups.upper,
};
}