MCPcopy Index your code
hub / github.com/MagicMirrorOrg/MagicMirror / cmpVersions

Function cmpVersions

js/app.js:163–177  ·  view source on GitHub ↗

* Compare two semantic version numbers and return the difference. * @param {string} a Version number a. * @param {string} b Version number b. * @returns {number} A positive number if a is larger than b, a negative * number if a is smaller and 0 if they are the same

(a, b)

Source from the content-addressed store, hash-verified

161 * number if a is smaller and 0 if they are the same
162 */
163 function cmpVersions (a, b) {
164 let i, diff;
165 const regExStrip0 = /(\.0+)+$/;
166 const segmentsA = a.replace(regExStrip0, "").split(".");
167 const segmentsB = b.replace(regExStrip0, "").split(".");
168 const l = Math.min(segmentsA.length, segmentsB.length);
169
170 for (i = 0; i < l; i++) {
171 diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10);
172 if (diff) {
173 return diff;
174 }
175 }
176 return segmentsA.length - segmentsB.length;
177 }
178
179 /**
180 * Start the core app.

Callers 1

loadModuleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected