Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
🤖 Parse ansi into an array of ansi-tags and text-chunks.
Parse-ANSI takes an ANSI string as input:
const text = "🤖\u001B[31m DANGER\u001B[0m Will Robbinson"
console.log(text)
When you run your text through the ANSI parser...
const parseAnsi = require('parse-ansi')
const parsed = parseAnsi(text)
console.log(parsed)
...Parse-ANSI outputs value, position and style data.
{
raw: '🤖\u001B[31m DANGER\u001B[0m Will Robbinson',
plain: '🤖 DANGER Will Robbinson',
textArea: {columns: 24, rows: 1},
chunks: [{
type: 'text',
value: '🤖',
position: {x: 0, y: 0, n: 0, raw: 0},
style: {}
}, {
type: 'ansi',
value: {tag: 'red', ansi: '\u001b[31m'},
position: {x: 2, y: 0, n: 2, raw: 2}
}, {
type: 'text',
value: ' DANGER',
position: {x: 2,y: 0,n: 2, raw: 7},
style: {
foregroundColor: 'red'
}
}, {
type: 'ansi',
value: {tag: 'reset', ansi: '\u001b[0m'},
position: {x: 9, y: 0, n: 9, raw: 14}
}, {
type: 'text',
value: ' Will Robbinson',
position: {x: 9, y: 0, n: 9, raw: 18},
style: {}
}]
}
This data can be used to convert ANSI sequences to other formatsm such as HTML, Image, SVG, etc.
Each object in the output array is called a "chunk". Each chunk represents one or more of the following data types.
ansi
- ANSI escape sequencenewline
- Newline charactertext
- Text chunk of like-stylesThe style object contains a list of styles associated with the current chunk. Each style represents an ANSI Escape sequence that is mapped to friendly name called an ANSI-Tag
.
The following style object describes a chunk of red text:
{
foregroundColor: 'red'
}
This object shows alls styles in combination:
{
backgroundColor: 'bgRed',
foregroundColor: 'white',
dim: true,
bold: true,
italic: true,
underline: true,
strikethrough: true,
inverse: true
}
Styles that are closed or reset are not included in the style object.
For example:
// Turn on Bold
const text = '\u001b[1m BOLD' +
// Turn off all styles
'\u001b[0m NORMAL'
const parsed = parseAnsi(text)
const styles = parsed
.filter(chunk => chunk.style)
.map(chunk => chunk.style)
console.log(styles)
The above code should log:
[
// Turn on Bold
{ bold: true },
// Turn off all styles
{}
]
{x: 2, y: 0, n: 2, raw: 2}
The position object contains 4 kinds of position:
x
- Plain-text column at which the chunk startsy
- Plain-text crow at which the chunk startsn
- Linear, 1-dimensional plain-text position at which the chunk starts.raw
- Linear 1-dimensional position at which the chunk starts for ANSI or plain-text. This is the real JavaScript position string position of the chunk.The value of a text
chunk is a JavaScript string. The value of a text chunk should never contain any ANSI escape sequences.
{
type: 'text',
value: ' DANGER',
}
The value of an ansi
chunk is an object.
value.tag
- Friendly-named ansi-tag.value.ansi
- Raw ANSI string value.{
type: 'ansi',
value: {
tag: 'red',
ansi: '\u001b[31m'
}
}
You can find the list ansi-tags in types/types.ansi-seqs-to-ansi-tags.js.
$ yarn add parse-ansi
FAQs
🤖 Parse ANSI text into an array of ansi-tags and text-chunks.
The npm package parse-ansi receives a total of 80 weekly downloads. As such, parse-ansi popularity was classified as not popular.
We found that parse-ansi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.