UNPKG

@tanstack/hotkeys

Version:

Type-safe, framework-agnostic keyboard hotkey management for the browser

22 lines (20 loc) • 866 B
import { canWarn } from "./_dev.js"; // src/_server.ts const SERVER_AGENT = /^(?:Node\.js\/|Deno\/|Bun\/|Cloudflare-Workers)/; /** Whether this runs on a server: no `navigator`, or a server runtime's. */ function isServerRuntime() { return typeof navigator === "undefined" || SERVER_AGENT.test(String(navigator.userAgent)); } let warned = false; /** * Warns once, in development, when a label's platform is detected during * server rendering. The server then renders 'linux' labels, which differ for * users on macOS and Windows after hydration. */ function warnServerPlatform() { if (canWarn && process.env.NODE_ENV !== "production" && !warned && isServerRuntime()) { warned = true; console.warn("[hotkeys] Server-rendered label uses 'linux'. Set the provider's platform with detectPlatform(userAgent)"); } } export { isServerRuntime, warnServerPlatform };