Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81159 views
1
#!/usr/bin/env node
2
'use strict';
3
var fs = require('fs');
4
var pkg = require('./package.json');
5
var stripAnsi = require('./');
6
var argv = process.argv.slice(2);
7
var input = argv[0];
8
9
function help() {
10
console.log([
11
'',
12
' ' + pkg.description,
13
'',
14
' Usage',
15
' strip-ansi <input-file> > <output-file>',
16
' cat <input-file> | strip-ansi > <output-file>',
17
'',
18
' Example',
19
' strip-ansi unicorn.txt > unicorn-stripped.txt'
20
].join('\n'));
21
}
22
23
function init(data) {
24
process.stdout.write(stripAnsi(data));
25
}
26
27
if (argv.indexOf('--help') !== -1) {
28
help();
29
return;
30
}
31
32
if (argv.indexOf('--version') !== -1) {
33
console.log(pkg.version);
34
return;
35
}
36
37
if (!input && process.stdin.isTTY) {
38
help();
39
return;
40
}
41
42
if (input) {
43
init(fs.readFileSync(input, 'utf8'));
44
} else {
45
process.stdin.setEncoding('utf8');
46
process.stdin.on('data', init);
47
}
48
49