UNPKG

@acrool/js-utils

Version:

Common javascript utils methods for project development

169 lines (168 loc) 4.61 kB
import { r as E } from "../regPattern-7f640e9d.js"; function w(e, t) { const r = { isZero: (t == null ? void 0 : t.isZero) ?? !0, isFalse: (t == null ? void 0 : t.isFalse) ?? !0 }; return e == null || r.isFalse && (e === !1 || e === "false") || r.isZero && (e === 0 || e === "0") || !(e instanceof Date) && typeof e == "object" && Object.keys(e).length === 0 || typeof e == "string" && e.trim().length === 0; } function D(e, t) { const r = { isZero: (t == null ? void 0 : t.isZero) ?? !0, isFalse: (t == null ? void 0 : t.isFalse) ?? !0 }; return !w(e, r); } function M(e) { const t = new RegExp(E.date); let r = !0; const s = t.exec(e); if (s !== null) { let n; n = parseFloat(s[1]), (n <= 0 || n > 9999) && (r = !1), n = parseFloat(s[2]), (n <= 0 || n > 12) && (r = !1), n = parseFloat(s[3]), (n <= 0 || n > 31) && (r = !1); } else r = !1; return r; } function P(e) { return e === null || e === "" ? !1 : !isNaN(e); } function A(e) { return !!(new RegExp(E.ipAddress).test(e) && RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256); } function B(e) { return !!(new RegExp(/(\d+)\.(\d+)\.(\d+)\.(\d+)/g).test(e) && RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256); } function Z(e) { try { const t = JSON.parse(e); if (t && typeof t == "object" && t !== null) return !0; } catch { return !1; } return !1; } const R = (e) => (t, r) => { const s = t == null ? void 0 : t.map((o) => o[e]).join("-"), n = r == null ? void 0 : r.map((o) => o[e]).join("-"); return s === n; }, q = R("id"), I = R("code"); function z(e, t) { if (e.length !== t.length) return !1; const r = /* @__PURE__ */ new Map(); for (const s of e) r.set(s, (r.get(s) || 0) + 1); for (const s of t) { if (!r.has(s)) return !1; const n = r.get(s) - 1; n === 0 ? r.delete(s) : r.set(s, n); } return r.size === 0; } function m(e, t) { const r = []; for (const s in e) t(e, s) && r.push(s); return r.concat( Object.getOwnPropertySymbols(e).filter( (s) => Object.getOwnPropertyDescriptor(e, s).enumerable ) ); } function N(e, t) { return Object.prototype.hasOwnProperty.call(e, t); } function F(e, t) { return N(e, t) && e[t] !== void 0; } function d(e) { return e !== null && typeof e == "object" && typeof e.nodeType == "number" && typeof e.nodeName == "string" && typeof e.isEqualNode == "function"; } function $(e, t) { return Object.prototype.toString.apply(t) === "[object " + e + "]"; } function j(e) { return !!e && $("Function", e.asymmetricMatch); } function h(e, t) { const r = j(e), s = j(t); if (!(r && s)) { if (r) return e.asymmetricMatch(t); if (s) return t.asymmetricMatch(e); } } const x = (e, t, r, s, n, o) => { n = n || []; let u = !0; const y = h(e, t); if (y !== void 0) return y; for (let a = 0; a < n.length; a++) { const p = n[a](e, t); if (p !== void 0) return p; } if (e instanceof Error && t instanceof Error) return e.message == t.message; if (Object.is(e, t)) return !0; if (e === null || t === null) return e === t; const l = Object.prototype.toString.call(e); if (l != Object.prototype.toString.call(t)) return !1; switch (l) { case "[object Boolean]": case "[object String]": case "[object Number]": return typeof e != typeof t ? !1 : typeof e != "object" && typeof t != "object" ? Object.is(e, t) : Object.is(e.valueOf(), t.valueOf()); case "[object Date]": return +e == +t; case "[object RegExp]": return e.source === t.source && e.flags === t.flags; } if (typeof e != "object" || typeof t != "object") return !1; if (d(e) && d(t)) return e.isEqualNode(t); let f = r.length; for (; f--; ) { if (r[f] === e) return s[f] === t; if (s[f] === t) return !1; } if (r.push(e), s.push(t), l == "[object Array]" && e.length !== t.length) return !1; const g = m(e, o); let i, c = g.length; if (m(t, o).length !== c) return !1; for (; c--; ) if (i = g[c], u = o(t, i) && x(e[i], t[i], r, s, n, o), !u) return !1; return r.pop(), s.pop(), u; }; function J(e, t, r, s) { const n = (s == null ? void 0 : s.customTesters) || []; return x(e, t, [], [], n, r ? N : F); } export { z as arrayCompose, J as deepCompare, M as isDate, w as isEmpty, A as isIP, B as isIPUrl, Z as isJSON, D as isNotEmpty, P as isNumber, R as objsComposeBy, I as objsComposeByCode, q as objsComposeById, E as regPattern };