UNPKG

4.06 kBJavaScriptView Raw
1!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).MinDash={})}(this,(function(n){"use strict";const t=Object.prototype.toString,e=Object.prototype.hasOwnProperty;function r(n){return void 0===n}function o(n){return void 0!==n}function u(n){return null==n}function i(n){return"[object Array]"===t.call(n)}function c(n){return"[object Object]"===t.call(n)}function f(n){const e=t.call(n);return"[object Function]"===e||"[object AsyncFunction]"===e||"[object GeneratorFunction]"===e||"[object AsyncGeneratorFunction]"===e||"[object Proxy]"===e}function l(n){if(!i(n))throw new Error("must supply array")}function s(n,t){return e.call(n,t)}function a(n,t){const e=w(t);let r;return p(n,(function(n,t){if(e(n,t))return r=n,!1})),r}function p(n,t){let e,o;if(r(n))return;const u=i(n)?O:v;for(let r in n)if(s(n,r)&&(e=n[r],o=t(e,u(r)),!1===o))return e}function y(n,t,e){return p(n,(function(n,r){e=t(e,n,r)})),e}function d(n,t){return!!y(n,(function(n,e,r){return n&&t(e,r)}),!0)}function b(n,t){let e=[];return p(n,(function(n,r){e.push(t(n,r))})),e}function h(n){return n&&Object.keys(n)||[]}function g(n,t,e={}){return t=_(t),p(n,(function(n){let r=t(n)||"_",o=e[r];o||(o=e[r]=[]),o.push(n)})),e}function j(n,...t){n=_(n);let e={};return p(t,(t=>g(t,n,e))),b(e,(function(n,t){return n[0]}))}const m=j;function _(n){return f(n)?n:t=>t[n]}function w(n){return f(n)?n:t=>t===n}function v(n){return n}function O(n){return Number(n)}n.assign=function(n,...t){return Object.assign(n,...t)},n.bind=function(n,t){return n.bind(t)},n.debounce=function(n,t){let e,r,o,u;function i(e){let i=Date.now(),l=e?0:u+t-i;if(l>0)return c(l);n.apply(o,r),f()}function c(n){e=setTimeout(i,n)}function f(){e&&clearTimeout(e),e=u=r=o=void 0}function l(...n){u=Date.now(),r=n,o=this,e||c(t)}return l.flush=function(){e&&i(!0),f()},l.cancel=f,l},n.ensureArray=l,n.every=d,n.filter=function(n,t){const e=w(t);let r=[];return p(n,(function(n,t){e(n,t)&&r.push(n)})),r},n.find=a,n.findIndex=function(n,t){const e=w(t);let r=i(n)?-1:void 0;return p(n,(function(n,t){if(e(n,t))return r=t,!1})),r},n.flatten=function(n){return Array.prototype.concat.apply([],n)},n.forEach=p,n.get=function(n,t,e){let o=n;return p(t,(function(n){if(u(o))return o=void 0,!1;o=o[n]})),r(o)?e:o},n.groupBy=g,n.has=s,n.isArray=i,n.isDefined=o,n.isFunction=f,n.isNil=u,n.isNumber=function(n){return"[object Number]"===t.call(n)},n.isObject=c,n.isString=function(n){return"[object String]"===t.call(n)},n.isUndefined=r,n.keys=h,n.map=b,n.matchPattern=function(n){return function(t){return d(n,(function(n,e){return t[e]===n}))}},n.merge=function n(t,...e){return e.length?(p(e,(function(e){e&&c(e)&&p(e,(function(e,r){if("__proto__"===r)return;let o=t[r];c(e)?(c(o)||(o={}),t[r]=n(o,e)):t[r]=e}))})),t):t},n.omit=function(n,t){let e={};return p(Object(n),(function(n,r){-1===t.indexOf(r)&&(e[r]=n)})),e},n.pick=function(n,t){let e={},r=Object(n);return p(t,(function(t){t in r&&(e[t]=n[t])})),e},n.reduce=y,n.set=function(n,t,e){let i=n;return p(t,(function(n,c){if("number"!=typeof n&&"string"!=typeof n)throw new Error("illegal key type: "+typeof n+". Key should be of type number or string.");if("constructor"===n)throw new Error("illegal key: constructor");if("__proto__"===n)throw new Error("illegal key: __proto__");let f=t[c+1],l=i[n];o(f)&&u(l)&&(l=i[n]=isNaN(+f)?{}:[]),r(f)?r(e)?delete i[n]:i[n]=e:i=l})),n},n.size=function(n){return h(n).length},n.some=function(n,t){return!!a(n,t)},n.sortBy=function(n,t){t=_(t);let e=[];return p(n,(function(n,r){let o=t(n,r),u={d:o,v:n};for(var i=0;i<e.length;i++){let{d:n}=e[i];if(o<n)return void e.splice(i,0,u)}e.push(u)})),b(e,(n=>n.v))},n.throttle=function(n,t){let e=!1;return function(...r){e||(n(...r),e=!0,setTimeout((()=>{e=!1}),t))}},n.unionBy=m,n.uniqueBy=j,n.values=function(n){return b(n,(n=>n))},n.without=function(n,t){if(r(n))return[];l(n);const e=w(t);return n.filter((function(n,t){return!e(n,t)}))}}));