strip-ansi 0.1.0 → 0.2.2

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.
Files changed (4) hide show
  1. package/cli.js +19 -21
  2. package/index.js +3 -1
  3. package/package.json +7 -4
  4. package/readme.md +20 -23
package/cli.js CHANGED
@@ -1,33 +1,30 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
  var fs = require('fs');
4
- var strip = require('./index');
4
+ var pkg = require('./package.json');
5
+ var strip = require('./');
5
6
  var input = process.argv[2];
6
7
 
7
-
8
- function getStdin(cb) {
9
- var ret = '';
10
-
11
- process.stdin.setEncoding('utf8');
12
-
13
- process.stdin.on('data', function (data) {
14
- ret += data;
15
- });
16
-
17
- process.stdin.on('end', function () {
18
- cb(ret);
19
- });
8
+ function help() {
9
+ console.log([
10
+ pkg.description,
11
+ '',
12
+ 'Usage',
13
+ ' $ strip-ansi <input-file> > <output-file>',
14
+ ' $ cat <input-file> | strip-ansi > <output-file>',
15
+ '',
16
+ 'Example',
17
+ ' $ strip-ansi unicorn.txt > unicorn-stripped.txt'
18
+ ].join('\n'));
20
19
  }
21
20
 
22
- if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) {
23
- console.log('strip-ansi <input file> > <output file>');
24
- console.log('or');
25
- console.log('cat <input file> | strip-ansi > <output file>');
21
+ if (process.argv.indexOf('--help') !== -1) {
22
+ help();
26
23
  return;
27
24
  }
28
25
 
29
- if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) {
30
- console.log(require('./package').version);
26
+ if (process.argv.indexOf('--version') !== -1) {
27
+ console.log(pkg.version);
31
28
  return;
32
29
  }
33
30
 
@@ -36,6 +33,7 @@ if (input) {
36
33
  return;
37
34
  }
38
35
 
39
- getStdin(function (data) {
36
+ process.stdin.setEncoding('utf8');
37
+ process.stdin.on('data', function (data) {
40
38
  process.stdout.write(strip(data));
41
39
  });
package/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  'use strict';
2
+ var ansiRegex = require('ansi-regex');
3
+
2
4
  module.exports = function (str) {
3
- return typeof str === 'string' ? str.replace(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/g, '') : str;
5
+ return typeof str === 'string' ? str.replace(ansiRegex, '') : str;
4
6
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "strip-ansi",
3
- "version": "0.1.0",
4
- "description": "Strip ANSI color codes",
3
+ "version": "0.2.2",
4
+ "description": "Strip ANSI escape codes",
5
5
  "license": "MIT",
6
6
  "bin": {
7
7
  "strip-ansi": "cli.js"
@@ -13,7 +13,7 @@
13
13
  "url": "http://sindresorhus.com"
14
14
  },
15
15
  "engines": {
16
- "node": ">=0.8.0"
16
+ "node": ">=0.10.0"
17
17
  },
18
18
  "scripts": {
19
19
  "test": "mocha"
@@ -47,7 +47,10 @@
47
47
  "command-line",
48
48
  "text"
49
49
  ],
50
+ "dependencies": {
51
+ "ansi-regex": "^0.1.0"
52
+ },
50
53
  "devDependencies": {
51
- "mocha": "~1.x"
54
+ "mocha": "*"
52
55
  }
53
56
  }
package/readme.md CHANGED
@@ -1,43 +1,40 @@
1
- # strip-ansi [![Build Status](https://secure.travis-ci.org/sindresorhus/strip-ansi.png?branch=master)](http://travis-ci.org/sindresorhus/strip-ansi)
1
+ # strip-ansi [![Build Status](https://travis-ci.org/sindresorhus/strip-ansi.svg?branch=master)](https://travis-ci.org/sindresorhus/strip-ansi)
2
2
 
3
- > Strip ANSI color codes
4
-
5
- Used in the terminal color module [chalk](https://github.com/sindresorhus/chalk).
3
+ > Strip [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code)
6
4
 
7
5
 
8
6
  ## Install
9
7
 
10
- Install locally with [npm](https://npmjs.org/package/strip-ansi):
11
-
12
- ```
13
- npm install --save strip-ansi
8
+ ```sh
9
+ $ npm install --save strip-ansi
14
10
  ```
15
11
 
16
- Or globally if you want to use it as a CLI app:
17
12
 
18
- ```
19
- npm install --global strip-ansi
20
- ```
13
+ ## Usage
21
14
 
22
- You can then use it in your Terminal like:
15
+ ```js
16
+ var stripAnsi = require('strip-ansi');
23
17
 
24
- ```
25
- strip-ansi file-with-color-codes
18
+ stripAnsi('\x1b[4mcake\x1b[0m');
19
+ //=> 'cake'
26
20
  ```
27
21
 
28
- Or pipe something to it:
29
22
 
30
- ```
31
- ls | strip-ansi
23
+ ## CLI
24
+
25
+ ```sh
26
+ $ npm install --global strip-ansi
32
27
  ```
33
28
 
29
+ ```sh
30
+ $ strip-ansi --help
34
31
 
35
- ## Example
32
+ Usage
33
+ $ strip-ansi <input-file> > <output-file>
34
+ $ cat <input-file> | strip-ansi > <output-file>
36
35
 
37
- ```js
38
- var stripAnsi = require('strip-ansi');
39
- stripAnsi('\x1b[4mcake\x1b[0m');
40
- //=> cake
36
+ Example
37
+ $ strip-ansi unicorn.txt > unicorn-stripped.txt
41
38
  ```
42
39
 
43
40