Package Exports
- js-runtime
- js-runtime/package.json
Readme
Detect which JavaScript runtime is being used, Bun, Deno or NodeJS.
Usage
index.js
import { getRuntime } from "js-runtime";
console.log(getRuntime()); //node or deno or bun$ bun index.js
$ deno run index.js
$ node index.jsAPI
getRuntime
Return the current runtime.
Type: function
Returns: bun | deno | node
isBun
Type: function
Returns: boolean
isDeno
Type: function
Returns: boolean
isNode
Type: function
Returns: boolean
getRuntimeVersion
Retrieve the version used in the current runtime.
Type: function
Returns: string
runtimeSwitch
Switch based on the current runtime.
Type: function
Returns: T
index.js
import { runtimeSwitch } from "js-runtime";
const message = runtimeSwitch({
bun: "Script is running with Bun",
deno: "Script is running with Deno",
node: "Script is running with Node",
})
console.log(message)$ bun index.ts
script is running with BunruntimeImport
Dynamic import based on switch data, see runtimeSwitch.
Type: function
Returns: T
index.js
import { runtimeImport } from "js-runtime";
const SQLite = await runtimeImport({
bun: "bun:sqlite",
deno: "https://deno.land/x/sqlite3@0.9.1/mod.ts",
node: "better-sqlite3"
});
console.log(SQLite)$ bun index.ts
bun:sqlite