@motojs_sdk/utils
Version:
2 lines (1 loc) • 2.12 kB
JavaScript
const d=(e,t)=>{try{e()}catch(n){console.error("\u51FA\u9519\u5566\uFF5E\uFF01",n),t&&t(n)}},h=(e,t,n,r=!1)=>{e.addEventListener(t,n,r)},m=(e,t,n,r=!1)=>{e.removeEventListener(t,n,r)},y=()=>typeof document=="undefined"||document.location==null?"":document.location.href,l=()=>Date.now(),w=(e,t)=>typeof e=="string"?e.slice(0,t)+(e.length>t?`;slice the first ${t} characters`:""):"",u=e=>{const t=new Set,n=JSON.stringify(e,function(r,o){return o in File?"File":t.has(o)?"Loop":(typeof o=="object"&&t.add(o),o)});return t.clear(),n},S=e=>typeof e=="object"&&e!==null?u(e):String(e),F=(e,t,n,r)=>{if(e&&(Reflect.has(e,t)||r)){const o=e[t],i=n(o);typeof i=="function"&&(e[t]=i)}},b=e=>{const t=e.tagName.toLowerCase();if(t==="body")return"";let n=e.classList.value;n=n!==""?` class="${n}"`:"";const r=e.id?` id="${e.id}"`:"",o=e.innerText;return`<${t}${r}${n!==""?n:""}>${o}</${t}>`},$=()=>{const e=window.chrome,t=e&&e.app&&e.app.runtime,n="history"in window&&!!window.history.pushState&&!!window.history.replaceState;return!t&&n},L=(e,t)=>Reflect.has(e,t)||t in e,v=e=>t=>{let n="",r=t;for(;r--;)n+=e[Math.random()*e.length|0];return n},f=v("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),p=(e,t)=>t===0?e:p(t,e%t),T=(...e)=>{if(!(e!=null&&e.length))return 1;if(e.length===1)return e[0];let t=e[0];for(let n=1;n<e.length;n++){const r=e[n];t=t*r/p(r,t)}return t},D=()=>{const e=l(),t=e.toString().slice(0,5).split("").reduce((s,c)=>s+parseInt(c),0),n=e.toString().slice(5,10).split("").reduce((s,c)=>s+parseInt(c),0),r=e.toString().slice(10,13).split("").reduce((s,c)=>s+parseInt(c),0),o=btoa(e.toString()),i=T(t,n,r).toString(),a=i.length,g=f(10);return i+g.slice(a)+a+o},E=(e,t)=>{typeof e=="string"&&(e=Number(e)),typeof t=="string"&&(t=Number(t));const n=new Date(e).getTime(),r=new Date(t).getTime();return Math.abs(n-r)};export{D as createFeId,y as getLocationHref,l as getTimestamp,b as htmlElementAsString,w as interceptStr,f as nanoid,d as nativeTryCatch,m as off,h as on,F as replaceOld,u as safeStringify,$ as supportsHistory,L as targetHasUnknow,E as timeDifference,S as unknowtoString};