rhodash
Version:
A deadly simple alternative to lodash
7 lines (6 loc) • 3.26 kB
JavaScript
/**
* @license
* rhodash v2.2.0
* Released under the MIT License.
*/
var rhodash=function(i){"use strict";function m(n,e){return n.filter(t=>!e.includes(t))}function y(n,e){if(e<=0)return[[]];const t=[];for(let o=0;o<n.length;o++)o%e===0?t.push([n[o]]):t[t.length-1].push(n[o]);return t}function f(n){if(!n)return n;if(Array.isArray(n))return n.map(f);if(n instanceof Date)return new Date(n);if(n instanceof Map){const e=new Map;for(const[t,o]of n.entries())e.set(t,f(o));return e}if(n instanceof Set){const e=new Set;for(const t of n.values())e.add(f(t));return e}if(n instanceof Buffer)return Buffer.from(n);if(typeof n=="object"){const e={};for(const t in n)e[t]=f(n[t]);return e}return n}function h(n,e){let t=0;for(const o of n)e(o)&&(t+=1);return t}function b(n){return new Promise(e=>setTimeout(e,n))}function d(n,e){const t={};for(const o of n){const r=e(o);t[r]===void 0?t[r]=[o]:t[r].push(o)}return t}function g(n){return n[n.length-1]}function p(n,e){const t={};for(const o in n)n[o]!==e[o]&&(t[o]=n[o]);return t}function a(n,e,t){const o=e.split(/\[|\]|\./).filter(Boolean);let r=n;for(let c=0;c<o.length-1;c++){const s=l(o[c]);(r[s]===void 0||!w(r[s]))&&(r[s]=k(o[c+1])?[]:{}),r=r[s]}const u=l(o[o.length-1]);return u!==void 0&&(r[u]=t),n}function k(n){return/^\d+$/.test(n)}function l(n){return n==='""'||n==="''"?"":n}function w(n){return n!==null&&typeof n=="object"}function B(n,e){const t={};for(const o in n)e.includes(o)||(t[o]=n[o]);return t}function S(n,e){const t=[],o=[];for(const r of n)e(r)?t.push(r):o.push(r);return[t,o]}function D(n,e){const t={};for(const o of e)t[o]=n[o];return t}function E(n,e=Boolean){const t={};for(const o in n)e(n[o])&&(t[o]=n[o]);return t}function z(n,e,t){if(typeof n!="number")throw Error("start must be a number");if(typeof e<"u"&&typeof e!="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");e===void 0&&(e=n,n=0),t===void 0&&(t=n<e?1:-1);const o=[];for(let r=n;n<e?r<e:r>e;r+=t)o.push(r);return o}function j(n){let e=0;for(const t of n)e+=t;return e}function O(n,e){let t=0;const o=typeof e=="function"?e:r=>r[e];for(const r of n)t+=o(r)||0;return t}function q(n,e,t){if(typeof n!="number")throw Error("start must be a number");if(typeof e<"u"&&typeof e!="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");e===void 0&&(e=n,n=0),t===void 0&&(t=n<e?1:-1);const o=[];for(let r=n;n<e?r<=e:r>=e;r+=t)o.push(r);return o}function M(n){return[...new Set(n)]}function A(n,e){const t=new Set,o=[];for(const r of n){const u=e(r);t.has(u)||(o.push(r),t.add(u))}return o}function K(...n){const e=[];for(let t=0;t<n[0].length;t++)e.push(n.map(o=>o[t]));return e}function L(n,e){const t={};for(let o=0;o<n.length;o++)t[n[o]]=e[o];return t}return i.arrayDifference=m,i.chunk=y,i.cloneDeep=f,i.countBy=h,i.delay=b,i.groupBy=d,i.last=g,i.objectDifference=p,i.objectSet=a,i.omit=B,i.partition=S,i.pick=D,i.pickBy=E,i.range=z,i.sum=j,i.sumBy=O,i.toRange=q,i.uniq=M,i.uniqBy=A,i.zip=K,i.zipObject=L,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),i}({});