Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : KA Maps Engine8 * File : server/km-maps/lib/semver.ts9 * Module : server10 * Repository : https://git.spboucher.ai/ka-maps-engine11 * Created : 2026-12-0112 * Last Modified : 2026-12-0113 *14 * Author : Simon-Pierre Boucher15 * Position : Professor of Finance16 * Institution : Université du Québec en Outaouais (UQO)17 * Organization : SP Boucher18 * Website : https://spboucher.ai19 * Git : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development : dev@spboucher.ai23 * Support : support@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Versions `a.b.c` du moteur et des thèmes (un suffixe `-pre` ou `+build` est toléré et ignoré).43export const SEMVER_RE = /^(\d{1,5})\.(\d{1,5})\.(\d{1,5})(?:[-+][0-9A-Za-z.-]{1,40})?$/;4445export function parseSemver(s: unknown): [number, number, number] | null {46 if (typeof s !== 'string') return null;47 const m = SEMVER_RE.exec(s);48 return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;49}5051/** < 0 si a < b, 0 si égales, > 0 si a > b. Une version illisible est traitée comme 0.0.0. */52export function compareSemver(a: string, b: string): number {53 const x = parseSemver(a) ?? [0, 0, 0];54 const y = parseSemver(b) ?? [0, 0, 0];55 for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] - y[i];56 return 0;57}58