0.1.17 • Published 5 months ago
@trenskow/print v0.1.17
@trenskow/print
A simple package for printing to the console (or other streams).
Usage
import { createWriteStream } from 'node:fs';
import print from '@trenskow/print';
print('Hello, World!'); // Simply prints to stdout.
print.nn('Hello, World!'); // Prints to stdout without new line.
print.sentence('Hello, World, this is a sentence.'); // Prints to stdout a sentence and line breaks at TTY width.
// Below does the same as above but to stderr instead.
print.err('Hello, World!');
print.err.nn('Hello, World!');
print.err.sentence('Hello, World, this is a sentence!');
// Below does the same but to a stream.
const out = print.stream(createWriteStream('out.txt'));
out('Hello, World!');
out.nn('Hello, World!');
out.sentence('Hello, World, this is a sentence!');
Parallel processing printer
There is also a build-in parallel processing builder. This is used to convey the state of multiple tasks.
Usage
import { parallelProgress } from '@trenskow/print';
const states = {
myTask1: 'waiting',
myTask2: 'waiting',
myTask3: 'waiting'
}
const { stateUpdated } = parallelProgress({
states,
simpleOutput: false, // force non-TTY output (defaults to `false`).
completionState: 'done', // State to remove task from list (defaults to ´'done'`).
waitingState: 'waiting' // State to signal task is waiting (defaults to `'waiting'`).
});
for (let idx = 0 ; idx < 3 ; idx++) {
setTimeout(() => {
states[`myTask${idx}`] = 'processing';
stateUpdated(`myTask${idx}`);
}, idx * 1000);
setTimeout(() => {
states[`myTask${idx}`] = 'done';
stateUpdated(`myTask${idx}`);
}, idx * 2000);
}
The above will output something like this.
myTask1 processing
myTask2 processing
myTask3 waiting
The list will auto-remove items that has the state of options.completionState
(default is 'done'
).
License
See license in LICENSE.
0.1.13
6 months ago
0.1.14
6 months ago
0.1.15
5 months ago
0.1.16
5 months ago
0.1.17
5 months ago
0.1.11
6 months ago
0.1.12
6 months ago
0.1.10
6 months ago
0.1.8
6 months ago
0.1.7
6 months ago
0.1.9
6 months ago
0.1.4
7 months ago
0.1.6
6 months ago
0.1.5
6 months ago
0.1.3
7 months ago
0.1.2
7 months ago
0.1.1
7 months ago
0.1.0
7 months ago