Giter VIP home page Giter VIP logo

strip-ansi's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

strip-ansi's Issues

suggestion: offer a "default" export option to increase compatibility with es6

when coding in typescript, using an es6 or exnext module backend, the suggested

import stripAnsi = require('strip-ansi')

is not allowed

error TS1202: Import assignment cannot be used when targeting ECMAScript modules

an option, in these cases, is to use instead

import * as stripAnsi from 'strip-ansi'

but this requires that one's entire project be compiled with allowSyntheticDefaultImports, which has fairly wide-ranging implications on the code base, especially with regards to dynamic imports.

might i suggest that strip-ansi offer e.g. an es6.js whose content is something like:

https://github.com/starpit/strip-ansi/blob/es6/es6.js
https://github.com/starpit/strip-ansi/blob/es6/es6.d.ts

which would allow

import stripAnsi from 'strip-ansi/es6'

ie11 does not work

It does not work on ie11.
It can be used after modifying the arrow function to a general function.

module.exports = input => typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
work after modified
module.exports = function(input) { return typeof input === 'string' ? input.replace(ansiRegex(), '') : input; }

bump version to 1.x

According to the semver spec, anything with a 0.x version number is by-definition unstable and can change its public API at any time.

Can you please update this to 1.0.0 if you don't plan on changing the API randomly?

There's a Regular Expression Denial of Service vulnerability in the ansi-regex package in versions < 6.0.1:

The dependencies from this package that use out of date versions that I see are:
| -- [email protected] | -- [email protected]

image

Fix version is 6.0.1.

Team Can you please check this
As I have other packages they are also using strip-ansi version 6.0.1. As strip-anis version 7.0 using ESM and their pacakges
using CJS so it is difficult to update strip-ansi to version 7.
It would be great if [email protected] update their ansi-regex to version 6.0.1.

Does not strip `ESC ]0;<TEXT> BEL`

According to https://en.wikipedia.org/wiki/ANSI_escape_code#OSC_(Operating_System_Command)_sequences, '\x1B]0;<TEXT>\x07' sequence should be stripped.

Current behavior:

stripAnsi('\x1B[2J\x1B[m\x1B[HABC\r\n\x1B]0;C:\\WINDOWS\\system32\\cmd.exe\x07\x1B[?25h')
//=> 'ABC\r\n:\\WINDOWS\\system32\\cmd.exe\x07'

Expected behavior:

stripAnsi('\x1B[2J\x1B[m\x1B[HABC\r\n\x1B]0;C:\\WINDOWS\\system32\\cmd.exe\x07\x1B[?25h')
//=> 'ABC\r\n'

strip-ansi version: 7.0.1
os: Windows

Not stripping object after stringify

I'm having a super weird issue. I have this object that is has computed keys. I have things that I want to highlight in this object so it has chalk colors on some keys. This works great.
My object

let stats = {
    [user.name]: {
      Name: chalk.cyan(user['name'])
     //other properties
    }
  };

I want to print these values to a file and would like to strip the ANSI. However, the strip function does not seem to be working.

Here is what I'm using to print to file.

let stripped = stripAnsi(JSON.stringify(stats,null,2));
fs.writeFile('./stats.json', stripped, function(err) {
  if (err) {
    return console.log(err);
  }
  console.log('Stats saved to file!');
});

The output looks like this

{
  "John": {
    "Name": "\u001b[36mJohn\u001b[39m"
  }
}

I did some debugging and the string checks in strip-ansi seem to be working. I thought you might have a better idea of what exactly is happening.

Thanks!

Incomplete support for XTerm escape codes

Many Unix terminals follow "XTerm escape codes". I refer to the "rxvt_reference" manpage, available on Debian Jessie as man 7 urxvt when the rxvt-unicode package is installed:

   XTerm Operating System Commands
       "ESC ] Ps;Pt ST"
           Set XTerm Parameters. 8-bit ST: 0x9c, 7-bit ST sequence: ESC \
           (0x1b, 0x5c), backwards compatible terminator BEL (0x07) is also
           accepted. any octet can be escaped by prefixing it with SYN (0x16,
           ^V).

           Ps = 0     Change Icon Name and Window Title to Pt
           Ps = 1     Change Icon Name to Pt
           Ps = 2     Change Window Title to Pt
...

So, for example, the sequence \033]2;example\007 will change the terminal's title to "example" and not use any of the character cells in the terminal itself.

This could be represented as a (non-passing) test:

t.is(m('\033]2;example\007'), '')

and similar for the ST sequences '\033\' and '\x9c' though to be honest I'm not sure whether the 8-bit '\x9c' even makes sense in UTF-8 world or can be expressed in javascript unicode strings.since it is only valid as a continuation byte in the UTF-8 encoding; it can probably be ignored.

