JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 56560
  • Score
    100M100P100Q132237F
  • License MIT

Detect which JavaScript runtime is being used.

Package Exports

  • js-runtime
  • js-runtime/package.json

Readme

js-runtime

Npm version Npm downloads Npm downloads

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.js

API

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 Bun

runtimeImport

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