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.
The cli-width package is a simple utility that allows you to retrieve the current width of the command line interface (CLI) in which your node.js application is running. It is useful for creating CLI tools that need to format output according to the width of the terminal window.
Get CLI width
This feature allows you to get the current width of the CLI. The function returns a number representing the number of columns in the terminal, or a default value if it can't be determined.
const cliWidth = require('cli-width');
console.log(cliWidth());
Set default width
This feature allows you to set a default width that cli-width will return if it cannot determine the actual width of the terminal. This is useful for ensuring your application has a fallback width to use for formatting output.
const cliWidth = require('cli-width');
cliWidth.defaultWidth = 100;
console.log(cliWidth());
The window-size package is similar to cli-width in that it provides the dimensions of the terminal window. However, window-size offers both width and height properties, and it can also provide dimensions based on environment variables or stdout/stderr dimensions.
Term-size is another package that offers similar functionality to cli-width. It provides the size of the terminal as an object with 'columns' and 'rows'. Unlike cli-width, term-size uses a native addon to retrieve terminal dimensions, which may offer more accurate results in some environments.
Get stdout window width, with four fallbacks, tty
, output.columns
, a custom environment variable and then a default.
Tested against Node v12 to v20. Includes TypeScript types.
npm install --save cli-width
const cliWidth = require('cli-width');
cliWidth(); // maybe 204 :)
You can also set the CLI_WIDTH
environment variable.
If none of the methods are supported, and the environment variable isn't set,
the default width value is going to be 0
, that can be changed using the configurable options
.
cliWidth
can be configured using an options
parameter, the possible properties are:
0
process.stdout
require('tty')
Defining both a default width value and a stream output to try to read from:
const cliWidth = require('cli-width');
const ttys = require('ttys');
cliWidth({
defaultWidth: 80,
output: ttys.output,
});
Defines a different tty module to read width from:
const cliWidth = require('cli-width');
const ttys = require('ttys');
cliWidth({
tty: ttys,
});
npm install
npm test
Coverage can be generated with npm run coverage
.
FAQs
Get stdout window width, with two fallbacks, tty and then a default.
We found that cli-width demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.