| |
| |
| |
| |
| |
| |
| |
| |
|
|
| define([], function() { |
| let pgAdmin = window.pgAdmin = window.pgAdmin || {}; |
|
|
| |
| |
| |
| pgAdmin.natural_sort = function(a, b, options) { |
| options = options || {}; |
|
|
| let re = /(^-?\d+(\.?\d*)[df]?e?\d?$|^0x[0-9a-f]+$|\d+)/gi, |
| sre = /(^[ ]*|[ ]*$)/g, |
| dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/, |
| hre = /^0x[0-9a-f]+$/i, |
| ore = /^0/, |
| i = function(s) { |
| return options.insensitive && ('' + s).toLowerCase() || '' + s; |
| }, |
| |
| x = i(a).replace(sre, '') || '', |
| y = i(b).replace(sre, '') || '', |
| |
| xN = x.replace(re, '\0$1\0').replace(/\0$/, '').replace(/^\0/, '').split('\0'), |
| yN = y.replace(re, '\0$1\0').replace(/\0$/, '').replace(/^\0/, '').split('\0'), |
| |
| xD = parseInt(x.match(hre)) || (xN.length !== 1 && x.match(dre) && Date.parse(x)), |
| yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null, |
| oFxNcL, oFyNcL, |
| mult = options.desc ? -1 : 1; |
|
|
| |
| if (yD) |
| if (xD < yD) return -1 * mult; |
| else if (xD > yD) return 1 * mult; |
|
|
| |
| for (let cLoc = 0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { |
| |
| oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0; |
| oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; |
| |
| if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { |
| return (isNaN(oFxNcL) ? 1 : -1) * mult; |
| } |
| |
| else if (typeof oFxNcL !== typeof oFyNcL) { |
| oFxNcL += ''; |
| oFyNcL += ''; |
| } |
| if (oFxNcL < oFyNcL) return -1 * mult; |
| if (oFxNcL > oFyNcL) return 1 * mult; |
| } |
| return 0; |
| }; |
|
|
| pgAdmin.numeric_comparator = function(a, b) { |
| a = parseInt(a); |
| b = parseInt(b); |
| if (a < b) |
| return -1; |
| else if (a == b) |
| return 0; |
| else |
| return 1; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| function decimalAdjust(type, value, exp) { |
| |
| if (typeof exp === 'undefined' || +exp === 0) { |
| return Math[type](value); |
| } |
| value = +value; |
| exp = +exp; |
| |
| if (isNaN(value) || exp % 1 !== 0) { |
| return NaN; |
| } |
| |
| value = value.toString().split('e'); |
| value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp))); |
| |
| value = value.toString().split('e'); |
| return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp)); |
| } |
|
|
| |
| if (!Math.round10) { |
| Math.round10 = function(value, exp) { |
| return decimalAdjust('round', value, exp); |
| }; |
| } |
| |
| if (!Math.floor10) { |
| Math.floor10 = function(value, exp) { |
| return decimalAdjust('floor', value, exp); |
| }; |
| } |
| |
| if (!Math.ceil10) { |
| Math.ceil10 = function(value, exp) { |
| return decimalAdjust('ceil', value, exp); |
| }; |
| } |
|
|
| return pgAdmin; |
| }); |
|
|