Note: I originally filed this as sindresorhus/string-width#7 but that author requested that I file it here instead.

incomplete stripping?

i have an example JSON fragment that, when i cat thisInput | jq and then try to strip-clean the output of jq, i am left with ANSI bits. it seems to come from certain cases where the control characters span lines? not entirely sure yet what the root cause is, but i've isolated it down to this example snippet of the larger JSON. fwiw xtermjs seems to handle this ok.

[
  {
    "description"[39;49;00m[1;39m: "hello strip-ansi.",
    "displayName": "Status Details",
    "path": "reason",
    "x-descriptors": [
     "snnipy"
    ]
  },
  {
    "description": "hello again.",
    "displayName": "Member Status",
    "path": "members",
    "x-descriptors": [
      "snappy"
    ]
  };39m
]                           

Add notes about non-esm version in readme

ESM breaks some build configurations, e.g. I was getting the following with a ts-node based configuration all of the sudden (and it doesn't even point to strip-ansi, it points to my own typescript files! only difference being if I'm importing strip-ansi or not)

 TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"

Consequently, I've had to revert to 3.0.0 for the meanwhile.

I'd request that a note mentioning the latest non-ESM version should be present in the documentation so that we can still work with the library until build systems are upgraded to acommodate ESM.

Support streams

Would be nice to remove ansi from streams, for example for people wanting to pipe from stdout to a file without the mess of colour codes.

set title mode escape codes not stripped

Hello,

according to links below, the following sequence instruct the terminal to set window title and icon:

\u001b]0;sg@tota:~/git/\u0007

and strip-ansi is not removing it

In other words I expect

stripAnsi('\u001b]0;sg@tota:~/git/\u0007\u001b[01;32m[sg@tota\u001b[01;37m misc-tests\u001b[01;32m]$') 

to return the string:

[sg@tota misc-tests]$

This is very common in xterm based linux stdout to print the prompt. Thanks BTW this is great project! keep it up!

References:
http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Title-Modes
https://unix.stackexchange.com/questions/288996/what-u001b0kubajcubic-u0007-escape-code-do

import * as stripAnsi from "strip-ansi";

I tried to import stripAnsi with import * as stripAnsi from "strip-ansi"; in a TypeScript-Node.js application but this fails with the error message Module '"/.../node_modules/@types/strip-ansi/index"' resolves to a non-module entity and cannot be imported using this construct.. The issue seems to be that a function is exported (see e.g. microsoft/TypeScript#5867 (comment)). Would it be possible to change that to something consumable by TypeScript? Or is there any other way I might get this to work?
I know that this module isn't doing much and that I can easily write such a function on my own but I thought maybe other people are going to have the same issue as well so maybe we can try to find a solution for it.

Error when starting a ts program in ts-node

I've made a mini JS program and started to migrate it to TS.

Code:

import chalk from 'chalk';
import stripAnsi from 'strip-ansi';
...

TSconfig:

{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */
    "target": "es5",                                /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
    "module": "commonjs",                           /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "allowJs": true,                             /* Allow javascript files to be compiled. */
    "outDir": "./build",                              /* Redirect output structure to the directory. */
    "rootDir": "./src",                             /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    "strict": true,                                 /* Enable all strict type-checking options. */
    "esModuleInterop": true,                        /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    "skipLibCheck": true,                           /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true        /* Disallow inconsistently-cased references to the same file. */
  }
}

Error:

Error: Must use import to load ES Module: C:\Users\ilja\Desktop\Projects\Development\Other\Plugins\steam-cloud-sync\node_modules\strip-ansi\index.js
require() of ES modules is not supported.
require() of C:\Users\ilja\Desktop\Projects\Development\Other\Plugins\steam-cloud-sync\node_modules\strip-ansi\index.js from C:\Users\ilja\Desktop\Projects\Development\Other\Plugins\steam-cloud-sync\src\logger.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES mo
dules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\ilja\Desktop\Projects\Development\Other\Plugins\steam-cloud-sync\node_modules\strip-ansi\package.json.

    at new NodeError (node:internal/errors:370:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:13)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:816:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (C:\Users\ilja\Desktop\Projects\Development\Other\Plugins\steam-cloud-sync\src\logger.js:43:36)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)

Unable to install

I thought this was a local problem untill I saw the NPM download stats.

Page: https://www.npmjs.com/package/strip-ansi

0 downloads in the last day <-- What?
7,881,216 downloads in the last week
32,726,462 downloads in the last month

I just tried to download from npm on a Windows machine and it worked. On my Debian machine I get the following error:

