Detect whether the terminal supports Unicode
npx @tessl/cli install tessl/npm-is-unicode-supported@1.3.00
# is-unicode-supported
1
2
is-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.
3
4
## Package Information
5
6
- **Package Name**: is-unicode-supported
7
- **Package Type**: npm
8
- **Language**: JavaScript (ES modules)
9
- **Installation**: `npm install is-unicode-supported`
10
11
## Core Imports
12
13
```javascript
14
import isUnicodeSupported from 'is-unicode-supported';
15
```
16
17
**Note**: This package is ESM-only and requires Node.js 12+ with ES module support. CommonJS `require()` is not supported.
18
19
## Basic Usage
20
21
```javascript
22
import isUnicodeSupported from 'is-unicode-supported';
23
24
const supportsUnicode = isUnicodeSupported();
25
26
if (supportsUnicode) {
27
console.log('✅ Unicode is supported - using fancy symbols');
28
} else {
29
console.log('[OK] Unicode not supported - using ASCII fallbacks');
30
}
31
```
32
33
## Capabilities
34
35
### Unicode Detection
36
37
Detects whether the terminal supports Unicode by examining platform-specific environment variables and terminal identifiers.
38
39
```javascript { .api }
40
/**
41
* Detect whether the terminal supports Unicode
42
* @returns {boolean} true if the terminal supports Unicode, false otherwise
43
*/
44
function isUnicodeSupported(): boolean;
45
```
46
47
**Detection Logic:**
48
49
For **non-Windows platforms** (macOS, Linux, etc.):
50
- Returns `true` by default
51
- Returns `false` only if `process.env.TERM === 'linux'` (Linux console kernel)
52
53
For **Windows platforms**:
54
- Returns `true` if any of the following conditions are met:
55
- `process.env.CI` is truthy (CI environments)
56
- `process.env.WT_SESSION` is truthy (Windows Terminal)
57
- `process.env.TERMINUS_SUBLIME` is truthy (Terminus < v0.2.27)
58
- `process.env.ConEmuTask === '{cmd::Cmder}'` (ConEmu and cmder)
59
- `process.env.TERM_PROGRAM === 'Terminus-Sublime'`
60
- `process.env.TERM_PROGRAM === 'vscode'` (VS Code integrated terminal)
61
- `process.env.TERM === 'xterm-256color'`
62
- `process.env.TERM === 'alacritty'`
63
- `process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm'`
64
- Returns `false` if none of the above conditions are met
65
66
**Usage Examples:**
67
68
```javascript
69
import isUnicodeSupported from 'is-unicode-supported';
70
71
// Simple check
72
if (isUnicodeSupported()) {
73
console.log('🎉 Unicode supported!');
74
} else {
75
console.log('Unicode not supported');
76
}
77
78
// CLI output decision
79
const checkMark = isUnicodeSupported() ? '✅' : '[OK]';
80
const crossMark = isUnicodeSupported() ? '❌' : '[FAIL]';
81
82
console.log(`${checkMark} Test passed`);
83
console.log(`${crossMark} Test failed`);
84
85
// Progress indicators
86
const spinner = isUnicodeSupported() ? ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] : ['|', '/', '-', '\\'];
87
```
88
89
## Platform Support
90
91
- **Node.js**: 12+ (ES modules support required)
92
- **Windows**: Detects specific terminal environments that support Unicode
93
- **macOS/Linux**: Assumes Unicode support except for Linux console kernel
94
- **CI Environments**: Automatically detects CI systems that support Unicode
95
96
## Dependencies
97
98
No runtime dependencies. Uses only Node.js built-in modules:
99
- `node:process` for platform detection and environment variable access