Detect whether the terminal supports Unicode
npx @tessl/cli install tessl/npm-is-unicode-supported@1.3.0is-unicode-supported is a lightweight utility library for detecting whether the current terminal environment supports Unicode characters. It provides platform-specific logic to determine Unicode support by checking environment variables and terminal identifiers, making it ideal for command-line tools and CLI applications that need to decide between Unicode symbols and ASCII fallbacks.
npm install is-unicode-supportedimport isUnicodeSupported from 'is-unicode-supported';Note: This package is ESM-only and requires Node.js 12+ with ES module support. CommonJS require() is not supported.
import isUnicodeSupported from 'is-unicode-supported';
const supportsUnicode = isUnicodeSupported();
if (supportsUnicode) {
console.log('✅ Unicode is supported - using fancy symbols');
} else {
console.log('[OK] Unicode not supported - using ASCII fallbacks');
}Detects whether the terminal supports Unicode by examining platform-specific environment variables and terminal identifiers.
/**
* Detect whether the terminal supports Unicode
* @returns {boolean} true if the terminal supports Unicode, false otherwise
*/
function isUnicodeSupported(): boolean;Detection Logic:
For non-Windows platforms (macOS, Linux, etc.):
true by defaultfalse only if process.env.TERM === 'linux' (Linux console kernel)For Windows platforms:
true if any of the following conditions are met:
process.env.CI is truthy (CI environments)process.env.WT_SESSION is truthy (Windows Terminal)process.env.TERMINUS_SUBLIME is truthy (Terminus < v0.2.27)process.env.ConEmuTask === '{cmd::Cmder}' (ConEmu and cmder)process.env.TERM_PROGRAM === 'Terminus-Sublime'process.env.TERM_PROGRAM === 'vscode' (VS Code integrated terminal)process.env.TERM === 'xterm-256color'process.env.TERM === 'alacritty'process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm'false if none of the above conditions are metUsage Examples:
import isUnicodeSupported from 'is-unicode-supported';
// Simple check
if (isUnicodeSupported()) {
console.log('🎉 Unicode supported!');
} else {
console.log('Unicode not supported');
}
// CLI output decision
const checkMark = isUnicodeSupported() ? '✅' : '[OK]';
const crossMark = isUnicodeSupported() ? '❌' : '[FAIL]';
console.log(`${checkMark} Test passed`);
console.log(`${crossMark} Test failed`);
// Progress indicators
const spinner = isUnicodeSupported() ? ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] : ['|', '/', '-', '\\'];No runtime dependencies. Uses only Node.js built-in modules:
node:process for platform detection and environment variable access