UNPKG

vite-uni-dev-tool

Version:

vite-uni-dev-tool, debug, uni-app, 一处编写,到处调试

128 lines (127 loc) 3.35 kB
import { isString as g, isBoolean as y, isFunction as m, isNil as B, isObject as p } from "./language.js"; function h(t, i, e) { if (t == null || typeof i != "string") return; const n = i.replace(/\[(\d+)\]/g, ".$1").split(".").filter((s) => s !== ""); if (n.length === 0) return; let r = t; const f = n.length - 1; for (let s = 0; s < f; s++) { const c = n[s]; if (!r[c]) { const u = n[s + 1]; r[c] = /^\d+$/.test(u) ? [] : {}; } r = r[c]; } r[n[f]] = e; } function x(t, i, e) { if (t == null || typeof i != "string") return e; const n = i.replace(/\[(\d+)\]/g, ".$1").split(".").filter((f) => f !== ""); let r = t; for (const f of n) { if (r == null) return e; r = r[f]; } return r !== void 0 ? r : e; } function a(t) { var n; if (t = $(t), t == null) return 0; const i = typeof t; if (i === "boolean") return 4; if (i === "number") return 8; if (i === "string") return t.length * 2; if (i === "symbol" || t instanceof Date) return 8; if (t instanceof RegExp) return a(t.source) + a(t.flags); let e = 0; if (e += 24, Array.isArray(t)) { e += 4; for (const r of t) e += 8, e += a(r); } else for (const r in t) (n = t == null ? void 0 : t.hasOwnProperty) != null && n.call(t, r) && (e += r.length * 2, e += 8, e += a(t[r])); return e; } function S(t, i = {}) { const { precision: e = 2, useBinary: n = !0, includeUnit: r = !0 } = i; if (t === 0) return r ? "0 Bytes" : "0"; const f = n ? ["B", "KiB", "MiB", "GiB", "TiB", "PiB"] : ["B", "KB", "MB", "GB", "TB", "PB"], s = n ? 1024 : 1e3; let c = 0; for (; t >= s && c < f.length - 1; ) t /= s, c++; const u = t.toFixed(e); return r ? `${u} ${f[c]}` : u; } function l(t, i = { maxDepth: 10, visited: /* @__PURE__ */ new WeakMap() }) { const { maxDepth: e, visited: n } = i; return t === null || typeof t != "object" ? JSON.stringify(t) : n.has(t) ? "[Circular]" : (n.set(t, !0), t instanceof Date ? `"${t.toISOString()}"` : t instanceof RegExp ? `/^${t.source}$/${t.flags}` : e <= 0 ? typeof t == "object" ? "{}" : "[]" : Array.isArray(t) ? `[${t.map( (c) => l(c, { maxDepth: e - 1, visited: n }) ).join(", ")}]` : `{${Object.keys(t).map((s) => { const c = l(t[s], { maxDepth: e - 1, visited: n }); return `"${s}": ${c}`; }).join(", ")}}`); } function $(t, i = 6) { const e = /* @__PURE__ */ new WeakMap(); function n(r, f, s = []) { if (g(r)) return `${r}`; if (y(r)) return `${r}`; if (m(r)) return "f(...) { ... }"; if (B(r)) return `${r}`; if (!p(r)) return r; if (f <= 0) return "[MaxDepth]"; if (e.has(r)) return `[Circular: ${e.get(r).join(".")}]`; if (e.set(r, [...s]), Array.isArray(r)) return r.map( (u, o) => n(u, f - 1, [...s, String(o)]) ); const c = {}; for (const [u, o] of Object.entries(r)) c[u] = n(o, f - 1, [...s, u]); return c; } return n(t, i); } function k(t, i) { if (!p(t)) return {}; const e = {}; for (const n of i) n in t && (e[n] = t[n]); return e; } export { a as calculateObjectSize, S as formatStorageSize, x as getValueByPath, $ as parseValue, k as pick, l as serializeCircular, h as setValueByPath };