lakutata
Version:
An IoC-based universal application framework.
195 lines (170 loc) • 4.26 kB
JavaScript
/* Build Date: Mon Jan 05 2026 23:52:23 GMT+0800 (China Standard Time) */
;
function e(e) {
return typeof e === "object" && e !== null;
}
function n(n) {
return e(n) && typeof n.length === "number";
}
function i(e) {
if (Array.isArray(e)) {
return e;
} else if (e === undefined) {
return [];
} else if (n(e) || e instanceof Set) {
return Array.from(e);
} else {
return [ e ];
}
}
function t(e) {
return !isNaN(parseFloat(e));
}
function r(e) {
return !isNaN(parseFloat(e)) && isFinite(e);
}
function s(e) {
return e !== null && typeof e === "object" && e.constructor === Object;
}
function u(e) {
return f(e) && typeof e.length === "number";
}
function f(e) {
return typeof e === "object" && e !== null;
}
function o(e) {
return typeof e !== "undefined";
}
function c(e) {
return !o(e);
}
function l(e) {
return e === null;
}
function a(e) {
return o(e) && !l(e) && !Number.isNaN(e);
}
function d(e) {
if (typeof e === "function") {
return /^class /.test(Function.prototype.toString.call(e));
} else {
return false;
}
}
function y(e) {
if (e === null) return true;
switch (typeof e) {
case "string":
case "number":
case "symbol":
case "undefined":
case "boolean":
return true;
default:
return false;
}
}
function b(e) {
if (e) {
const n = o(Promise) && e instanceof Promise;
const i = e.then && typeof e.then === "function";
return !!(n || i);
} else {
return false;
}
}
function m(e) {
if (e === null || !o(e)) {
return false;
} else {
return typeof e[Symbol.iterator] === "function" || typeof e[Symbol.asyncIterator] === "function";
}
}
function p(e) {
return typeof e === "string";
}
function N(e) {
return typeof e === "function";
}
function D(e) {
return typeof e === "function" && e.constructor.name === "AsyncFunction";
}
const k = {
isNumber: t,
isFiniteNumber: r,
isPlainObject: s,
isArrayLike: u,
isObject: f,
isDefined: o,
isUndefined: c,
isNull: l,
isDefinedValue: a,
isClass: d,
isPrimitive: y,
isPromise: b,
isIterable: m,
isString: p,
isFunction: N,
isAsyncFunction: D
};
function R(e, n = {}) {
n = Object.assign({
computed: {},
customOrders: {},
nullRank: 1,
undefinedRank: 1,
nanRank: 1
}, n);
e.sort(g(n));
return e;
}
function g(e = {}) {
const n = i(e.by);
const t = i(e.order);
const {customOrders: r, computed: s} = e;
return function i(u, f, o = 0) {
const c = t[o] || "asc";
if (!(c === "asc" || c === "desc" || r[c])) {
return 0;
}
let l, a, d;
if (n.length) {
a = k.isDefined(u[n[o]]) ? u[n[o]] : s[n[o]] && s[n[o]](u);
d = k.isDefined(f[n[o]]) ? f[n[o]] : s[n[o]] && s[n[o]](f);
} else {
a = u;
d = f;
}
if (r && r[c]) {
l = r[c].indexOf(a) - r[c].indexOf(d);
} else if (a === d) {
l = 0;
} else if (k.isNull(a) && k.isUndefined(d)) {
l = c === "asc" ? 1 : c === "desc" ? -1 : 0;
} else if (k.isUndefined(a) && k.isNull(d)) {
l = c === "asc" ? -1 : c === "desc" ? 1 : 0;
} else if (k.isNull(a) && k.isDefinedValue(d)) {
l = e.nullRank;
} else if (k.isUndefined(a) && k.isDefinedValue(d)) {
l = e.undefinedRank;
} else if (Number.isNaN(a) && k.isDefinedValue(d)) {
l = e.nanRank;
} else if (k.isNull(d) && k.isDefinedValue(a)) {
l = -e.nullRank;
} else if (k.isUndefined(d) && k.isDefinedValue(a)) {
l = -e.undefinedRank;
} else if (Number.isNaN(d) && k.isDefinedValue(a)) {
l = -e.nanRank;
} else {
l = a < d ? -1 : a > d ? 1 : 0;
if (c === "desc") {
l = l * -1;
}
}
if (l === 0 && k.isDefined(n[o + 1])) {
l = i(u, f, o + 1);
}
return l;
};
}
exports.sortArray = R;