Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Yurnalist is a simple and elegant logger for Node.js applications. It provides a set of logging utilities that can be used to output messages to the console in a structured and visually appealing way. It is particularly useful for command-line tools and scripts that require user-friendly output.
Basic Logging
Yurnalist allows you to log basic messages to the console. This is useful for general-purpose logging in your application.
const { Reporter } = require('yurnalist');
const reporter = new Reporter();
reporter.log('This is a basic log message.');
Progress Bars
Yurnalist provides a progress bar utility that can be used to indicate the progress of a task. This is particularly useful for long-running operations.
const { Reporter } = require('yurnalist');
const reporter = new Reporter();
const progress = reporter.progress();
progress.tick();
progress.tick();
Spinners
Yurnalist includes a spinner utility that can be used to show that an operation is in progress. This is useful for providing visual feedback to users.
const { Reporter } = require('yurnalist');
const reporter = new Reporter();
const spinner = reporter.activity();
spinner.tick('Loading...');
setTimeout(() => spinner.end(), 2000);
Success and Error Messages
Yurnalist allows you to log success and error messages in a visually distinct way. This helps in clearly communicating the outcome of operations to users.
const { Reporter } = require('yurnalist');
const reporter = new Reporter();
reporter.success('Operation completed successfully.');
reporter.error('An error occurred during the operation.');
Winston is a versatile logging library for Node.js that supports multiple transports (e.g., console, file, HTTP). It is more feature-rich compared to Yurnalist and is suitable for applications that require advanced logging capabilities.
Ora is a library for creating elegant terminal spinners. It is similar to Yurnalist's spinner functionality but is more focused and customizable. Ora is a good choice if you need advanced spinner features.
Progress is a simple and flexible progress bar library for Node.js. It offers more customization options compared to Yurnalist's progress bar and is suitable for applications that need detailed progress tracking.
An elegant console reporter, borrowed from Yarn.
Pretty console output makes developers happy and Yarn is doing a nice job. Yurnalist takes the internal console reporter code from Yarn and makes it available for use in other Node.js applications.
The current version is based on code from Yarn v1.13.0.
Yurnalist can be used to report many different things besides simple messages.
yarn add yurnalist
Or if your prefer NPM
npm install yurnalist
Here is an example showing a combination of different reporter API functions.
import report from 'yurnalist'
/* A function to fake some async task */
function waitNumberOfSecs(secs) {
return new Promise((resolve) => setTimeout(resolve, secs * 1000));
}
async function fetchSomething() {
report.info('Please wait while I fetch something for you.');
report.warn('It might take a little while though.');
const spinner = report.activity();
spinner.tick('I am on it!');
try {
await waitNumberOfSecs(1);
spinner.tick('Still busy...');
await waitNumberOfSecs(1);
spinner.tick('Almost there...');
await waitNumberOfSecs(1);
report.success('Done!');
} catch (err) {
report.error(err);
}
spinner.end();
}
fetchSomething();
Node >= 4
Examples showing different API functions are found in /examples.
You can run them directly with node >= 7.6 (because of async/await syntax). For
older versions you could use the --harmony
flag, or otherwise Babel.
To run the activity example:
node examples/activity.js
A normal import gives you a reporter instance configured with defaults for easy
use. If you want something else you can call createReporter(options)
to give
you an instance with different options.
These are the options of the reporter as defined by Flow:
type ReporterOptions = {
verbose?: boolean,
stdout?: Stdout,
stderr?: Stdout,
stdin?: Stdin,
emoji?: boolean,
noProgress?: boolean,
silent?: boolean,
nonInteractive?: boolean,
peekMemoryCounter?: boolean
};
The defaults used are:
const defaults = {
verbose: false,
stdout: process.stdout,
stderr: process.stderr,
stdin: process.stdin,
emoji: true,
noProgress: false,
silent: false,
nonInteractive: false,
peekMemoryCounter: false
}
The peekMemoryCounter is disabled by default. If you enable it, you'll have to
call reporter.close()
to stop its running timer. Otherwise your program will
not exit. The memory counter can be used to display in the footer data.
Silent mode can be set via the options passed to createReporter. It disables
output for various functions like info
, list
, activity
and progress
. The
output from warning
and error
messages is not silenced.
Silent mode can also be enabled with the YURNALIST_SILENT
environment
variable.
In CI environments the output from activity
and progress
is disabled.
The API still needs some documentation, but most methods are straightforward. In the meantime you can also look at the examples and possibly even the tests.
The following functions are available:
Pretty-prints the thing
.
Generates a list of the provided items. Turns into a definition list if hints
are provided.
Example of a simple list:
report.list('My grocery list', ['bananas', 'tulips', 'eggs', 'bamischijf']);
Outputs:
list My grocery list
- bananas
- tulips
- eggs
- bamischijf
Example with hints:
const items = ['bananas', 'tulips', 'eggs', 'bamischijf'];
const hints = {
bananas: 'for baking',
tulips: 'because it makes you happy',
eggs: 'not the cheap ones though',
bamischijf: 'if they have it',
};
report.list('My grocery list', items, hints);
Outputs:
list My grocery list
- bananas
for baking
- tulips
because it makes you happy
- eggs
not the cheap ones though
- bamischijf
if they have it
Yarn uses a language file for certain messages. For example if you try to skip a required question, or when you pick an invalid item from a select. This language file is not yet exposed in the Yurnalist API. The only supported language is English, as it is in Yarn at the moment.
I plan to make this configurable so that you can define your own messages in your own language .
You can use Emojis in your output. Yurnalist should disable them if they are not allowed in the application environment.
Check:
Of course ❤️ and credits to all the contributers of Yarn. The ease with which I was able to extract this module from their codebase is proving some awesome engineering skills.
FAQs
Elegant console output, borrowed from Yarn
The npm package yurnalist receives a total of 229,471 weekly downloads. As such, yurnalist popularity was classified as popular.
We found that yurnalist 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.