-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·37 lines (30 loc) · 652 Bytes
/
cli.js
File metadata and controls
executable file
·37 lines (30 loc) · 652 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
import process from 'node:process';
import getStdin from 'get-stdin';
import meow from 'meow';
import hasAnsi from 'has-ansi';
const cli = meow(`
Usage
$ has-ansi <text>
$ echo <text> | has-ansi
Example
$ ls --color | has-ansi && echo 'has ansi'
Exits with code 0 if input has ANSI escape codes and 1 if not
`, {
importMeta: import.meta,
});
const input = cli.input[0];
function init(data) {
process.exit(hasAnsi(data) ? 0 : 1);
}
if (!input && process.stdin.isTTY) {
console.error('Input required');
process.exit(2);
}
(async () => {
if (input) {
init(input);
} else {
init(await getStdin());
}
})();