Module: @lumjs/core/context

Context sub-module

Used as a static object that has a bunch of properties describing the current JS environment and execution context.

Properties:
Name Type Attributes Description
hasDefine boolean

A global define() function was found.

hasRequire boolean

A global require() function was found.

hasExports boolean

A global exports variable was found.

hasModule boolean

A global module object was found.

hasModuleExports boolean

A module.exports exists.

hasSyncedExports boolean

exports === module.exports

isNode boolean

An alias to Node.ok.

isBrowser boolean

A web-browser environment detected.

isWindow boolean

Is a browser Window context.

isWorker boolean

Is a browser Worker (sub-types below.)

isServiceWorker boolean

Is a ServiceWorker context.

isDedicatedWorker boolean

Is a DedicatedWorker context.

isSharedWorker boolean

Is a SharedWorker context.

AMD object

Asynchronous Module Definition detection.

Properties
Name Type Description
isSupported boolean

The define.amd property is set.

isRequireJS boolean

A global requirejs was found.

CJS object

CommonJS detection.

Properties
Name Type Description
standard boolean

hasDefine && hasRequire

nodeLike boolean

CJS.standard && hasExports

isLumV5 boolean

Lum.js browser bundler detected.

isWebpack boolean

Webpack bundler detected.

inBrowser boolean

CJS.isLumV5 || CJS.isWebpack

Node object

Node.js detection.

Properties
Name Type Attributes Description
isSane boolean

CJS.nodeLike && !CJS.inBrowser

hasProcess boolean

A global process object exists.

ok boolean

Node.isSane && Node.hasProcess

ver string <nullable>

process.versions.node ?? null

versions object <nullable>

process.versions ?? null

args Array

Command line arguments.

script string

Command line script name.

Electron object

Electron detection.

ok boolean

Electron environment detected.

isDefault boolean

Is this the default app?

isBundled boolean

Is this a bundled app?

isMain boolean

Is this the main renderer frame?

type string <nullable>

process.type

root object

See module:@lumjs/core/types.root

Source:

Methods

(static) has(ns) → {boolean}

See if a root-level name is defined.

This adds a context.has.{name} boolean property which caches the result so it can be referred to directly.

In any JS environment with the Proxy object (which honestly should be all modern ones), you can simple do context.has.SomeObject instead of context.has('SomeObject') and it will do the Right Thing™.

Parameters:
Name Type Description
ns string

The global function/class/object we're looking for.

Source:
Returns:

If that global name is defined or not.

Type
boolean