UNPKG

real-dev-hours

Version:
71 lines (70 loc) 3.48 kB
export function enableRealDevHours(config = {}) { // just in case you're something like astro if (typeof window === 'undefined' || typeof document === 'undefined') return; const { framework = 'vanilla', enableLogs = true, enableVisualChaos = true, interval = 8000, consoleNoiseLevel = 'medium', } = config; // CSS var override, because why not document.documentElement.style.setProperty('--btn-margin', `calc(1rem + 0.3vw * ${Math.floor(Math.random() * 10)})`); // inject very very important div if (!document.getElementById('debug-shadow-root')) { const debugDiv = document.createElement('div'); debugDiv.id = 'debug-shadow-root'; document.body.appendChild(debugDiv); } // self explanatory logs if (enableLogs) { console.warn("Real Dev Hours activated. Nothing will ever be the same."); setInterval(() => { const log = (...args) => { if (consoleNoiseLevel === 'low') return; console.warn(...args); }; const error = (...args) => { if (consoleNoiseLevel === 'low') return; console.error(...args); }; switch (framework) { case 'react': log("Warning: Each child in a list should have a unique 'key' prop."); error("Uncaught Error: Too many re-renders. React limits the number of renders to prevent an infinite loop."); log("Warning: Can't perform a React state update on an unmounted component."); break; case 'vue': log("[Vue warn]: Property or method 'x' is not defined on the instance but referenced during render."); error("Uncaught TypeError: Cannot read property 'x' of undefined"); break; case 'svelte': log("A component was created with unknown prop 'value'"); error("Uncaught (in promise): No store found for 'someStore'"); break; case 'angular': log("NG0100: ExpressionChangedAfterItHasBeenCheckedError"); error("core.js:12345 ERROR TypeError: Cannot read property 'foo' of undefined"); break; case 'solid': log("Hydration mismatch: unable to reconcile nodes"); error("Error: Signal value accessed outside reactive context"); break; default: log("Failed to load resource: net::ERR_FAILED"); log("client:1722 WebSocket connection to 'ws://localhost:3000/' failed:"); error("Uncaught TypeError: Cannot read properties of undefined (reading 'value')"); } if (consoleNoiseLevel === 'high') { error("UnhandledPromiseRejectionWarning: ReferenceError: x is not defined"); log("DevTools failed to load SourceMap: Could not load content for file://..."); } }, interval); } // as it sounds if (enableVisualChaos) { setInterval(() => { const els = document.querySelectorAll("*"); els.forEach(el => { el.style.transform = `translate(${Math.random() * 3}px, ${Math.random() * 3}px)`; }); }, 5000); } }