Skip to content

Commit

Permalink
fix(api): invalid version sorting (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Dec 9, 2023
1 parent a96f31e commit 4ee5a54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-donuts-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": patch
---

fix(api): invalid version sorting
15 changes: 9 additions & 6 deletions api/metadata/src/stats/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ interface JSDelivrAPIVersion {

export const sortSemverList = (list: string[]): string[] => {
return list.sort((a, b) => {
const aMajor = a.split('.')[0];
const bMajor = b.split('.')[0];
const aMinor = a.split('.')[1];
const bMinor = b.split('.')[1];
const aPatch = a.split('.')[2];
const bPatch = b.split('.')[2];
const aSplit = a.split('.');
const bSplit = b.split('.');

const aMajor = Number(aSplit[0]);
const bMajor = Number(bSplit[0]);
const aMinor = Number(aSplit[1]);
const bMinor = Number(bSplit[1]);
const aPatch = Number(aSplit[2]);
const bPatch = Number(bSplit[2]);
if (aMajor > bMajor) return -1;
if (aMajor < bMajor) return 1;
if (aMinor > bMinor) return -1;
Expand Down

0 comments on commit 4ee5a54

Please sign in to comment.