#browser Clear
Tags #utils #browser #performance #array #async #dom #objects #pattern #events #format #concurrency #http #ui #advanced #fetch #url #string #functional #cache #files #crypto #promise #intl #observer
JavaScript Copy Text to Clipboard
Copies a string to the system clipboard. Uses the modern navigator.clipboard.writeText API (requires HTTPS or localhost) and falls back to the deprecated document.execCommand approach for older browsers or non-secure contexts. Returns a Promise so you can show success/error feedback.
JavaScript LocalStorage with Expiry
Extends localStorage with TTL (time-to-live) support. setItem stores a value alongside an expiry timestamp. getItem returns null and removes the key if the TTL has elapsed. Useful for caching API responses client-side, storing ephemeral UI state, and implementing remember-me tokens without a backend session.
JavaScript Cookie Helpers (Get / Set / Delete)
Minimal cookie utilities: getCookie retrieves a value by name, setCookie writes a cookie with optional expiry days and path, deleteCookie removes it by setting an expired date. No library needed for simple first-party cookie management. For complex scenarios (SameSite, Secure, partitioned) extend the options object.
JavaScript DOM Ready Helper
Runs a callback when the DOM is fully parsed and ready, without waiting for images or stylesheets. Works whether called before or after DOMContentLoaded has already fired — unlike a bare addEventListener which misses the event if the DOM is already ready when the script runs.
JavaScript Detect Dark Mode Preference
Reads the user's OS-level dark mode preference using the prefers-color-scheme media query and watches for live changes. Useful for initialising theme state before any user interaction and reacting automatically when the user switches their system theme without reloading the page.
JavaScript Detect Mobile / Device Type
Detects whether the user is on a mobile, tablet, or desktop device. The navigator.userAgentData API (Chromium) is preferred for its structured data; falls back to a User-Agent regex for Safari and Firefox. Useful for conditional rendering, touch event handling, and analytics segmentation.
JavaScript IndexedDB Wrapper
A Promise-based wrapper for the IndexedDB API — simplifies the verbose request/onsuccess/onerror pattern into clean async/await calls. Supports get, set, delete, and getAll operations on a named object store. Ideal for storing large client-side datasets, offline data, and blobs that exceed localStorage limits.
JavaScript Keyboard Shortcut Manager
Registers global keyboard shortcuts with a simple key-combo syntax ("ctrl+k", "meta+shift+p"). Handles modifier keys (ctrl, alt, shift, meta) and prevents default browser behaviour when a shortcut matches. Shortcuts can be unregistered individually or all at once, making it easy to scope shortcuts to page sections or modals.
JavaScript Download File from Client
Programmatically triggers a file download from a Blob, File object, or plain text/JSON string without a server round-trip. Creates a temporary anchor element with a download attribute and revokes the object URL after use to prevent memory leaks. Supports custom filenames and MIME types.