UNPKG

@naverpay/hidash

Version:

improved lodash

50 lines (49 loc) 1.18 kB
import { isFunction as p } from "../isFunction.mjs"; import { isPlainObject as e } from "../isPlainObject.mjs"; import { isArrayLike as y } from "./array.mjs"; function a(r, n) { if (!e(r) || !e(n)) return !1; const u = r, i = n, t = Object.keys(i), f = t.length; for (let o = 0; o < f; o++) { const l = t[o], s = i[l], c = u[l]; if (c !== s && (s == null || typeof s != "object" || !a(c, s))) return !1; } return !0; } function j(r) { if (r == null) return function(n) { return n; }; if (typeof r == "function") return r; if (y(r) && !p(r)) { const [n, u] = r; if (typeof n == "string" && !n.includes(".")) return function(t) { return t == null ? !1 : t[n] === u; }; const i = typeof n == "string" ? n.split(".") : [n]; return function(t) { if (t == null) return !1; let f = t; for (const o of i) { if (f == null) return !1; f = f[o]; } return f === u; }; } if (e(r) && !p(r)) return function(n) { return e(n) ? a(n, r) : !1; }; throw new Error("Invalid iteratee"); } export { j as baseIteratee };