UNPKG

rhodash

Version:

A deadly simple alternative to lodash

199 lines (198 loc) 4.16 kB
function p(n, o) { return n.filter((t) => !o.includes(t)); } function y(n, o) { if (o <= 0) return [[]]; const t = []; for (let r = 0; r < n.length; r++) r % o === 0 ? t.push([n[r]]) : t[t.length - 1].push(n[r]); return t; } function c(n) { if (!n) return n; if (Array.isArray(n)) return n.map(c); if (n instanceof Date) return new Date(n); if (n instanceof Map) { const o = /* @__PURE__ */ new Map(); for (const [t, r] of n.entries()) o.set(t, c(r)); return o; } if (n instanceof Set) { const o = /* @__PURE__ */ new Set(); for (const t of n.values()) o.add(c(t)); return o; } if (n instanceof Buffer) return Buffer.from(n); if (typeof n == "object") { const o = {}; for (const t in n) o[t] = c(n[t]); return o; } return n; } function h(n, o) { let t = 0; for (const r of n) o(r) && (t += 1); return t; } function b(n) { return new Promise((o) => setTimeout(o, n)); } function d(n, o) { const t = {}; for (const r of n) { const e = o(r); t[e] === void 0 ? t[e] = [r] : t[e].push(r); } return t; } function w(n) { return n[n.length - 1]; } function k(n, o) { const t = {}; for (const r in n) n[r] !== o[r] && (t[r] = n[r]); return t; } function g(n, o, t) { const r = o.split(/\[|\]|\./).filter(Boolean); let e = n; for (let i = 0; i < r.length - 1; i++) { const u = s(r[i]); (e[u] === void 0 || !l(e[u])) && (e[u] = m(r[i + 1]) ? [] : {}), e = e[u]; } const f = s(r[r.length - 1]); return f !== void 0 && (e[f] = t), n; } function m(n) { return /^\d+$/.test(n); } function s(n) { return n === '""' || n === "''" ? "" : n; } function l(n) { return n !== null && typeof n == "object"; } function B(n, o) { const t = {}; for (const r in n) o.includes(r) || (t[r] = n[r]); return t; } function E(n, o) { const t = [], r = []; for (const e of n) o(e) ? t.push(e) : r.push(e); return [t, r]; } function S(n, o) { const t = {}; for (const r of o) t[r] = n[r]; return t; } function D(n, o = Boolean) { const t = {}; for (const r in n) o(n[r]) && (t[r] = n[r]); return t; } function z(n, o, t) { if (typeof n != "number") throw Error("start must be a number"); if (typeof o < "u" && typeof o != "number") throw Error("end must be a number"); if (typeof t < "u" && typeof t != "number") throw Error("step must be a number"); if (t === 0) throw Error("step cannot be zero"); o === void 0 && (o = n, n = 0), t === void 0 && (t = n < o ? 1 : -1); const r = []; for (let e = n; n < o ? e < o : e > o; e += t) r.push(e); return r; } function A(n) { let o = 0; for (const t of n) o += t; return o; } function K(n, o) { let t = 0; const r = typeof o == "function" ? o : (e) => e[o]; for (const e of n) t += r(e) || 0; return t; } function O(n, o, t) { if (typeof n != "number") throw Error("start must be a number"); if (typeof o < "u" && typeof o != "number") throw Error("end must be a number"); if (typeof t < "u" && typeof t != "number") throw Error("step must be a number"); if (t === 0) throw Error("step cannot be zero"); o === void 0 && (o = n, n = 0), t === void 0 && (t = n < o ? 1 : -1); const r = []; for (let e = n; n < o ? e <= o : e >= o; e += t) r.push(e); return r; } function a(n) { return [...new Set(n)]; } function q(n, o) { const t = /* @__PURE__ */ new Set(), r = []; for (const e of n) { const f = o(e); t.has(f) || (r.push(e), t.add(f)); } return r; } function L(...n) { const o = []; for (let t = 0; t < n[0].length; t++) o.push(n.map((r) => r[t])); return o; } function M(n, o) { const t = {}; for (let r = 0; r < n.length; r++) t[n[r]] = o[r]; return t; } export { p as arrayDifference, y as chunk, c as cloneDeep, h as countBy, b as delay, d as groupBy, w as last, k as objectDifference, g as objectSet, B as omit, E as partition, S as pick, D as pickBy, z as range, A as sum, K as sumBy, O as toRange, a as uniq, q as uniqBy, L as zip, M as zipObject };