Skip to content

useColor

reference
1 min readUpdated

Kind: Function

Source: lib/command.js

Exported for using from tests, not otherwise used outside this file.

useColor is a helper exported from lib/command.js for test code. It exposes the command module's color-selection behavior without being used elsewhere outside that file.

Diagram

mermaid
graph LR
  Environment[Runtime environment] --> UseColor[useColor]
  UseColor --> ColorDecision[Color decision]
  ColorDecision --> Tests[Test assertions]

Usage

js
import { useColor } from './lib/command.js';

const colorEnabled = useColor();

if (colorEnabled) {
  console.log('Color output is enabled');
}

AI Coding Instructions

  • Keep useColor exported so tests can access the same color behavior as lib/command.js.
  • Test color-related behavior through useColor rather than duplicating its decision logic in test files.
  • Avoid adding production call sites outside lib/command.js unless the module boundary is intentionally changed.
  • Account for runtime environment settings that may affect whether color output is enabled.

Was this page helpful?

Download as PDF