Skip to content

Color levels

marker uses a 0–3 color level to control output depth, matching chalk's convention.

LevelMeaningEscape type
0No colorPlain text passthrough
116-colorBasic ANSI \x1b[30m\x1b[37m
2256-color\x1b[38;5;Nm
3Truecolor\x1b[38;2;R;G;Bm

Detection

The level is detected once at module load from process.stdout:

ts
import { supportsColor, supportsColorStderr } from 'console-marker';

if (supportsColor) {
  console.log(`stdout supports color level ${supportsColor.level}`);
}
if (supportsColorStderr) {
  console.log(`stderr supports color level ${supportsColorStderr.level}`);
}

Environment overrides

Variable / flagEffect
FORCE_COLOR=0Disable colors
FORCE_COLOR=1 | 2 | 3Force level
NO_COLOR=1Disable colors (standard)
--no-colorDisable colors
--color=256Force 256-color
--color=16mForce truecolor

These take effect at startup — changing process.env.FORCE_COLOR after import has no effect.

Custom level instance

Create a builder fixed to a specific level:

ts
import { withLevel } from 'console-marker';

const m = withLevel(0);   // colors off — useful for testing
m.red('text')             // → 'text' (unchanged)

const m256 = withLevel(2);
m256.rgb(255, 100, 0)('text')  // → ANSI 256 escape, not truecolor

Checking the current level

ts
import marker from 'console-marker';

console.log(marker.level);  // 0 | 1 | 2 | 3

Released under the MIT License.