1 | has-unicode
|
---|
2 | ===========
|
---|
3 |
|
---|
4 | Try to guess if your terminal supports unicode
|
---|
5 |
|
---|
6 | ```javascript
|
---|
7 | var hasUnicode = require("has-unicode")
|
---|
8 |
|
---|
9 | if (hasUnicode()) {
|
---|
10 | // the terminal probably has unicode support
|
---|
11 | }
|
---|
12 | ```
|
---|
13 | ```javascript
|
---|
14 | var hasUnicode = require("has-unicode").tryHarder
|
---|
15 | hasUnicode(function(unicodeSupported) {
|
---|
16 | if (unicodeSupported) {
|
---|
17 | // the terminal probably has unicode support
|
---|
18 | }
|
---|
19 | })
|
---|
20 | ```
|
---|
21 |
|
---|
22 | ## Detecting Unicode
|
---|
23 |
|
---|
24 | What we actually detect is UTF-8 support, as that's what Node itself supports.
|
---|
25 | If you have a UTF-16 locale then you won't be detected as unicode capable.
|
---|
26 |
|
---|
27 | ### Windows
|
---|
28 |
|
---|
29 | Since at least Windows 7, `cmd` and `powershell` have been unicode capable,
|
---|
30 | but unfortunately even then it's not guaranteed. In many localizations it
|
---|
31 | still uses legacy code pages and there's no facility short of running
|
---|
32 | programs or linking C++ that will let us detect this. As such, we
|
---|
33 | report any Windows installation as NOT unicode capable, and recommend
|
---|
34 | that you encourage your users to override this via config.
|
---|
35 |
|
---|
36 | ### Unix Like Operating Systems
|
---|
37 |
|
---|
38 | We look at the environment variables `LC_ALL`, `LC_CTYPE`, and `LANG` in
|
---|
39 | that order. For `LC_ALL` and `LANG`, it looks for `.UTF-8` in the value.
|
---|
40 | For `LC_CTYPE` it looks to see if the value is `UTF-8`. This is sufficient
|
---|
41 | for most POSIX systems. While locale data can be put in `/etc/locale.conf`
|
---|
42 | as well, AFAIK it's always copied into the environment.
|
---|
43 |
|
---|