Last active
December 10, 2023 14:33
-
-
Save guest271314/13ae833d27395f3db7d3b683b02cc611 to your computer and use it in GitHub Desktop.
Return the name of the JavaScript runtime the script is running in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const runtime = () => { | |
// TODO: More direct and exclusionary way to do this for QuickJS | |
if ( | |
!globalThis.hasOwnProperty("hasOwn") && | |
Array.isArray(globalThis.scriptArgs) | |
) { | |
return "qjs"; | |
} | |
if (Object.hasOwn(globalThis, "tjs")) { | |
return globalThis.tjs.args[0]; | |
} | |
if (Object.hasOwn(globalThis, "process")) { | |
if (globalThis.process.argv0 === "node") { | |
return globalThis.process.argv0; | |
} | |
if ( | |
globalThis.process.argv0 === "bun" | |
&& globalThis.process.isBun) { | |
return globalThis.process.argv0; | |
} | |
} | |
if (Object.hasOwn(globalThis, "Deno")) { | |
return Object.keys(globalThis.Deno.version).shift(); | |
} | |
}; | |
console.log(runtime()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment