MCPcopy
hub / github.com/mongodb/node-mongodb-native / customSemverCompare

Function customSemverCompare

etc/docs/utils.ts:93–112  ·  view source on GitHub ↗
(a: string, b: string)

Source from the content-addressed store, hash-verified

91}
92
93export function customSemverCompare(a: string, b: string) {
94 [a, b] = [a.toLowerCase(), b.toLowerCase()];
95
96 // 'next' always bubbles to the front of the list
97 if ([a, b].includes('next')) {
98 return a === 'next' ? -1 : 1;
99 }
100
101 const [majorA, minorA] = a.split('.').map(Number);
102 const [majorB, minorB] = b.split('.').map(Number);
103
104 if (majorA === majorB) {
105 if (minorA === minorB) {
106 return 0;
107 }
108 return minorB > minorA ? 1 : -1;
109 }
110
111 return majorB > majorA ? 1 : -1;
112}

Callers 1

Calls 1

mapMethod · 0.45

Tested by

no test coverage detected