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/has-ansi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0722275e1bef139fcd09137da6e5550c3cd368b9
Choose a base ref
...
head repository: chalk/has-ansi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e0482ff90bc06ba2ab5fe6e06ce6a5b74d15c545
Choose a head ref
  • 11 commits
  • 13 files changed
  • 3 contributors

Commits on Jun 30, 2015

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    4d4def8 View commit details

Commits on Jul 1, 2015

  1. added Qix as maintainer

    Qix- committed Jul 1, 2015
    Copy the full SHA
    77fd627 View commit details

Commits on Aug 24, 2015

  1. add XO

    sindresorhus committed Aug 24, 2015
    Copy the full SHA
    8265d04 View commit details

Commits on Jan 1, 2016

  1. Copy the full SHA
    82a887c View commit details

Commits on Feb 21, 2016

  1. Updates maintainer email.

    jbnicolai committed Feb 21, 2016
    Copy the full SHA
    d4c3315 View commit details

Commits on Jun 20, 2017

  1. Require Node.js 4

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

    sindresorhus committed Jun 20, 2017
    Copy the full SHA
    7ba9550 View commit details
  3. 3.0.0

    sindresorhus committed Jun 20, 2017
    Copy the full SHA
    5b1f1e1 View commit details

Commits on Sep 10, 2019

  1. Tidelift tasks

    sindresorhus committed Sep 10, 2019
    Copy the full SHA
    cc62ac2 View commit details
  2. Require Node.js 8

    sindresorhus committed Sep 10, 2019
    Copy the full SHA
    5922c60 View commit details
  3. 4.0.0

    sindresorhus committed Sep 10, 2019
    Copy the full SHA
    e0482ff View commit details
Showing with 101 additions and 111 deletions.
  1. +1 −4 .editorconfig
  2. +1 −1 .gitattributes
  3. +2 −0 .github/funding.yml
  4. +3 −0 .github/security.md
  5. +1 −0 .gitignore
  6. +0 −12 .jshintrc
  7. +1 −0 .npmrc
  8. +3 −4 .travis.yml
  9. +6 −3 index.js
  10. +4 −16 license
  11. +49 −53 package.json
  12. +25 −11 readme.md
  13. +5 −7 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
tidelift: npm/has-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.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
12 changes: 0 additions & 12 deletions .jshintrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sudo: false
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'
- '12'
- '10'
- '8'
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';
var ansiRegex = require('ansi-regex');
var re = new RegExp(ansiRegex().source); // remove the `g` flag
module.exports = re.test.bind(re);
const ansiRegex = require('ansi-regex');

// Removes the `g` flag
const regex = new RegExp(ansiRegex().source);

module.exports = string => regex.test(string);
20 changes: 4 additions & 16 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)

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.
102 changes: 49 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,51 @@
{
"name": "has-ansi",
"version": "2.0.0",
"description": "Check if a string has ANSI escape codes",
"license": "MIT",
"repository": "sindresorhus/has-ansi",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"maintainers": [
"Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
"Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)"
],
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "node test.js"
},
"files": [
"index.js"
],
"keywords": [
"ansi",
"styles",
"color",
"colour",
"colors",
"terminal",
"console",
"string",
"tty",
"escape",
"shell",
"xterm",
"command-line",
"text",
"regex",
"regexp",
"re",
"match",
"test",
"find",
"pattern",
"has"
],
"dependencies": {
"ansi-regex": "^2.0.0"
},
"devDependencies": {
"ava": "0.0.4"
}
"name": "has-ansi",
"version": "4.0.0",
"description": "Check if a string has ANSI escape codes",
"license": "MIT",
"repository": "chalk/has-ansi",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"ansi",
"styles",
"color",
"colour",
"colors",
"terminal",
"console",
"string",
"tty",
"escape",
"shell",
"xterm",
"command-line",
"text",
"regex",
"regexp",
"match",
"test",
"find",
"pattern",
"has"
],
"dependencies": {
"ansi-regex": "^4.1.0"
},
"devDependencies": {
"ava": "^2.3.0",
"xo": "^0.24.0"
}
}
36 changes: 25 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# has-ansi [![Build Status](https://travis-ci.org/sindresorhus/has-ansi.svg?branch=master)](https://travis-ci.org/sindresorhus/has-ansi)
# has-ansi [![Build Status](https://travis-ci.org/chalk/has-ansi.svg?branch=master)](https://travis-ci.org/chalk/has-ansi)

> Check if a string has [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code)
> Check if a string has [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)

## Install

```
$ npm install --save has-ansi
$ npm install has-ansi
```


## Usage

```js
var hasAnsi = require('has-ansi');
const hasAnsi = require('has-ansi');

hasAnsi('\u001b[4mcake\u001b[0m');
hasAnsi('\u001B[4mUnicorn\u001B[0m');
//=> true

hasAnsi('cake');
@@ -25,12 +25,26 @@ hasAnsi('cake');

## Related

- [has-ansi-cli](https://github.com/sindresorhus/has-ansi-cli) - CLI for this module
- [strip-ansi](https://github.com/sindresorhus/strip-ansi) - Strip ANSI escape codes
- [ansi-regex](https://github.com/sindresorhus/ansi-regex) - Regular expression for matching ANSI escape codes
- [chalk](https://github.com/sindresorhus/chalk) - Terminal string styling done right
- [has-ansi-cli](https://github.com/chalk/has-ansi-cli) - CLI for this module
- [strip-ansi](https://github.com/chalk/strip-ansi) - Strip 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


## License
## Maintainers

MIT © [Sindre Sorhus](http://sindresorhus.com)
- [Sindre Sorhus](https://github.com/sindresorhus)
- [Josh Junon](https://github.com/qix-)


---

<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-has-ansi?utm_source=npm-has-ansi&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
12 changes: 5 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';
var test = require('ava');
var hasAnsi = require('./');
import test from 'ava';
import hasAnsi from '.';

test(function (t) {
t.assert(hasAnsi('foo\u001b[4mcake\u001b[0m'));
t.assert(!hasAnsi('cake'));
t.end();
test('main', t => {
t.true(hasAnsi('foo\u001B[4mcake\u001B[0m'));
t.false(hasAnsi('cake'));
});