Skip to content

Commit 01b83ae

Browse files
committed
Init
0 parents  commit 01b83ae

12 files changed

+176
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.yml]
11+
indent_style = space
12+
indent_size = 2

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/workflows/main.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
name: Node.js ${{ matrix.node-version }}
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
node-version:
13+
- 14
14+
- 12
15+
- 10
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: actions/setup-node@v1
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
- run: npm install
22+
- run: npm test

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
yarn.lock

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

index.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
Detect whether the terminal supports Unicode.
3+
4+
@example
5+
```
6+
import isUnicodeSupported = require('is-unicode-supported');
7+
8+
isUnicodeSupported();
9+
//=> true
10+
```
11+
*/
12+
declare function isUnicodeSupported(): boolean;
13+
14+
export = isUnicodeSupported;

index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
module.exports = () => {
4+
if (process.platform !== 'win32') {
5+
return true;
6+
}
7+
8+
return Boolean(process.env.CI) ||
9+
Boolean(process.env.WT_SESSION) || // Windows Terminal
10+
process.env.TERM_PROGRAM === 'vscode' ||
11+
process.env.TERM === 'xterm-256color' ||
12+
process.env.TERM === 'alacritty';
13+
};

index.test-d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {expectType} from 'tsd';
2+
import isUnicodeSupported = require('.');
3+
4+
expectType<boolean>(isUnicodeSupported());

license

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "is-unicode-supported",
3+
"version": "0.0.0",
4+
"description": "Detect whether the terminal supports Unicode",
5+
"license": "MIT",
6+
"repository": "sindresorhus/is-unicode-supported",
7+
"funding": "https://github.com/sponsors/sindresorhus",
8+
"author": {
9+
"name": "Sindre Sorhus",
10+
"email": "[email protected]",
11+
"url": "https://sindresorhus.com"
12+
},
13+
"engines": {
14+
"node": ">=10"
15+
},
16+
"scripts": {
17+
"test": "xo && ava && tsd"
18+
},
19+
"files": [
20+
"index.js",
21+
"index.d.ts"
22+
],
23+
"keywords": [
24+
"terminal",
25+
"unicode",
26+
"detect",
27+
"utf8",
28+
"console",
29+
"shell",
30+
"support",
31+
"supports",
32+
"supported",
33+
"check",
34+
"detection"
35+
],
36+
"devDependencies": {
37+
"ava": "^2.4.0",
38+
"tsd": "^0.14.0",
39+
"xo": "^0.38.2"
40+
}
41+
}

readme.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# is-unicode-supported
2+
3+
> Detect whether the terminal supports Unicode
4+
5+
This can be useful to decide whether to use Unicode characters or fallback ASCII characters in command-line output.
6+
7+
Note that the check is quite naive. It just assumes all non-Windows terminals support Unicode and hard-codes which Windows terminals that do support Unicode. However, I have been using this logic in some popular packages for years without problems.
8+
9+
## Install
10+
11+
```
12+
$ npm install is-unicode-supported
13+
```
14+
15+
## Usage
16+
17+
```js
18+
const isUnicodeSupported = require('is-unicode-supported');
19+
20+
isUnicodeSupported();
21+
//=> true
22+
```
23+
24+
## API
25+
26+
### isUnicodeSupported()
27+
28+
Returns a `boolean` for whether the terminal supports Unicode.
29+
30+
## Related
31+
32+
- [is-interactive](https://github.com/sindresorhus/is-interactive) - Check if stdout or stderr is interactive
33+
- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
34+
- [figures](https://github.com/sindresorhus/figures) - Unicode symbols with Windows fallbacks
35+
- [log-symbols](https://github.com/sindresorhus/log-symbols) - Colored symbols for various log levels

test.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import test from 'ava';
2+
import isUnicodeSupported from './index.js';
3+
4+
test.serial('main', t => {
5+
t.true(isUnicodeSupported());
6+
});
7+
8+
test.serial('windows', t => {
9+
delete process.env.CI;
10+
delete process.env.TERM;
11+
delete process.env.TERM_PROGRAM;
12+
13+
const originalPlatform = process.platform;
14+
15+
Object.defineProperty(process, 'platform', {value: 'win32'});
16+
t.false(isUnicodeSupported());
17+
process.env.WT_SESSION = '1';
18+
t.true(isUnicodeSupported());
19+
20+
Object.defineProperty(process, 'platform', {value: originalPlatform});
21+
delete process.env.WT_SESSION;
22+
});

0 commit comments

Comments
 (0)