strip-ansi 0.2.1 → 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 -7
  2. package/index.js +3 -1
  3. package/package.json +5 -2
  4. package/readme.md +11 -14
package/cli.js CHANGED
@@ -1,18 +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
- if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) {
8
- console.log('strip-ansi <input file> > <output file>');
9
- console.log('or');
10
- console.log('cat <input file> | strip-ansi > <output file>');
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'));
19
+ }
20
+
21
+ if (process.argv.indexOf('--help') !== -1) {
22
+ help();
11
23
  return;
12
24
  }
13
25
 
14
- if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) {
15
- console.log(require('./package').version);
26
+ if (process.argv.indexOf('--version') !== -1) {
27
+ console.log(pkg.version);
16
28
  return;
17
29
  }
18
30
 
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,3}(;[0-9]{1,3})*)?[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.2.1",
4
- "description": "Strip ANSI escape codes (used for colorizing strings in the terminal)",
3
+ "version": "0.2.2",
4
+ "description": "Strip ANSI escape codes",
5
5
  "license": "MIT",
6
6
  "bin": {
7
7
  "strip-ansi": "cli.js"
@@ -47,6 +47,9 @@
47
47
  "command-line",
48
48
  "text"
49
49
  ],
50
+ "dependencies": {
51
+ "ansi-regex": "^0.1.0"
52
+ },
50
53
  "devDependencies": {
51
54
  "mocha": "*"
52
55
  }
package/readme.md CHANGED
@@ -1,13 +1,11 @@
1
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 escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) (used for colorizing strings in the terminal)
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
- ```bash
8
+ ```sh
11
9
  $ npm install --save strip-ansi
12
10
  ```
13
11
 
@@ -24,23 +22,22 @@ stripAnsi('\x1b[4mcake\x1b[0m');
24
22
 
25
23
  ## CLI
26
24
 
27
- You can also use it as a CLI app by installing it globally:
28
-
29
- ```bash
25
+ ```sh
30
26
  $ npm install --global strip-ansi
31
27
  ```
32
28
 
33
- #### Usage
34
-
35
- ```bash
29
+ ```sh
36
30
  $ strip-ansi --help
37
31
 
38
- strip-ansi <input-file>
39
- or
40
- cat <input-file> | strip-ansi
32
+ Usage
33
+ $ strip-ansi <input-file> > <output-file>
34
+ $ cat <input-file> | strip-ansi > <output-file>
35
+
36
+ Example
37
+ $ strip-ansi unicorn.txt > unicorn-stripped.txt
41
38
  ```
42
39
 
43
40
 
44
41
  ## License
45
42
 
46
- [MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com)
43
+ MIT © [Sindre Sorhus](http://sindresorhus.com)