]> Git Repo - pico-vscode.git/blob - src/utils/semverUtil.mts
Add elf2uf2 and pioasm for sdk 1.5.1
[pico-vscode.git] / src / utils / semverUtil.mts
1 /**
2  * Function used to determine the order of the elements.
3  * It is expected to return
4  * - a negative value if the first argument is less than the second argument,
5  * - zero if they're equal,
6  * - and a positive value otherwise.
7  * If omitted, the elements are sorted in ascending, ASCII character order.
8  *
9  * @param a
10  * @param b
11  * @returns
12  */
13 export function compare(a: string, b: string): number {
14   // check format
15   if (!/^\d+(\.\d+)*$/.test(a) || !/^\d+(\.\d+)*$/.test(b)) {
16     //throw new Error("Invalid version format");
17     //return null;
18     return 0;
19   }
20
21   const aParts = a.split(".");
22   const bParts = b.split(".");
23
24   for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
25     const aPart = parseInt(aParts[i] || "0");
26     const bPart = parseInt(bParts[i] || "0");
27
28     if (aPart > bPart) {
29       return 1;
30     } else if (aPart < bPart) {
31       return -1;
32     }
33   }
34
35   return 0;
36 }
This page took 0.028286 seconds and 4 git commands to generate.