Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
single-line-log
Advanced tools
Keep writing to the same line in the terminal. Very useful when you write progress bars, or a status message during longer operations
The single-line-log npm package allows you to log messages to the console on a single line, overwriting the previous message. This is particularly useful for creating progress bars, status updates, or any other scenario where you want to update the console output without cluttering it with multiple lines.
Basic Single Line Logging
This feature allows you to log messages on a single line, overwriting the previous message. The code sample demonstrates logging 'Loading...', then 'Still loading...' after 1 second, and finally 'Done!' after 2 seconds.
const log = require('single-line-log').stdout;
log('Loading...');
setTimeout(() => log('Still loading...'), 1000);
setTimeout(() => log('Done!'), 2000);
Progress Bar
This feature is useful for creating a progress bar. The code sample shows a progress bar that updates every second, increasing the progress by 10% each time until it reaches 100%.
const log = require('single-line-log').stdout;
let progress = 0;
const interval = setInterval(() => {
progress += 10;
log(`Progress: ${progress}%`);
if (progress >= 100) clearInterval(interval);
}, 1000);
The cli-progress package provides a more advanced and customizable progress bar for command-line interfaces. It offers multiple progress bars, different bar styles, and more control over the appearance and behavior of the progress bars. Compared to single-line-log, cli-progress is more feature-rich and suitable for more complex use cases.
The ora package is a terminal spinner that provides a simple way to display a spinner while performing asynchronous tasks. It supports different spinner styles and colors, and can be used to indicate ongoing operations. While single-line-log focuses on overwriting a single line, ora provides a more visually appealing way to show progress or status updates.
The progress package is another option for creating progress bars in the terminal. It offers a simple API for creating and updating progress bars, with support for custom tokens and formatting. Compared to single-line-log, the progress package is specifically designed for progress bars and offers more customization options.
Small Node.js module that keeps writing to the same line in the console. Very useful when you write progress bars, or a status message during longer operations.
npm install single-line-log
var log = require('single-line-log');
var read = 0;
var size = fs.statSync('super-large-file').size;
var rs = fs.createReadStream('super-large-file');
rs.on('data', function(data) {
read += data.length;
var percentage = Math.floor(100*read/size);
// Keep writing to the same line in the console
log('[' + percentage + '%]', read, 'bytes read');
});
Clears the log (i.e., writes a newline).
var log = require('single-line-log');
log('Line 1');
log.clear()
log('Line 2');
MIT
FAQs
Keep writing to the same line in the terminal. Very useful when you write progress bars, or a status message during longer operations
The npm package single-line-log receives a total of 93,439 weekly downloads. As such, single-line-log popularity was classified as popular.
We found that single-line-log 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.