INNER CODE UNIT · TypeScript

compareSemverDesc

cyanheads/pubmed-mcp-server · scripts/build-changelog.ts:63

function compareSemverDesc(a: string, b: string): number {
  const parse = (v: string): [number[], string | null] => {
    const [base, pre = null] = v.split('-', 2) as [string, string | undefined];
    return [base.split('.').map(Number), pre ?? null];
  };
  const [aParts, aPre] = parse(a);
  const [bParts, bPre] = parse(b);
  for (let i = 0; i < 3; i++) {
    const diff = (bParts[i] ?? 0) - (aParts[i] ?? 0);
    if (diff !== 0) return diff;
  }
  if (aPre === bPre) return 0;
  if (aPre === null) return -1;
  if (bPre === null) return 1;
  return bPre.localeCompare(aPre);
}

/**

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…