Runtime object with boolean flags for each environment
const runtime = runtimeFn();
if (runtime.isNodeIsh) {
// Use Node.js APIs
const fs = require('fs');
} else if (runtime.isBrowser) {
// Use browser APIs
console.log(window.location.href);
} else if (runtime.isDeno) {
// Use Deno APIs
const file = await Deno.readTextFile('./config.json');
} else if (runtime.isCFWorker) {
// Use Cloudflare Workers APIs
const cache = caches.default;
}
Detects the current JavaScript runtime environment.
Performs feature detection to identify which runtime environment the code is executing in. Checks for environment-specific global objects and APIs in priority order:
The detection is mutually exclusive - only one environment flag will be true.