Files
t-admin/unpackage/dist/dev/mp-weixin/uni_modules/uni-upgrade-center/pages/utils.js
T
2025-06-13 21:16:12 +08:00

57 lines
1.7 KiB
JavaScript

"use strict";
function isArray(arr) {
return Object.prototype.toString.call(arr) === "[object Array]";
}
function deepClone(obj) {
if ([null, void 0, NaN, false].includes(obj))
return obj;
if (typeof obj !== "object" && typeof obj !== "function") {
return obj;
}
let o = isArray(obj) ? [] : {};
for (let i in obj) {
if (obj.hasOwnProperty(i)) {
o[i] = typeof obj[i] === "object" ? deepClone(obj[i]) : obj[i];
}
}
return o;
}
const appListDbName = "opendb-app-list";
const appVersionListDbName = "opendb-app-versions";
const defaultDisplayApp = "";
function compare(v1 = "0", v2 = "0") {
v1 = String(v1).split(".");
v2 = String(v2).split(".");
const minVersionLens = Math.min(v1.length, v2.length);
let result = 0;
for (let i = 0; i < minVersionLens; i++) {
const curV1 = Number(v1[i]);
const curV2 = Number(v2[i]);
if (curV1 > curV2) {
result = 1;
break;
} else if (curV1 < curV2) {
result = -1;
break;
}
}
if (result === 0 && v1.length !== v2.length) {
const v1BiggerThenv2 = v1.length > v2.length;
const maxLensVersion = v1BiggerThenv2 ? v1 : v2;
for (let i = minVersionLens; i < maxLensVersion.length; i++) {
const curVersion = Number(maxLensVersion[i]);
if (curVersion > 0) {
v1BiggerThenv2 ? result = 1 : result = -1;
break;
}
}
}
return result;
}
exports.appListDbName = appListDbName;
exports.appVersionListDbName = appVersionListDbName;
exports.compare = compare;
exports.deepClone = deepClone;
exports.defaultDisplayApp = defaultDisplayApp;
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/uni_modules/uni-upgrade-center/pages/utils.js.map