runtimey
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

runtimey

Easily detect which JavaScript runtime is being used. Bun, Deno, Node.JS or browser.

Useful for packages or scripts to customize functionality of their code depending on the runtime being executed.

Usage

index.js

import { currentRuntime } from "runtimey";
console.log(currentRuntime);

shell

$ bun index.js && deno run index.js && node index.js
bun
deno
node

Documentation

  • isBun

    true if the Bun runtime is being used.

  • isDeno

    true if the Deno runtime is being used.

  • isNode

    true if the Node.JS runtime is being used.

  • isBrowser

    true if running inside a browser.

  • currentRuntime: "bun" | "deno" | "node" | "browser" | "unknown"

    The name of the current runtime being used.

  • runtimeValue({ bun, deno, node, browser, default })

    Returns the value according to the runtime being used.

    index.js

    import { runtimeValue } from "runtimey";
    const val = runtimeValue({ bun: "RUNTIME_BUN", deno: "RUNTIME_DENO", node: "RUNTIME_NODE" });
    console.log("Current runtime:", val);

    shell

    $ bun index.js && deno run index.js && node index.js
    Current runtime: RUNTIME_BUN
    Current runtime: RUNTIME_DENO
    Current runtime: RUNTIME_NODE
  • isServiceWorker

    true if running in a worker environment.

License

This repository uses MIT License. See LICENSE for full license text.

Package Sidebar

Install

npm i runtimey

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

4.26 kB

Total Files

5

Last publish

Collaborators

  • tr1ckydev