@resolid/utils
Version:
Common utils
1 lines • 1.96 kB
JavaScript
var y=n=>Array.isArray(n)?n:[n];var k=process.env.NODE_ENV!=="production",A=typeof window<"u",E=n=>typeof n=="boolean",m=n=>typeof n=="number",T=n=>typeof n=="string",d=n=>n!==null&&typeof n=="object",O=n=>typeof n>"u",h=n=>n==null,f=n=>typeof n=="function",D=n=>n instanceof Date||Object.prototype.toString.call(n)==="[object Date]",j=n=>h(n)?true:m(n)?n===0:T(n)?n.trim()=="":Array.isArray(n)?n.length===0:d(n)?Object.keys(n).length===0:false,P=n=>n instanceof Promise;var C=()=>{},F=n=>new Promise(e=>setTimeout(e,n)),L=n=>()=>n,N=n=>n.then(e=>[null,e]).catch(e=>[e,void 0]);function S(n,...e){return f(n)?n(...e):n}var K=(n,[e,t])=>Math.min(t,Math.max(e,n)),B=(n,e)=>n>e?[]:Array.from({length:e-n+1},(t,r)=>n+r);var R=(n,e)=>e.reduce((t,r)=>(delete t[r],t),{...n});var z=n=>n?n.charAt(0).toUpperCase()+n.slice(1):"",g=(n,e,t=true)=>n.length<e.length?false:t?n.toLowerCase().startsWith(e.toLowerCase()):n.startsWith(e),x=(n,e,t=true)=>n.length<e.length?false:t?n.toLowerCase().endsWith(e.toLowerCase()):n.endsWith(e),I=(n,e,t=true)=>g(n,e,t)?n.slice(e.length,n.length):n,q=(n,e,t=true)=>x(n,e,t)?n.slice(0,n.length-e.length):n;var w=(n,e=0,{start:t=true,middle:r=true,once:o=false}={})=>{let i=t,u=0,l,c=false,s=function(...a){if(c)return;let p=Date.now()-u;u=Date.now(),t&&r&&p>=e&&(i=true),i?(i=false,n.apply(this,a),o&&s.cancel()):(r&&p<e||!r)&&(clearTimeout(l),l=setTimeout(()=>{u=Date.now(),n.apply(this,a),o&&s.cancel();},r?e-p:e));};return s.cancel=()=>{clearTimeout(l),c=true;},s},H=(n,e=0,{start:t=false,middle:r=false,once:o=false}={})=>w(n,e,{start:t,middle:r,once:o});export{k as __DEV__,L as always,y as asArray,z as capitalize,K as clamp,H as debounce,x as endsWith,E as isBoolean,A as isBrowser,D as isDate,j as isEmpty,f as isFunction,h as isNullish,m as isNumber,d as isObject,P as isPromise,T as isString,O as isUndefined,C as noop,R as omit,B as range,S as runIf,F as sleep,g as startsWith,w as throttle,N as to,q as trimEnd,I as trimStart};