snoby-utils
Version:
A javascrpt utils.
205 lines (204 loc) • 5.46 kB
JavaScript
import a from "dayjs";
function g(t) {
const n = `sno-${t}`;
return w(n);
}
function f(t, n, o, e) {
return n && (t += `-${n}`), o && (t += `__${o}`), e && (t += `--${e}`), t;
}
function w(t) {
return {
b: (i) => f(t, i, "", ""),
e: (i) => f(t, "", i, ""),
m: (i) => f(t, "", "", i),
be: (i, u) => f(t, i, u, ""),
bm: (i, u) => f(t, i, "", u),
bem: (i, u, O) => f(t, i, u, O),
em: (i, u) => f(t, "", i, u),
is: (i, u) => `is-${u}`
};
}
function c(t, n) {
return Object.prototype.toString.call(t) === `[object ${n}]`;
}
function h(t) {
return c(t, "Function");
}
const S = (t) => typeof t < "u", D = (t) => !S(t), m = (t) => t !== null && c(t, "Object");
function E(t) {
return c(t, "Date");
}
function _(t) {
return c(t, "Number");
}
function R(t) {
return c(t, "AsyncFunction");
}
function $(t) {
return c(t, "Promise") && m(t) && h(t.then) && h(t.catch);
}
function L(t) {
return c(t, "String");
}
function F(t) {
return c(t, "Boolean");
}
function C(t) {
return t && Array.isArray(t);
}
const A = () => typeof window < "u", T = (t) => typeof window < "u" && c(t, "Window"), H = (t) => m(t) && !!t.tagName;
function b(t) {
return t === null;
}
function N(t) {
return D(t) || b(t);
}
const P = (t) => /^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(t), j = (t) => c(t, "Undefined"), v = (t, n, o = (e) => e.toUpperCase()) => {
const e = {};
for (let r in t)
Object.prototype.hasOwnProperty.call(t, r) && (e[o(r)] = t[r]);
return {
...n,
...e
};
};
function k(t) {
return m(t) ? Object.keys(t) : [];
}
function V(t) {
return m(t) ? Object.values(t) : [];
}
const y = "YYYY-MM-DD HH:mm";
function W(t) {
const n = a(t);
return n.isValid() ? n.hour() === 0 && n.minute() === 0 : !1;
}
function Y(t) {
const n = a(t);
return n.isValid() ? n.hour() === 24 && n.minute() === 0 : !1;
}
function B(t, n = 15) {
const o = a(t);
if (!o.isValid())
throw new Error("Invalid date format");
const e = o.unix(), r = n * 60, s = Math.round(e / r) * r;
return a.unix(s).format(y);
}
function J(t = 24) {
return Array.from({ length: t }, (n, o) => String(o).padStart(2, "0"));
}
function K(t = 1440, n = 15) {
const o = [];
for (let e = 0; e < t; e += n) {
const r = Math.floor(e / 60), s = e % 60;
o.push(`${String(r).padStart(2, "0")}:${String(s).padStart(2, "0")}`);
}
return o;
}
function q(t, n) {
const o = Math.abs(a(t).valueOf() - a(n).valueOf());
return Math.floor(o / (1e3 * 60 * 60 * 24));
}
function z(t, n) {
const r = a(t), s = a(n);
if (r.isValid() || s.isValid())
throw new Error("Invalid date format");
const d = Math.abs(s.valueOf() - r.valueOf()), l = Math.floor(d / 36e5), p = Math.floor(d % 36e5 / 6e4);
return { hours: l, minutes: p };
}
function G(t, n) {
(plus.downloader && plus.downloader.createDownload(
t,
{ filename: `download/${n}` },
// 保存到downloads目录
(e, r) => {
r === 200 ? plus.nativeUI.toast(`文件已保存到: ${e.filename}`) : (plus.nativeUI.alert(`下载失败,错误代码: ${r}`), I(t, n));
}
)).start();
}
function I(t, n = "") {
const o = document.createElement("a");
try {
o.href = t, o.download = n, o.style.display = "none", document.body.appendChild(o), o.click(), setTimeout(() => {
document.body.removeChild(o), t.startsWith("blob:") && window.URL.revokeObjectURL(t);
}, 100);
} catch {
alert("文件下载失败,请检查网络连接或尝试其他方式下载");
}
}
function Q(t, n = "xlsx") {
const o = t["content-disposition"];
let e = `${(/* @__PURE__ */ new Date()).valueOf()}.${n}`;
if (o) {
const r = o.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
r && r[1] && (e = r[1].replace(/['"]/g, ""), e.startsWith("UTF-8''") && (e = decodeURIComponent(e.replace("UTF-8''", ""))));
}
return decodeURIComponent(e);
}
const X = (t, n) => {
if (!t || !n) return "";
const o = new RegExp(`(^|\\?|&)${n}=([^&]*)(&|$)`), e = t.match(o);
return e ? decodeURIComponent(e[2]) : "";
};
function M(t, n = "children") {
return JSON.parse(JSON.stringify(t)).flatMap((e) => [
e,
...e[n] ? M(e.children) : []
]);
}
function Z(t = 15) {
if (t <= 0 || t > 60 || 60 % t !== 0)
throw new Error(
"intervalMinutes must be a positive divisor of 60 (e.g., 1, 5, 10, 15, 20, 30, 60)"
);
const n = [], o = 24, e = 60;
for (let r = 0; r < o; r++)
for (let s = 0; s < e; s += t) {
const d = String(r).padStart(2, "0"), l = String(s).padStart(2, "0");
n.push(`${d}:${l}`);
}
return n.push("24:00"), n;
}
function x() {
return ["testFunction"];
}
export {
z as calcDurationDate,
g as createNameSpace,
q as dayDifference,
Q as findFileNameByContentDisposition,
J as generateHourOptions,
K as generateTimeOptionsWithStep,
M as getFlatMenuList,
X as getParam,
c as is,
W as is0000,
Y as is2400,
C as isArray,
R as isAsyncFunction,
F as isBoolean,
A as isClient,
E as isDate,
S as isDef,
H as isElement,
h as isFunction,
P as isHexColor,
b as isNull,
N as isNullOrUnDef,
_ as isNumber,
m as isObject,
$ as isPromise,
L as isString,
D as isUnDef,
j as isUndefined,
T as isWindow,
B as mapToNearest15MinInterval,
G as nativeDownload,
k as objectKeys,
V as objectValues,
x as testFunction,
Z as timeRangeForm24Hour,
v as transformKeysAndMerge,
I as webDownload
};
//# sourceMappingURL=index.mjs.map