has-ansi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +53 -0
- package/index.js +4 -0
- package/package.json +57 -0
- package/readme.md +45 -0
package/cli.js
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
'use strict';
|
3
|
+
var pkg = require('./package.json');
|
4
|
+
var hasAnsi = require('./');
|
5
|
+
var input = process.argv[2];
|
6
|
+
|
7
|
+
function stdin(cb) {
|
8
|
+
var ret = '';
|
9
|
+
process.stdin.setEncoding('utf8');
|
10
|
+
process.stdin.on('data', function (data) {
|
11
|
+
ret += data;
|
12
|
+
});
|
13
|
+
process.stdin.on('end', function () {
|
14
|
+
cb(ret);
|
15
|
+
});
|
16
|
+
}
|
17
|
+
|
18
|
+
function help() {
|
19
|
+
console.log([
|
20
|
+
pkg.description,
|
21
|
+
'',
|
22
|
+
'Usage',
|
23
|
+
' $ has-ansi <string>',
|
24
|
+
' $ echo <string> | has-ansi',
|
25
|
+
'',
|
26
|
+
'Exits with code 0 if input has ANSI escape codes and 1 if not'
|
27
|
+
].join('\n'));
|
28
|
+
}
|
29
|
+
|
30
|
+
function init(data) {
|
31
|
+
process.exit(hasAnsi(data) ? 0 : 1);
|
32
|
+
}
|
33
|
+
|
34
|
+
if (process.argv.indexOf('--help') !== -1) {
|
35
|
+
help();
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
|
39
|
+
if (process.argv.indexOf('--version') !== -1) {
|
40
|
+
console.log(pkg.version);
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
|
44
|
+
if (process.stdin.isTTY) {
|
45
|
+
if (!input) {
|
46
|
+
help();
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
|
50
|
+
init(input);
|
51
|
+
} else {
|
52
|
+
stdin(init);
|
53
|
+
}
|
package/index.js
ADDED
package/package.json
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
{
|
2
|
+
"name": "has-ansi",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "Check if a string has ANSI escape codes",
|
5
|
+
"license": "MIT",
|
6
|
+
"repository": "sindresorhus/has-ansi",
|
7
|
+
"bin": {
|
8
|
+
"has-ansi": "cli.js"
|
9
|
+
},
|
10
|
+
"author": {
|
11
|
+
"name": "Sindre Sorhus",
|
12
|
+
"email": "sindresorhus@gmail.com",
|
13
|
+
"url": "http://sindresorhus.com"
|
14
|
+
},
|
15
|
+
"engines": {
|
16
|
+
"node": ">=0.10.0"
|
17
|
+
},
|
18
|
+
"scripts": {
|
19
|
+
"test": "mocha"
|
20
|
+
},
|
21
|
+
"files": [
|
22
|
+
"index.js",
|
23
|
+
"cli.js"
|
24
|
+
],
|
25
|
+
"keywords": [
|
26
|
+
"cli",
|
27
|
+
"bin",
|
28
|
+
"ansi",
|
29
|
+
"styles",
|
30
|
+
"color",
|
31
|
+
"colour",
|
32
|
+
"colors",
|
33
|
+
"terminal",
|
34
|
+
"console",
|
35
|
+
"string",
|
36
|
+
"tty",
|
37
|
+
"escape",
|
38
|
+
"shell",
|
39
|
+
"xterm",
|
40
|
+
"command-line",
|
41
|
+
"text",
|
42
|
+
"regex",
|
43
|
+
"regexp",
|
44
|
+
"re",
|
45
|
+
"match",
|
46
|
+
"test",
|
47
|
+
"find",
|
48
|
+
"pattern",
|
49
|
+
"has"
|
50
|
+
],
|
51
|
+
"dependencies": {
|
52
|
+
"ansi-regex": "^0.2.0"
|
53
|
+
},
|
54
|
+
"devDependencies": {
|
55
|
+
"mocha": "*"
|
56
|
+
}
|
57
|
+
}
|
package/readme.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# has-ansi [](https://travis-ci.org/sindresorhus/has-ansi)
|
2
|
+
|
3
|
+
> Check if a string has [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code)
|
4
|
+
|
5
|
+
|
6
|
+
## Install
|
7
|
+
|
8
|
+
```sh
|
9
|
+
$ npm install --save has-ansi
|
10
|
+
```
|
11
|
+
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```js
|
16
|
+
var hasAnsi = require('has-ansi');
|
17
|
+
|
18
|
+
hasAnsi('\u001b[4mcake\u001b[0m');
|
19
|
+
//=> true
|
20
|
+
|
21
|
+
hasAnsi('cake');
|
22
|
+
//=> false
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
## CLI
|
27
|
+
|
28
|
+
```sh
|
29
|
+
$ npm install --global has-ansi
|
30
|
+
```
|
31
|
+
|
32
|
+
```
|
33
|
+
$ has-ansi --help
|
34
|
+
|
35
|
+
Usage
|
36
|
+
$ has-ansi <string>
|
37
|
+
$ echo <string> | has-ansi
|
38
|
+
|
39
|
+
Exits with code 0 if input has ANSI escape codes and 1 if not
|
40
|
+
```
|
41
|
+
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
MIT © [Sindre Sorhus](http://sindresorhus.com)
|