npm ERR! path /home/grant/node-console-probe/node_modules/npm/node_modules/dezalgo
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/home/grant/node-console-probe/node_modules/npm/node_modules/dezalgo' -> '/home/grant/node-console-probe/node_modules/npm/node_modules/.dezalgo.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/grant/.npm/_logs/2018-01-25T00_29_40_604Z-debug.log

I don't really know if this just a local issue or not. I am only posting this issue because of the zero downloads in the last day stat.

[Feature Request] Add ability to only strip some ANSI codes

I'm working on a CLI E2E testing library that I would love to add the ability to "pretty print" output all of stdout to the console when a test implementation requests.

This would include keeping ANSI codes when present, but removing the ones that would clear the screen (to help with the debug process)

Adding in the ability to pass the codes to strip would help a lot in this regard. Happy to submit a PR

License not readable

Hi
I'm working on a project where a package uses your library
Now that we are testing the pipeline we have started getting errors related to the package license file

[ERROR] The IQ Server reports policy failing due to 
Policy(License-None) [
 Component(displayName=strip-ansi-cjs : 6.0.1, hash=849ff8d01283d89e19c0) [
  Constraint(Contact Sonatype Support - declared license issue: Not Provided) [License is 'Not Supported' because: Found 'Not Supported' license, on condition 0, License is 'Not Provided' because: Found 'Not Provided' license, on condition 0] ]]
[ERROR] The IQ Server reports policy failing due to 
Policy(License-None) [
 Component(displayName=string-width-cjs : 4.2.3, hash=e621da8847ceb2f46d3f) [
  Constraint(Contact Sonatype Support - declared license issue: Not Provided) [License is 'Not Supported' because: Found 'Not Supported' license, on condition 0, License is 'Not Provided' because: Found 'Not Provided' license, on condition 0] ]]
[ERROR] The IQ Server reports policy failing due to 
Policy(License-None) [
 Component(displayName=wrap-ansi-cjs : 7.0.0, hash=feb65f52a9f9713d5c12) [
  Constraint(Contact Sonatype Support - declared license issue: Not Provided) [License is 'Not Supported' because: Found 'Not Supported' license, on condition 0, License is 'Not Provided' because: Found 'Not Provided' license, on condition 0] ]]
[WARN] The IQ Server reports policy warning due to 

I have used Gemini to see if there was any problem with the license file and got this answer
image

While asking for example to check the one from Vue, I got the answer
image

Thanks

Pure ESM issues

Hi 👋 @sindresorhus,

I'm working a Node (v14.17.3) command line tool which uses this library and tried updating it from version v5.2.0 to v7.0.0.

I've read this and decided to give it a try by changing my project as described in the How can I move my CommonJS project to ESM? guideline, but then other libraries started complaining for not supporting ESM.

So how would I go about using the latest version of this library in my Node app/script?

Thank you for your work, your contribution to the space is amazing.

npm ERR! Error: EROFS, symlink '../strip-ansi/cli.js'

Hi, I got this while trying to install "elasticsearch":

root@ubuntu:~/babasard/web-server# npm install elasticsearch
npm WARN package.json [email protected] No description
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm http GET https://registry.npmjs.org/elasticsearch
npm http 304 https://registry.npmjs.org/elasticsearch
npm http GET https://registry.npmjs.org/chalk
npm http 304 https://registry.npmjs.org/chalk
npm http GET https://registry.npmjs.org/strip-ansi
npm http 304 https://registry.npmjs.org/strip-ansi
npm ERR! Error: EROFS, symlink '../strip-ansi/cli.js'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Linux 3.5.0-23-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "elasticsearch"
npm ERR! cwd /media/sf_project_babasard/web-server
npm ERR! node -v v0.10.18
npm ERR! npm -v 1.3.8
npm ERR! path ../strip-ansi/cli.js
npm ERR! code EROFS
npm ERR! errno 56
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /media/sf_project_babasard/web-server/npm-debug.log
npm ERR! not ok code 0

Also trying to install it directly:

root@ubuntu:~/babasard/web-server# npm install --save strip-ansi
npm WARN package.json [email protected] No description
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm http GET https://registry.npmjs.org/strip-ansi
npm http 304 https://registry.npmjs.org/strip-ansi
npm ERR! Error: EROFS, symlink '../strip-ansi/cli.js'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Linux 3.5.0-23-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "--save" "strip-ansi"
npm ERR! cwd /media/sf_project_babasard/web-server
npm ERR! node -v v0.10.18
npm ERR! npm -v 1.3.8
npm ERR! path ../strip-ansi/cli.js
npm ERR! code EROFS
npm ERR! errno 56
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /media/sf_project_babasard/web-server/npm-debug.log
npm ERR! not ok code 0

Any thought about that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.