Skip to content

Commit c214314

Browse files
committed
Require Node.js 18
Closes #151
1 parent edc5d7d commit c214314

File tree

9 files changed

+175
-165
lines changed

9 files changed

+175
-165
lines changed

.github/funding.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
github: [sindresorhus, Qix-]
2-
tidelift: npm/supports-color

.github/workflows/main.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 20
1314
- 18
14-
- 16
15-
- 14
1615
steps:
17-
- uses: actions/checkout@v3
18-
- uses: actions/setup-node@v3
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
1918
with:
2019
node-version: ${{ matrix.node-version }}
2120
- run: npm install

browser.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
/* eslint-env browser */
22

33
const level = (() => {
4-
if (navigator.userAgentData) {
4+
if (!('navigator' in globalThis)) {
5+
return 0;
6+
}
7+
8+
if (globalThis.navigator.userAgentData) {
59
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
610
if (brand?.version > 93) {
711
return 3;
812
}
913
}
1014

11-
if (/\b(Chrome|Chromium)\//.test(navigator.userAgent)) {
15+
if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
1216
return 1;
1317
}
1418

index.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type {WriteStream} from 'node:tty';
22

3-
export interface Options {
3+
export type Options = {
44
/**
55
Whether `process.argv` should be sniffed for `--color` and `--no-color` flags.
66
77
@default true
88
*/
99
readonly sniffFlags?: boolean;
10-
}
10+
};
1111

1212
/**
1313
Levels:
@@ -21,7 +21,7 @@ export type ColorSupportLevel = 0 | 1 | 2 | 3;
2121
/**
2222
Detect whether the terminal supports color.
2323
*/
24-
export interface ColorSupport {
24+
export type ColorSupport = {
2525
/**
2626
The color level.
2727
*/
@@ -41,7 +41,7 @@ export interface ColorSupport {
4141
Whether Truecolor 16 million colors are supported.
4242
*/
4343
has16m: boolean;
44-
}
44+
};
4545

4646
export type ColorInfo = ColorSupport | false;
4747

index.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,29 @@ if (
3131
}
3232

3333
function envForceColor() {
34-
if ('FORCE_COLOR' in env) {
35-
if (env.FORCE_COLOR === 'true') {
36-
return 1;
37-
}
34+
if (!('FORCE_COLOR' in env)) {
35+
return;
36+
}
3837

39-
if (env.FORCE_COLOR === 'false') {
40-
return 0;
41-
}
38+
if (env.FORCE_COLOR === 'true') {
39+
return 1;
40+
}
41+
42+
if (env.FORCE_COLOR === 'false') {
43+
return 0;
44+
}
4245

43-
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
46+
if (env.FORCE_COLOR.length === 0) {
47+
return 1;
4448
}
49+
50+
const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
51+
52+
if (![0, 1, 2, 3].includes(level)) {
53+
return;
54+
}
55+
56+
return level;
4557
}
4658

4759
function translateLevel(level) {

index.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {stdout, stderr} from 'node:process';
22
import {expectType} from 'tsd';
3-
import supportsColor, {createSupportsColor, Options, ColorInfo} from './index.js';
3+
import supportsColor, {createSupportsColor, type Options, type ColorInfo} from './index.js';
44

55
const options: Options = {};
66

package.json

+12-8
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
},
1313
"type": "module",
1414
"exports": {
15+
"types": "./index.d.ts",
1516
"node": "./index.js",
1617
"default": "./browser.js"
1718
},
19+
"sideEffects": false,
1820
"engines": {
19-
"node": ">=12"
21+
"node": ">=18"
2022
},
2123
"scripts": {
22-
"//test": "xo && ava && tsd",
23-
"test": "tsd"
24+
"test": "xo && ava && tsd"
2425
},
2526
"files": [
2627
"index.js",
@@ -51,10 +52,13 @@
5152
"16m"
5253
],
5354
"devDependencies": {
54-
"@types/node": "^20.3.2",
55-
"ava": "^5.3.1",
56-
"import-fresh": "^3.3.0",
57-
"tsd": "^0.18.0",
58-
"xo": "^0.54.2"
55+
"@types/node": "^20.11.17",
56+
"ava": "^6.1.1",
57+
"tsd": "^0.30.4",
58+
"xo": "^0.57.0"
59+
},
60+
"ava": {
61+
"serial": true,
62+
"workerThreads": false
5963
}
6064
}

readme.md

+2-16
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
55
## Install
66

7-
```
8-
$ npm install supports-color
7+
```sh
8+
npm install supports-color
99
```
1010

1111
## Usage
@@ -73,17 +73,3 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
7373

7474
- [Sindre Sorhus](https://github.com/sindresorhus)
7575
- [Josh Junon](https://github.com/qix-)
76-
77-
---
78-
79-
<div align="center">
80-
<b>
81-
<a href="https://tidelift.com/subscription/pkg/npm-supports-color?utm_source=npm-supports-color&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
82-
</b>
83-
<br>
84-
<sub>
85-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
86-
</sub>
87-
</div>
88-
89-
---

0 commit comments

Comments
 (0)