Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
browser-or-node
Advanced tools
The 'browser-or-node' npm package is a utility that helps developers determine whether their code is running in a browser or Node.js environment. This can be particularly useful for writing isomorphic JavaScript that needs to behave differently depending on the runtime environment.
Detect if running in a browser
This feature allows you to check if the code is being executed in a browser environment. The 'isBrowser' boolean will be true if the code is running in a browser.
const { isBrowser } = require('browser-or-node');
if (isBrowser) {
console.log('Running in a browser');
}
Detect if running in Node.js
This feature allows you to check if the code is being executed in a Node.js environment. The 'isNode' boolean will be true if the code is running in Node.js.
const { isNode } = require('browser-or-node');
if (isNode) {
console.log('Running in Node.js');
}
Detect if running in a web worker
This feature allows you to check if the code is being executed in a Web Worker environment. The 'isWebWorker' boolean will be true if the code is running in a Web Worker.
const { isWebWorker } = require('browser-or-node');
if (isWebWorker) {
console.log('Running in a Web Worker');
}
The 'is-browser' package provides a simple way to check if the code is running in a browser environment. It is similar to 'browser-or-node' but does not offer the same level of granularity, such as detecting Node.js or Web Workers.
The 'detect-node' package is a lightweight utility to check if the code is running in a Node.js environment. Unlike 'browser-or-node', it does not provide functionality to detect browser or Web Worker environments.
The 'is-node' package is another utility to determine if the code is running in a Node.js environment. It is similar to 'detect-node' and does not offer the ability to detect browser or Web Worker environments.
Check whether the code is running in the browser or node.js runtime.
$ npm install --save browser-or-node
ES6 style import
import { isBrowser, isNode, isWebWorker, isJsDom, isDeno } from "browser-or-node";
if (isBrowser) {
// do browser only stuff
}
if (isNode) {
// do node.js only stuff
}
if (isWebWorker) {
// do web worker only stuff
}
if (isJsDom) {
// do jsdom only stuff
}
if (isDeno) {
// do deno only stuff
}
ES5 style import
var jsEnv = require("browser-or-node");
if (jsEnv.isBrowser) {
// do browser only stuff
}
if (jsEnv.isNode) {
// do node.js only stuff
}
if (jsEnv.isWebWorker) {
// do web worker only stuff
}
if (jsEnv.isJsDom) {
// do jsdom only stuff
}
if (jsEnv.isDeno) {
// do deno only stuff
}
MIT © Dineshkumar Pandiyan
FAQs
Check in which environment the code is running - browser/node.js/webworker/jsdom/deno
We found that browser-or-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.