A shared folder with AI prompts and code snippets
From workspace: FreeCodeCamp
Team: Main
Total snippets: 4
4 snippets
Checks if the user's system prefers dark mode.
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
Copies text to the clipboard using the Clipboard API.
function copyToClipboard(text) { navigator.clipboard.writeText(text); }
Ensures a function is called at most once every specified interval.
function throttle(func, limit) { let inThrottle; return function(...args) { if (!inThrottle) { func.apply(this, args); inThrottle = true; setTimeout(() => inThrottle = false, limit); } }; }
Delays a function call until after a specified delay from the last event trigger.
function debounce(func, delay) { let timeout; return function(...args) { clearTimeout(timeout); timeout = setTimeout(() => func.apply(this, args), delay); }; }