@ndriadev/react-tools
Version:
A React library of hooks, components, utils and types ready to use
2 lines (1 loc) • 2.01 kB
JavaScript
const y=(e,t)=>{if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;const i=Reflect.ownKeys(e),n=Reflect.ownKeys(t);if(i.length!==n.length)return!1;for(let s=0,c=i.length;s<c;s++){const l=i[s];if(!Reflect.has(t,l)||!Object.is(e[l],t[l]))return!1}return!0},a=(e,t,i=new WeakMap)=>{if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(i.get(e)===t)return!0;i.set(e,t);const n=Reflect.ownKeys(e),s=Reflect.ownKeys(t);if(n.length!==s.length)return!1;for(let c=0;c<n.length;c++)if(!Reflect.has(t,n[c])||!a(e[n[c]],t[n[c]],i))return!1;return!0},m=e=>e.nativeEvent?window.TouchEvent?e.nativeEvent instanceof TouchEvent:"touches"in e.nativeEvent:e instanceof TouchEvent,d=e=>typeof e=="function"&&e.constructor.name==="AsyncFunction"||typeof e=="object"&&typeof e.then=="function",g=(e,t)=>i=>{let n=e.toLowerCase().split("+").map(r=>r.trim());const s={alt:n.includes("alt"),ctrl:n.includes("ctrl"),meta:n.includes("meta"),ctrlCommand:n.includes("ctrlcommand"),shift:n.includes("shift")};n=n.filter(r=>!["alt","ctrl","meta","shift","ctrlCommand"].includes(r));for(let r=0,u=n.length;r<u;r++)n[r]===""&&r+1<u&&n[r+1]===""&&(n[r+1]="+");n=n.filter(r=>r!=="");const{altKey:c,ctrlKey:l,metaKey:f,shiftKey:o,key:h}=i;if(s.ctrlCommand){if(!l&&!f)return}else if(l!==s.ctrl||c!==s.alt||f!==s.meta||o!==s.shift)return;(n.includes(h.toLowerCase())||n.includes(i.code.replace("Key","")))&&t&&t(i)};function p(){const e=navigator.userAgent;let t;return e.match(/chrome|chromium|crios/i)?t="chrome":e.match(/firefox|fxios/i)?t="firefox":e.match(/safari/i)?t="safari":e.match(/opr/i)?t="opera":e.match(/edg/i)?t="edge":t="No detection",t}exports.detectBrowser=p;exports.hotKeyHandler=g;exports.isAsync=d;exports.isDeepEqual=a;exports.isShallowEqual=y;exports.isTouchEvent=m;
;