CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-std-env

Runtime agnostic JavaScript utility library for environment detection, platform information, CI/CD provider detection, and runtime identification.

Pending
Overview
Eval results
Files

environment-detection.mddocs/

Environment Detection

Boolean flags for detecting various environment states including CI, debug, test, production, development modes, and terminal capabilities.

Capabilities

CI Environment Detection

Detects continuous integration environments through environment variables and provider detection.

/**
 * Detects if running in a CI environment
 * Based on CI environment variable or detected CI provider
 */
const isCI: boolean;

Usage Examples:

import { isCI } from "std-env";

if (isCI) {
  console.log("Running in CI environment");
  // Disable interactive prompts
  // Enable CI-specific logging
}

Debug Mode Detection

Detects debug mode based on the DEBUG environment variable.

/**
 * Detects if DEBUG environment variable is set to a truthy value
 */
const isDebug: boolean;

Usage Examples:

import { isDebug } from "std-env";

if (isDebug) {
  console.log("Debug mode enabled");
  // Enable verbose logging
  // Show debug information
}

Test Environment Detection

Detects test environments based on NODE_ENV or TEST environment variables.

/**
 * Detects if running in test environment
 * True when NODE_ENV is 'test' or TEST environment variable is truthy
 */
const isTest: boolean;

Usage Examples:

import { isTest } from "std-env";

if (isTest) {
  console.log("Running in test environment");
  // Use test database
  // Mock external services
}

Production Environment Detection

Detects production environments based on NODE_ENV.

/**
 * Detects if NODE_ENV is set to 'production'
 */
const isProduction: boolean;

Usage Examples:

import { isProduction } from "std-env";

if (isProduction) {
  console.log("Running in production");
  // Enable optimizations
  // Disable debug features
}

Development Environment Detection

Detects development environments based on NODE_ENV.

/**
 * Detects if NODE_ENV is 'dev' or 'development'
 */
const isDevelopment: boolean;

Usage Examples:

import { isDevelopment } from "std-env";

if (isDevelopment) {
  console.log("Running in development");
  // Enable hot reloading
  // Show development tools
}

Minimal Environment Detection

Detects minimal environments where rich UI features should be disabled.

/**
 * Detects minimal environment conditions
 * True when MINIMAL env var is set, running in CI, test, or TTY unavailable
 */
const isMinimal: boolean;

Usage Examples:

import { isMinimal } from "std-env";

if (isMinimal) {
  // Disable animations
  // Use simplified output
  // Skip interactive features
}

TTY Detection

Detects if stdout TTY is available for interactive features.

/**
 * Detects if stdout TTY is available
 * Checks process.stdout.isTTY when available
 */
const hasTTY: boolean;

Usage Examples:

import { hasTTY } from "std-env";

if (hasTTY) {
  // Enable interactive prompts
  // Use colored output
  // Show progress bars
}

Window Object Detection

Detects if running in a browser environment with window object.

/**
 * Detects if global window object is available
 * Indicates browser environment
 */
const hasWindow: boolean;

Usage Examples:

import { hasWindow } from "std-env";

if (hasWindow) {
  console.log("Running in browser");
  // Use browser APIs
  // Access DOM
} else {
  console.log("Running in server environment");
}

Color Support Detection

Detects terminal color support for enhanced output formatting.

/**
 * Detects if terminal supports colors
 * Based on NO_COLOR, FORCE_COLOR, TTY status, and CI environment
 */
const isColorSupported: boolean;

Usage Examples:

import { isColorSupported } from "std-env";

if (isColorSupported) {
  console.log("\x1b[32mGreen text\x1b[0m");
} else {
  console.log("Plain text");
}

Detection Logic

The environment detection uses the following logic:

  • isCI: env.CI is truthy OR detected CI provider
  • isDebug: env.DEBUG is truthy
  • isTest: nodeENV === "test" OR env.TEST is truthy
  • isProduction: nodeENV === "production"
  • isDevelopment: nodeENV === "dev" OR nodeENV === "development"
  • isMinimal: env.MINIMAL is truthy OR isCI OR isTest OR !hasTTY
  • hasTTY: process.stdout.isTTY is truthy
  • hasWindow: typeof window !== "undefined"
  • isColorSupported: !env.NO_COLOR AND (env.FORCE_COLOR OR hasTTY OR isWindows OR isCI) AND env.TERM !== "dumb"

Install with Tessl CLI

npx tessl i tessl/npm-std-env

docs

environment-detection.md

environment-variables.md

index.md

platform-detection.md

provider-detection.md

runtime-detection.md

tile.json