All files / src/utils version.ts

100% Statements 9/9
100% Branches 6/6
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                    28x 1287x   1275x 1275x   1271x 1271x   1271x    
/**
 * Parse a version string into a comparable integer.
 * Uses major * 100 + minor encoding to correctly handle minor >= 10
 * (e.g., "16.11.0" → 1611, "8.14.2" → 814).
 *
 * @param version - Version string like "16.11.0-ee", "15.0", or "unknown"
 * @returns Comparable integer (0 for unparseable versions)
 * @example parseVersion("16.11.0-ee") // 1611
 * @example parseVersion("unknown") // 0
 */
export function parseVersion(version: string): number {
  if (!version || version === "unknown") return 0;
 
  const match = version.match(/^(\d+)\.(\d+)/);
  if (!match) return 0;
 
  const major = parseInt(match[1], 10);
  const minor = parseInt(match[2], 10);
 
  return major * 100 + minor;
}