Skip to main content
Home

Detect javascript runtime without any deps

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (0.3.0)

MIT license GitHub issues TypeScript Bun


Refer to JSR website JSRPackageSetup for installing the package. Or see the instruction above the readme file


Isjsruntime

Update: Full deno support AND bun (that means the engine() function worked!). Updated readme with consistent implementation (because of the old repo). And now the script is typesafe!

Only contains 2 non-async function (which on fails, return undefined)

  • env(legacy=false) for detecting javascript runtime. Contains one optional parameter (boolean) for enabling the legacy detector for JSDOM, and
  • engine() for detecting javascript engine. No parameters required

And 2 types

  • jsEngineList list of accepted engine such as v8, etc.
  • jsEnvList list of accepted javascript runtime

Detect if running on bun (working with/without polyfill)

// import the package
import * isjs from '@cupglassdev/isjsruntime'
// make a function
function run(){
// check using the env() function
const env = isjs.env()
if (env==='bun'){ 
  console.log('you are on bun')
} else {
  throw new Error('it looks like you are using another js enviroment')
}
}
// run the function
run()

detect if the node engine is running on v8

import * as isjs from '@cupglassdev/isjsruntime'

function isusingv8() {
// check using the engine() function
const engine = isjs.engine()
if (engine ==='v8') return true
else return false;
}
//print it onto the console
console.log(isusingv8())

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@cupglassdev/isjsruntime

Import symbol

import * as isjsruntime from "@cupglassdev/isjsruntime";
or

Import directly with a jsr specifier

import * as isjsruntime from "jsr:@cupglassdev/isjsruntime";

Add Package

pnpm i jsr:@cupglassdev/isjsruntime
or (using pnpm 10.8 or older)
pnpm dlx jsr add @cupglassdev/isjsruntime

Import symbol

import * as isjsruntime from "@cupglassdev/isjsruntime";

Add Package

yarn add jsr:@cupglassdev/isjsruntime
or (using Yarn 4.8 or older)
yarn dlx jsr add @cupglassdev/isjsruntime

Import symbol

import * as isjsruntime from "@cupglassdev/isjsruntime";

Add Package

vlt install jsr:@cupglassdev/isjsruntime

Import symbol

import * as isjsruntime from "@cupglassdev/isjsruntime";

Add Package

npx jsr add @cupglassdev/isjsruntime

Import symbol

import * as isjsruntime from "@cupglassdev/isjsruntime";

Add Package

bunx jsr add @cupglassdev/isjsruntime

Import symbol

import * as isjsruntime from "@cupglassdev/isjsruntime";