UNPKG

highly

Version:

> TODO: create docs

2 lines (1 loc) 8.18 kB
"use strict";function t(t,n,r,e){if(!e)return[];n<0&&(n=-n>e?0:e+n),r<0?r+=e:r>e&&(r=e),e=n>r?0:r-n>>>0,n>>>=0;let o=-1;const s=new Array(e);for(;++o<e;)s[o]=t[o+n];return s}function n(n){return r=>{const{length:e}=r;let o=0;for(;o<e&&n(r[o],o,r);)o++;return t(r,o,e,e)}}const r=void 0,e=Math,o=e.ceil,s=e.floor,i=e.trunc;function u(t){return"function"==typeof t&&/native\scode/.test(`${t}`)}const c=u(i)?i:function(t){return t<0?o(t):s(t)};function f(t,n){return(t=c(t))<0?n+t:t}function p(t,n,r,e){for(;r<e;r++)if(n(t[r],r,t))return r;return-1}function a(t,n){return r=>{const{length:e}=r;return e>0?(n=n?f(+n,e):0,p(r,t,n>0?n:0,e)):-1}}function x(t,n){return e=>{const{length:o}=e;if(o>0)for(let s=(n=n===r?o-1:f(+n,o))>=o?o-1:n;s>=0;s--)if(t(e[s],s,e))return s;return-1}}function l(t){return n=>{const{length:r}=n;for(let e=0;e<r;e++)t(n[e],e,n);return n}}const h=Object,g=h.prototype,y=g.toString;function m(t){return y.call(t).slice(8,-1)}const d=null;function A(t){return n=>n!=d&&m(n)===t}const w=A("Array"),b=Array.isArray,I=u(b)?b:w,k=Number,E=k.isNaN,N=u(E)?E:t=>t!=t;function S(t){return N(t)?N:n=>n===t}function v(t){return()=>t}const F=v(!1);function O(t){return t.length>0?n=>function(t,n){return function(t,n,r=0){return p(t,S(n),r,t.length)}(t,n,0)>-1}(t,n):F}function U(n){return r=>{const{length:e}=r;let o=0;for(;o<e&&n(r[o],o,r);o++);return o>0?t(r,0,o,e):[]}}const L=Promise;function P(t){return new L((n=>setTimeout(n,t)))}const W=v(!0);function j(t){return!!t}function M(t,n){return r=>t(n(r))}function B(t,n){return(...r)=>!!t(...r)&&!!n(...r)}function T(t,n){return(...r)=>!!t(...r)||!!n(...r)}function R(t){return(...n)=>!t(...n)}const D=e.pow;function $(t){return n=>n>t}function _(t){return n=>n>=t}function z(t){return n=>n<t}function C(t){return n=>n<=t}const G=h.entries,X=h.keys,Z=u(G)?G:function(t){return X(t).map((n=>[n,t[n]]))},q=h.hasOwn,H=g.hasOwnProperty,J=u(q)?q:function(t,n){return H.call(t,n)};function K(t){return t==d}function Q(t){return n=>{const r={};for(const e in n){const o=n[e];t(o,e,n)&&(r[e]=o)}return r}}function V(t){return n=>typeof n===t}const Y=V("string"),tt=h.values,nt=u(tt)?tt:function(t){return X(t).map((n=>t[n]))},rt=V("boolean"),et=A("Date"),ot=k.isFinite,st=V("number"),it=u(ot)?ot:function(t){return st(t)&&isFinite(t)},ut=V("function"),ct=k.isInteger,ft=u(ct)?ct:function(t){return it(t)&&s(t)===t},pt=A("Map"),at=A("WeakMap"),xt=S(d);function lt(t){return t!=d&&"object"==typeof t}const ht=h.getPrototypeOf,gt=h.toString(),yt=A("Promise"),mt=A("RegExp"),dt=k.isSafeInteger,At=k.MAX_SAFE_INTEGER,wt=st(At)?At:9007199254740991,bt=e.abs,It=u(dt)?dt:function(t){return ft(t)&&bt(t)<=wt},kt=A("Set"),Et=A("WeakSet"),Nt=V("symbol"),St=A("Uint8Array"),vt=A("Uint16Array"),Ft=A("Uint32Array"),Ot=A("Int8Array"),Ut=A("Int16Array"),Lt=A("Int32Array"),Pt=S(r);function Wt(t){return/^[\s\uFEFF\u00A0]$/.test(t)}function jt(t,n){const r=Y(t)?t?n=>t.indexOf(n)>=0:null:mt(t)?n=>t.test(n):ut(t)?t:null;return!0===n?r||F:r?T(r,Wt):Wt}function Mt(t,n){const r=jt(t,n);return t=>{const{length:n}=t;let e=n;for(;e>0&&r(t.charAt(e-1));)e--;return e>0?e<n?t.slice(0,e):t:""}}function Bt(t,n){const r=jt(t,n);return t=>{const{length:n}=t;let e=0;for(;e<n&&r(t.charAt(e));)e++;return e>0?t.slice(e):t}}exports.F=F,exports.T=W,exports.add=function(t,n){if(n){const n=+t;return t=>+t+n}return n=>n+t},exports.always=v,exports.and=B,exports.between=function(t,n,r="[)"){switch(r){case"()":return B($(t),z(n));case"(]":return B($(t),C(n));case"[]":return B(_(t),C(n))}return B(_(t),z(n))},exports.clamp=function(t,n){return r=>r<t?t:r>n?n:r},exports.div=function(t){return n=>n/t},exports.drop=function(t){if(t<0)throw new Error("`n` must be a nonnegative integer");return n(((n,r)=>r<t))},exports.dropLast=function(n){if(n<0)throw new Error("`n` must be a nonnegative integer");return r=>{const{length:e}=r;return n<e?t(r,0,e-n,e):[]}},exports.dropLastWhile=function(n){return r=>{const{length:e}=r;let o=e-1;for(;o>=0&&n(r[o],o,r);)o--;return t(r,o,e,e)}},exports.dropWhile=n,exports.entries=Z,exports.every=function(t){return n=>{let r=-1;const{length:e}=n;for(;++r<e;)if(!t(n[r],r,n))return!1;return!0}},exports.filter=function(t){return n=>n.filter(t)},exports.find=function(t,n){const e=a(t,n);return t=>{const n=e(t);return n>-1?t[n]:r}},exports.findIndex=a,exports.findLast=function(t,n){const e=x(t,n);return t=>{const n=e(t);return n>-1?t[n]:r}},exports.findLastIndex=x,exports.forEach=l,exports.forEachRight=function(t){return n=>{let{length:r}=n;for(;r--;)t(n[r],r,n);return n}},exports.forIn=function(t){return n=>{if(n!=d)for(const r in n)t(n[r],r,n);return n}},exports.forOwn=function(t){return n=>{for(const r in n)J(n,r)&&t(n[r],r,n);return n}},exports.fork=function(t){return n=>{const r=[],e=[],{length:o}=n;for(let s=0;s<o;s++){const o=n[s];t(o,s)?r.push(o):e.push(o)}return[r,e]}},exports.groupBy=function(t){return n=>{const r={},{length:e}=n;for(let o=0;o<e;o++){const e=n[o],s=t(e,o,n),i=r[s];I(i)?i.push(e):r[s]=[e]}return r}},exports.gt=$,exports.gte=_,exports.identity=function(t){return t},exports.inArray=O,exports.indexOf=function(t,n=0){return a(S(t),n)},exports.is=S,exports.isArray=I,exports.isBoolean=rt,exports.isDate=et,exports.isFalsy=function(t){return!t},exports.isFinite=it,exports.isFunction=ut,exports.isInt16Array=Ut,exports.isInt32Array=Lt,exports.isInt8Array=Ot,exports.isInteger=ft,exports.isMap=pt,exports.isNaN=N,exports.isNative=u,exports.isNil=K,exports.isNull=xt,exports.isNumber=st,exports.isNumeric=function(t){const n=typeof t;return"string"===n?!!/^[+-]?\.?\d/.test(t)&&t-t==0:"number"===n&&t-t==0},exports.isObjectLike=lt,exports.isPlainObject=function(t){if(!lt(t)||"Object"!==((n=t)===r?"Undefined":n===d?"Null":m(n)))return!1;var n;const e=ht(t);if(e===d)return!0;const o=J(e,"constructor")?e.constructor:d;return!!o&&ut(o)&&o.toString()===gt},exports.isPrimitive=function(t){const n=typeof t;return"object"===n?t===d:"function"!==n},exports.isPromise=yt,exports.isPromiseLike=function(t){return(lt(t)||ut(t))&&ut(t.then)},exports.isRegExp=mt,exports.isSafeInteger=It,exports.isScalar=function(t){const n=typeof t;return"number"===n||"string"===n||"boolean"===n},exports.isSet=kt,exports.isString=Y,exports.isSymbol=Nt,exports.isTruthy=j,exports.isTypedArray=function(t){return t!=d&&/^(?:Uint|Int|Float|BigInt|BigUint)\d\d?[a-zA-Z]*Array/.test(m(t))},exports.isUint16Array=vt,exports.isUint32Array=Ft,exports.isUint8Array=St,exports.isUndefined=Pt,exports.isWeakMap=at,exports.isWeakSet=Et,exports.keys=function(t){return K(t)?[]:X(t)},exports.lt=z,exports.lte=C,exports.map=function(t,n){return n?n=>n.map(t):n=>{const r=[],{length:e}=n;let o=0;for(;o<e;)r[o]=t(n[o],o,n),o++;return r}},exports.mul=function(t){return n=>n*t},exports.noop=function(){},exports.not=R,exports.o=M,exports.omit=function(t){return Q((t=I(t)?t:Y(t)?[t]:[]).length>0?R(O(t)):W)},exports.omitBy=function(t){return Q(R(t))},exports.or=T,exports.pick=function(t){return n=>{const r={};return n!=d&&(n=Object(n),l((t=>{t in n&&(r[t]=n[t])}))(t)),r}},exports.pickBy=Q,exports.pow=function(t){return n=>D(n,t)},exports.retry=function(t,n){const r=n.maxAttempts||0,e=+n.delayMs||0,o=n.canNext?n.canNext:W,s=n.canDone||j;return async function(...n){const i=new Error(`Could not complete function within ${r} attempts`);for(let u=0;u<r;++u){let r=null;try{const r=await t.apply(this,n);if(s.call(this,r,u))return r}catch(t){r=t}if(!o.call(this,r,u))throw r||i;e&&await P(e)}throw i}},exports.sleep=P,exports.some=function(t,n){return n?n=>n.some(t):n=>{const{length:r}=n;let e=0;for(;e<r;){if(t(n[e],e,n))return!0;e++}return!1}},exports.sub=function(t){return n=>n-t},exports.take=function(t){if(t<0)throw new Error("`n` must be a nonnegative integer");return U(((n,r)=>r<t))},exports.takeLast=function(n){if(n<0)throw new Error("`n` must be a nonnegative integer");return r=>{const{length:e}=r;return t(r,n>=e?0:e-n,e,e)}},exports.takeLastWhile=function(n){return r=>{const{length:e}=r;let o=r.length-1;for(;o>=0&&n(r[o],o,r);o--);return t(r,o+1,e,e)}},exports.takeWhile=U,exports.trim=function(t,n){const r=jt(t,n),e=Bt(r,!0);return M(Mt(r,!0),e)},exports.trimEnd=Mt,exports.trimStart=Bt,exports.values=nt;