A collection of runtime environment utilities and indicators, providing an easy interface to decipher the current runtime environment.
Install the package:
npm i @cocopina/environment
The global scope, can be either "global" or "window".
// Browser
import { globalScope } from '@cocopina/environment';
console.log(globalScope === window); // true
// Node
const { globalScope } = require('@cocopina/environment');
console.log(globalScope === global); // true
Whether the current enironment is a node-like environment.
// Browser
import { node } from '@cocopina/environment';
console.log(node); // false
// Node
const { node } = require('@cocopina/environment');
console.log(node); // true
Whether the current enironment is a browser environment.
// Browser
import { browser } from '@cocopina/environment';
console.log(browser); // true
// Node
const { browser } = require('@cocopina/environment');
console.log(browser); // false