UNPKG

@acrool/js-utils

Version:

Common javascript utils methods for project development

112 lines (111 loc) 2.6 kB
function s(n, e) { const t = e && typeof e == "object" ? { ...e } : e; return n ? [t].concat(n.slice(0)) : [t]; } function g(n, e) { const t = e && typeof e == "object" ? { ...e } : e; return n ? n.slice(0).concat(t) : [t]; } function p(n, e, t) { const o = t && typeof t == "object" ? { ...t } : t; return n ? [...n.slice(0, e), o, ...n.slice(e)] : [o]; } function l(n, e, t) { if (!n || e === t) return n; const o = [...n], u = o[e]; return o.splice(e, 1), o.splice(t, 0, u), o; } function h(n, e) { if (!n) return n; const t = n.findIndex(e); return t === -1 ? n : i(n, t); } function m(n, e) { if (!n) return n; const t = n.findIndex(e.finder); return t === -1 ? n : f(n, t, e.updater); } function i(n, e) { return !n || e === -1 || e > n.length - 1 ? n : [...n.slice(0, e), ...n.slice(e + 1)]; } function f(n, e, t) { if (e === -1 || !n || e > n.length - 1) return n; const o = { ...n[e] }; t(o); const u = [...n]; return u[e] = o, u; } function A(n, e) { if (!n) return n; const t = /* @__PURE__ */ new Set(), o = new Array(); for (const u of n) { const r = e ? e(u) : u; t.has(r) || (t.add(r), o.push(u)); } return o; } function d(n, e) { return n ? n.join(e) : ""; } function I(n) { return n == null ? void 0 : n[0]; } function w(n, e) { if (!n || e <= 0) return; const t = Math.ceil(n.length / e); return Array.from({ length: t }, (o, u) => n.slice(u * e, (u + 1) * e)); } function S(n, e) { return n.reduce((t, o) => { const u = e(o); return t[u] || (t[u] = []), t[u].push(o), t; }, {}); } function b(n, e) { const t = {}; return n.forEach((o) => { const { groupKey: u, groupData: r, child: c } = e(o); t[u] || (t[u] = { ...r, children: [] }), t[u].children.push(c); }), Object.keys(t).map((o) => t[o]); } function j(n, e) { const t = [...n]; return t.sort(e), t; } function B(n, e = "ASC") { return function(t, o) { const u = n(t), r = n(o); return u < r ? e === "ASC" ? -1 : 1 : u > r ? e === "ASC" ? 1 : -1 : 0; }; } const k = (n, e = "skeleton_") => Array.from({ length: n }).map((t, o) => `${e}${o}`); function v(n) { return (e) => { const o = (n.indexOf(e) + 1) % n.length; return n[o]; }; } export { I as arrayFirst, d as arrayJoin, w as arraySplit, B as generateSortByProperty, k as generatorArray, v as generatorArrayToggle, S as groupBy, b as groupTreeBy, p as insert, l as move, s as pull, g as push, i as removeByIndex, h as removeFind, j as sort, A as unique, f as updateByIndex, m as updateFind };