Skip to content

Instantly share code, notes, and snippets.

@guest271314
Last active December 10, 2023 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guest271314/13ae833d27395f3db7d3b683b02cc611 to your computer and use it in GitHub Desktop.
Save guest271314/13ae833d27395f3db7d3b683b02cc611 to your computer and use it in GitHub Desktop.
Return the name of the JavaScript runtime the script is running in
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