From 02dd14109599a39a9180304954e0476957b29956 Mon Sep 17 00:00:00 2001 From: Harry de Kroon Date: Fri, 19 Feb 2021 16:55:04 +0100 Subject: [PATCH] New attempt for PR #2821 PR #2821 could not be completed due to different email addresses used for it's commits. This new branch is meant to be used as a new PR to replace the failed one --- .../editor-client/src/js/ui/palette-editor.js | 67 ++++++++++++++++--- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js index b0aeed0fe..48dd47a08 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js @@ -31,15 +31,66 @@ RED.palette.editor = (function() { var eventTimers = {}; var activeFilter = ""; - function semVerCompare(A,B) { - var aParts = A.split(".").map(function(m) { return parseInt(m);}); - var bParts = B.split(".").map(function(m) { return parseInt(m);}); - for (var i=0;i<3;i++) { - var j = aParts[i]-bParts[i]; - if (j<0) { return -1 } - if (j>0) { return 1 } + var semverre = /^(?\d+)(\.(?\d+))?(\.(?\d+))?(-(?
[0-9A-Za-z-]+))?(\.(?[0-9A-Za-z-.]+))?$/;
+    var NUMBERS_ONLY = /^\d+$/;
+
+
+	function SemVerPart ( part ) {
+        this.number = 0;
+        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) {