nanoweb-cli
v0.6.1
Published
Nan•web console line interface.
Downloads
166
Readme
Utility Module
This module provides a set of utility functions for formatting console output, measuring performance, and handling memory usage in Node.js applications.
Installation
To install the package, use the following command:
npm install nanoweb-cli
Usage
Import the module and use the provided functions as needed:
const { write, GREEN, RESET, OK, NANO } = require('nanoweb-cli');
// Example usage
print(`${GREEN}${OK} Hello, World!${RESET} Welcome in console interface`);
print(`This is an overwritten text because the previous characters was \\r`, "\n");
Functions
print(message, end = '\r', skipColumns = false)
Prints a message to the console, optionally adjusting for terminal width.
panic(err, highlighedRows = 1)
Prints an error stack trace to the console with highlighted rows.
progress(i, len, fixed = 1)
Calculates progress percentage.
spent(checkpoint, fixed = 2)
Calculates the time spent since the given checkpoint.
debounce(func, wait)
Creates a debounced function that delays invoking the provided function until after the specified wait time.
formatMemoryUsage(bytes, bytesAffix = 'b')
Formats memory usage in human-readable form (e.g., KB, MB, GB).
mem(value = null, bytesAffix = 'b')
Returns the formatted memory usage of the current process or the provided value.
getMemoryUsage(MEMORY_DANGER_USE = 1024 * 1024 * 1024)
Returns an array of formatted memory usage statistics for the current process.
setDebounced
Sets a state value using a debounced function.
short(message, cutTo = null, offsetToSave = null)
Shortens a message to the specified length, optionally preserving parts of the message.
timer(started = null)
Returns the current time or the time elapsed since the given start time.
Constants
GREEN
, RED
, YELLOW
, BG_YELLOW
, RESET
, OK
, FAIL
, NANO
Constants for console text formatting and symbols.
const OK = '✓';
const FAIL = '×';
const NANO = '·';
Example
const { print, GREEN, OK, RESET, debounce } = require('nanoweb-cli');
print('Processing...', "\n");
debounce(() => {
print(`${GREEN}${OK}${RESET} Operation completed successfully.`, "\n");
}, 108);
License
MIT
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.