Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chalk/strip-ansi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8270705c704956da865623e564eba4875c3ea17f
Choose a base ref
...
head repository: chalk/strip-ansi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 316ff53b074b4b1465e18a35e5d792b27ecc2865
Choose a head ref

Commits on Jun 20, 2017

  1. Require Node.js 4

    sindresorhus committed Jun 20, 2017
    Copy the full SHA
    0978944 View commit details
  2. Bump ansi-regex

    sindresorhus committed Jun 20, 2017

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    740dac9 View commit details
  3. 4.0.0

    sindresorhus committed Jun 20, 2017

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c299056 View commit details

Commits on Sep 20, 2017

  1. Copy the full SHA
    52dcf65 View commit details

Commits on Sep 29, 2018

  1. Copy the full SHA
    e8d149c View commit details
  2. Copy the full SHA
    6a25566 View commit details
  3. 5.0.0

    sindresorhus committed Sep 29, 2018
    Copy the full SHA
    dfab677 View commit details

Commits on Dec 25, 2018

  1. Add security section

    sindresorhus authored Dec 25, 2018
    Copy the full SHA
    841f0c4 View commit details

Commits on Mar 8, 2019

  1. Copy the full SHA
    41b0a8b View commit details
  2. 5.1.0

    sindresorhus committed Mar 8, 2019
    Copy the full SHA
    581fd4e View commit details
  3. Fix readme (#27)

    LitoMore authored and sindresorhus committed Mar 8, 2019
    Copy the full SHA
    5cb7e20 View commit details

Commits on Mar 18, 2019

  1. Copy the full SHA
    89dc7f6 View commit details
  2. Meta tweaks

    sindresorhus committed Mar 18, 2019
    Copy the full SHA
    81cd3cc View commit details
  3. 5.2.0

    sindresorhus committed Mar 18, 2019
    Copy the full SHA
    b9c4929 View commit details

Commits on May 31, 2019

  1. Tidelift tasks

    sindresorhus committed May 31, 2019
    Copy the full SHA
    a022f23 View commit details

Commits on Oct 30, 2019

  1. Tidelift tasks

    sindresorhus committed Oct 30, 2019
    Copy the full SHA
    57878e2 View commit details

Commits on Nov 9, 2019

  1. Require Node.js 8

    Closes #29
    sindresorhus committed Nov 9, 2019
    Copy the full SHA
    976f459 View commit details
  2. 6.0.0

    sindresorhus committed Nov 9, 2019
    Copy the full SHA
    59533da View commit details

Commits on Nov 20, 2020

  1. Copy the full SHA
    0a6e98d View commit details

Commits on Dec 2, 2020

  1. Move to GitHub Actions

    sindresorhus committed Dec 2, 2020
    1
    Copy the full SHA
    601423d View commit details

Commits on Dec 16, 2020

  1. Add @Qix- to funding.yml

    sindresorhus authored Dec 16, 2020
    Copy the full SHA
    d6d1128 View commit details

Commits on Apr 16, 2021

  1. Copy the full SHA
    7cda68d View commit details
  2. 7.0.0

    sindresorhus committed Apr 16, 2021
    Copy the full SHA
    316ff53 View commit details
Showing with 144 additions and 102 deletions.
  1. +1 −4 .editorconfig
  2. +1 −1 .gitattributes
  3. +2 −0 .github/funding.yml
  4. +3 −0 .github/security.md
  5. +21 −0 .github/workflows/main.yml
  6. +1 −0 .gitignore
  7. +1 −0 .npmrc
  8. +0 −6 .travis.yml
  9. +15 −0 index.d.ts
  10. +8 −5 index.js
  11. +4 −0 index.test-d.ts
  12. +5 −17 license
  13. +55 −55 package.json
  14. +18 −10 readme.md
  15. +9 −4 test.js
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
2 changes: 2 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [sindresorhus, Qix-]
tidelift: npm/strip-ansi
3 changes: 3 additions & 0 deletions .github/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 14
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

15 changes: 15 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
@example
```
import stripAnsi from 'strip-ansi';
stripAnsi('\u001B[4mUnicorn\u001B[0m');
//=> 'Unicorn'
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
//=> 'Click'
```
*/
export default function stripAnsi(string: string): string;
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';
var ansiRegex = require('ansi-regex')();
import ansiRegex from 'ansi-regex';

module.exports = function (str) {
return typeof str === 'string' ? str.replace(ansiRegex, '') : str;
};
export default function stripAnsi(string) {
if (typeof string !== 'string') {
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
}

return string.replace(ansiRegex(), '');
}
4 changes: 4 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {expectType} from 'tsd';
import stripAnsi from './index.js';

expectType<string>(stripAnsi('\u001B[4mcake\u001B[0m'));
22 changes: 5 additions & 17 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
110 changes: 55 additions & 55 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
{
"name": "strip-ansi",
"version": "3.0.1",
"description": "Strip ANSI escape codes",
"license": "MIT",
"repository": "chalk/strip-ansi",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"maintainers": [
"Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
"Joshua Boy Nicolai Appelman <joshua@jbna.nl> (jbna.nl)",
"JD Ballard <i.am.qix@gmail.com> (github.com/qix-)"
],
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"strip",
"trim",
"remove",
"ansi",
"styles",
"color",
"colour",
"colors",
"terminal",
"console",
"string",
"tty",
"escape",
"formatting",
"rgb",
"256",
"shell",
"xterm",
"log",
"logging",
"command-line",
"text"
],
"dependencies": {
"ansi-regex": "^2.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "strip-ansi",
"version": "7.0.0",
"description": "Strip ANSI escape codes from a string",
"license": "MIT",
"repository": "chalk/strip-ansi",
"funding": "https://github.com/chalk/strip-ansi?sponsor=1",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"strip",
"trim",
"remove",
"ansi",
"styles",
"color",
"colour",
"colors",
"terminal",
"console",
"string",
"tty",
"escape",
"formatting",
"rgb",
"256",
"shell",
"xterm",
"log",
"logging",
"command-line",
"text"
],
"dependencies": {
"ansi-regex": "^6.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
28 changes: 18 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
# strip-ansi [![Build Status](https://travis-ci.org/chalk/strip-ansi.svg?branch=master)](https://travis-ci.org/chalk/strip-ansi)

> Strip [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code)
# strip-ansi

> Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string
## Install

```
$ npm install --save strip-ansi
$ npm install strip-ansi
```


## Usage

```js
var stripAnsi = require('strip-ansi');
import stripAnsi from 'strip-ansi';

stripAnsi('\u001B[4mUnicorn\u001B[0m');
//=> 'Unicorn'

stripAnsi('\u001b[4mcake\u001b[0m');
//=> 'cake'
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
//=> 'Click'
```

## strip-ansi for enterprise

Available as part of the Tidelift Subscription.

The maintainers of strip-ansi and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-strip-ansi?utm_source=npm-strip-ansi&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)

## Related

- [strip-ansi-cli](https://github.com/chalk/strip-ansi-cli) - CLI for this module
- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Streaming version of this module
- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right

## Maintainers

## License
- [Sindre Sorhus](https://github.com/sindresorhus)
- [Josh Junon](https://github.com/qix-)

MIT © [Sindre Sorhus](http://sindresorhus.com)
13 changes: 9 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import test from 'ava';
import fn from './';
import stripAnsi from './index.js';

test('strip color from string', t => {
t.is(fn('\u001b[0m\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24mfoo\u001b[0m'), 'foofoo');
t.is(stripAnsi('\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m'), 'foofoo');
});

test('strip color from ls command', t => {
t.is(fn('\u001b[00;38;5;244m\u001b[m\u001b[00;38;5;33mfoo\u001b[0m'), 'foo');
t.is(stripAnsi('\u001B[00;38;5;244m\u001B[m\u001B[00;38;5;33mfoo\u001B[0m'), 'foo');
});

test('strip reset;setfg;setbg;italics;strike;underline sequence from string', t => {
t.is(fn('\x1b[0;33;49;3;9;4mbar\x1b[0m'), 'bar');
t.is(stripAnsi('\u001B[0;33;49;3;9;4mbar\u001B[0m'), 'bar');
});

test('strip link from terminal link', t => {
t.is(stripAnsi('\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'), 'click');
});