1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #2879 from HaKr/SemVerFullCompareNewAttempt

New attempt for PR #2821
This commit is contained in:
Nick O'Leary 2021-02-22 11:01:39 +00:00 committed by GitHub
commit 69befe8f0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,15 +31,66 @@ RED.palette.editor = (function() {
var eventTimers = {}; var eventTimers = {};
var activeFilter = ""; var activeFilter = "";
function semVerCompare(A,B) { var semverre = /^(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(-(?<pre>[0-9A-Za-z-]+))?(\.(?<build>[0-9A-Za-z-.]+))?$/;
var aParts = A.split(".").map(function(m) { return parseInt(m);}); var NUMBERS_ONLY = /^\d+$/;
var bParts = B.split(".").map(function(m) { return parseInt(m);});
for (var i=0;i<3;i++) {
var j = aParts[i]-bParts[i]; function SemVerPart ( part ) {
if (j<0) { return -1 } this.number = 0;
if (j>0) { return 1 } this.text = part;
if ( NUMBERS_ONLY.test( toe ) )
{
this.number = parseInt( part );
this.type = "N";
} else
{
this.type = part == undefined || part.length < 1 ? "E" : "T";
} }
return 0; }
SemVerPart.prototype.compare = function ( other ) {
const types = this.type + other.type;
switch ( types )
{
case "EE": return 0;
case "NT":
case "TE":
case "EN": return -1;
case "NN": return this.number - other.number;
case "TT": return this.text.localeCompare( other.text );
case "ET":
case "TN":
case "NE": return 1;
}
};
function SemVer ( ver ) {
const groups = ver.match( semverre ).groups;
this.parts = [ new SemVerPart( groups.major ), new SemVerPart( groups.minor ), new SemVerPart( groups.patch ), new SemVerPart( groups.pre ), new SemVerPart( groups.build ) ];
}
SemVer.prototype.compare = function ( other ) {
let result = 0;
for ( let i = 0, n = this.parts.length; result == 0 && i < n; i++ )
{
result = this.parts[ i ].compare( other.parts[ i ] );
}
return result;
};
function semVerCompare ( ver1, ver2 ) {
const semver1 = new SemVer( ver1 );
const semver2 = new SemVer( ver2 );
const result = semver1.compare( semver2 );
return result;
} }
function delayCallback(start,callback) { function delayCallback(start,callback) {