mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix semver comparison in palette editor
This commit is contained in:
parent
7be7dec19a
commit
3dc696b2a9
@ -34,35 +34,26 @@ RED.palette.editor = (function() {
|
|||||||
var semverre = /^(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(-(?<pre>[0-9A-Za-z-]+))?(\.(?<build>[0-9A-Za-z-.]+))?$/;
|
var semverre = /^(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(-(?<pre>[0-9A-Za-z-]+))?(\.(?<build>[0-9A-Za-z-.]+))?$/;
|
||||||
var NUMBERS_ONLY = /^\d+$/;
|
var NUMBERS_ONLY = /^\d+$/;
|
||||||
|
|
||||||
|
|
||||||
function SemVerPart(part) {
|
function SemVerPart(part) {
|
||||||
this.number = 0;
|
this.number = 0;
|
||||||
this.text = part;
|
this.text = part;
|
||||||
if ( NUMBERS_ONLY.test( toe ) )
|
if ( NUMBERS_ONLY.test(part)){
|
||||||
{
|
|
||||||
this.number = parseInt(part);
|
this.number = parseInt(part);
|
||||||
this.type = "N";
|
this.type = "N";
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
this.type = part == undefined || part.length < 1 ? "E" : "T";
|
this.type = part == undefined || part.length < 1 ? "E" : "T";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SemVerPart.prototype.compare = function(other) {
|
SemVerPart.prototype.compare = function(other) {
|
||||||
const types = this.type + other.type;
|
var types = this.type + other.type;
|
||||||
|
switch ( types ) {
|
||||||
switch ( types )
|
|
||||||
{
|
|
||||||
case "EE": return 0;
|
case "EE": return 0;
|
||||||
|
|
||||||
case "NT":
|
case "NT":
|
||||||
case "TE":
|
case "TE":
|
||||||
case "EN": return -1;
|
case "EN": return -1;
|
||||||
|
|
||||||
case "NN": return this.number - other.number;
|
case "NN": return this.number - other.number;
|
||||||
|
|
||||||
case "TT": return this.text.localeCompare( other.text );
|
case "TT": return this.text.localeCompare( other.text );
|
||||||
|
|
||||||
case "ET":
|
case "ET":
|
||||||
case "TN":
|
case "TN":
|
||||||
case "NE": return 1;
|
case "NE": return 1;
|
||||||
@ -70,26 +61,22 @@ RED.palette.editor = (function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function SemVer(ver) {
|
function SemVer(ver) {
|
||||||
const groups = ver.match( semverre ).groups;
|
var 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 ) ];
|
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) {
|
SemVer.prototype.compare = function(other) {
|
||||||
let result = 0;
|
var result = 0;
|
||||||
for ( let i = 0, n = this.parts.length; result == 0 && i < n; i++ )
|
for ( var i = 0, n = this.parts.length; result == 0 && i < n; i++ ) {
|
||||||
{
|
|
||||||
result = this.parts[ i ].compare( other.parts[ i ] );
|
result = this.parts[ i ].compare( other.parts[ i ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
function semVerCompare(ver1, ver2) {
|
function semVerCompare(ver1, ver2) {
|
||||||
const semver1 = new SemVer( ver1 );
|
var semver1 = new SemVer(ver1);
|
||||||
const semver2 = new SemVer( ver2 );
|
var semver2 = new SemVer(ver2);
|
||||||
|
var result = semver1.compare(semver2);
|
||||||
const result = semver1.compare( semver2 );
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user