Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
short-ansi
This package allows you to easily mix and match ANSI terminal color/formatting to make it easier to style your output logs.
To use short-ansi
, start by creating a session:
let a = require('short-ansi')();
From there you can immediately generate formatting codes by accessing properties of your short-ansi
session:
console.log(a.ut + "This text is underlined and bold" + a.e + " and this is not");
The name of the property you access gets parsed by the session (a JavaScript proxy) to create the formatting codes dynamically, and each character of that name represents a command or parameter.
There is also another, nicer way to use short-ansi
, using JavaScript template strings. A short-ansi
session, along with being a proxy, is also a function that can parse template strings and format them automatically:
console.log(a`\{ut This text is underlined and bold\} and this is not`);
Notice how our session a
is prepended to the template string. This tells JavaScript to use our session as a parser for the template string.
When short-ansi
parses your template strings, it looks for matching escaped brackets and applies styles within them. Normally, escaped brackets would just be converted into normal brackets, but short-ansi
actually parses the raw text inside the string. The first non-space characters inside a set of brackets determine the formatting to apply to the text inside the brackets (ut
in this example), which is then followed by a space and the text you want to format. Then after the closing bracket of the set, the formatting of the string is returned to its previous state. This means that you can actually nest formatting inside template strings:
console.log(a`\{u This text is underlined \{t and this is also bold\} and this is just underlined again\}`);
console.log(a`\{rt This is red and bold \{e this is normal\} and this is red and bold again\}`);
Because we are using template strings, we can still use string interpolation too:
let someText = "This will be printed in red";
console.log(a`Value of 'someText': \{r ${someText}\}`);
short-ansi
has one last feature: presets. You can define and use a preset just like so:
a.p1 = a.utr;
console.log(a`\{p1 This is underlined, bold, and red\}`);
Presets are numbered and prefixed with a p
, and are unique to each session.
If you have any confusion about what the color commands do, Wikipedia has some good documentation.
Command | Type | Description | Parameters |
---|---|---|---|
, | no-op | used for readability | (none) |
e | reset | reset all formatting (end) | (none) |
u | style | underline | (none) |
t | style | bold (thick) | (none) |
s | style | faint (slim) | (none) |
i | style | italic | (none) |
f[n] | style | font | f : font number |
d | basic color | black (dark) | (none) |
r | basic color | red | (none) |
g | basic color | green | (none) |
y | basic color | yellow | (none) |
b | basic color | blue | (none) |
m | basic color | magenta | (none) |
c | basic color | cyan | (none) |
w | basic color | white | (none) |
q[n] | color | 8-bit color cube (qube) | n : color cube number |
a[r]_[g]_[b] | color | 24-bit rgb (all colors) | r : red, g : green, b : blue |
l[c] | color modifier | brighten (lighten) | c : basic color |
h[c] | color modifier | background (highlight) | c : any color or brightened color |
n[c] | modifier | not | c : any of utsidrgybmcwqah |
p[n] | preset | preset | n : preset number |
Note: the "not" (n
) command takes a single character without any extra parameters. For example, nq30
is not valid because q
is used as a raw parameter instead of as a command, and 30
isn't a known command. Conversely, q30
is valid, because 30
is used as q
's parameter. Also, when paired with a style, the "not" command will reset that style specifically, but when paired with h
or any color command, it will reset the background color or foreground color, respectively.
FAQs
A package to make styling terminal output easier and simpler
The npm package short-ansi receives a total of 0 weekly downloads. As such, short-ansi popularity was classified as not popular.
We found that short-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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.