Const
if (currentRuntimeValidationFnMap[RUNTIME.NODE]()) {
// execute nodejs-specific logic
console.log("current nodejs working directory is:", process.cwd())
}
if (currentRuntimeValidationFnMap[RUNTIME.DENO]()) {
// execute deno-specific logic
console.log("current deno working directory is:", Deno.cwd())
}
if (currentRuntimeValidationFnMap[RUNTIME.WEB]()) {
// execute web-specific logic
console.log("current webpage's url is:", globalThis.location?.href)
}
a map/record of runtime validation functions that determine if the current javascript environment matches a specific runtime.
each key represents a runtime type defined by the RUNTIME enum, and each value is a function that returns a boolean indicating whether your current environment satisfies the global-object requirements of the given RUNTIME.