mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-25 14:41:20 +00:00
14 lines
503 B
TypeScript
14 lines
503 B
TypeScript
/**
|
|
* Compare two X.Y.Z version strings numerically.
|
|
* Returns a positive number if a > b, negative if a < b, 0 if equal.
|
|
*/
|
|
export function compareVersions(a: string, b: string): number {
|
|
const partsA = a.split('.').map((p) => Number.parseInt(p, 10) || 0)
|
|
const partsB = b.split('.').map((p) => Number.parseInt(p, 10) || 0)
|
|
for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
|
|
const diff = (partsA[i] ?? 0) - (partsB[i] ?? 0)
|
|
if (diff !== 0) return diff
|
|
}
|
|
return 0
|
|
}
|