This module provides a collection of utility functions for various purposes.
Logs a formatted message to the console with an optional sub-message.
Parameters:
options: The options for the log message.color: The color of the main message text. Defaults to "white".subColor: The color of the sub-message text. Defaults to "dim".subPrefix: The prefix for the sub-message. Defaults to " > ".title: The title of the log message.mainMsg: The main message text.subMsg: The sub-message text.
Logs an array of messages to the console with specified text and color formatting.
Parameters:
msgs: An array of message objects, each containing:text: The message text to be logged.color: The color to apply to the message text.
Sets up and returns a logger instance with optional file logging.
Parameters:
logFilePath(optional): A string representing the path to a log file. If provided, logs with level "ERROR" and above will be written to this file.
Returns:
A promise that resolves to a stdLog.Logger instance configured with console
and (optionally) file logging.
Example Usage:
// Setup logger with console and file handlers
const logger = await getLogger("/path/to/logfile.log");
logger.debug("This is a debug message");
logger.error("This is an error message");// Setup logger with only console handler
const logger = await getLogger();
logger.debug("This is a debug message");
logger.error("This is an error message");You can customize text formatting by passing formatting options as an additional argument to the logger methods:
// A single formatting option (as a string)
logger.debug("This is a red debug message", "red");
// Multiple formatting options (as an array)
logger.error("This is a formatted error message", [
"bgRed",
"bold",
"italic",
"underline",
]);Note: Formatting options are taken from the first additional argument (
args[0]) passed to the log method. These should be valid color or style functions fromstd/fmt/colors. A single string will be wrapped into an array internally.
You can also import an already configured simple console-only logger instance:
import { log } from "@jackfiszr/utils";
log.info("This is an info message");
log.error("This is an error message");Starts an Oak application with the specified options.
Parameters:
app: The Oak application instance.options: Configuration options for starting the application.openFn: Function to open the app in a browser (default:openfrom @rdsq/open).
Returns: A promise that resolves to an Oak Application.
Starts a Hono application with the specified options.
Parameters:
app: The Hono application instance.options: Configuration options for starting the application.openFn: Function to open the app in a browser (default:openfrom @rdsq/open).
Returns: A promise that resolves to a Deno.HttpServer.
Creates one or multiple test PDFs with a specified number of pages.
Parameters:
filenames: A single filename or an array of filenames to create.directory: (Optional) Directory where the PDFs should be saved. Defaults to the current working directory.numPages: (Optional) Number of pages in each PDF. Defaults to 1.
Returns: A promise that resolves when all PDFs are created.
Example Usage:
await createMockPdf("test.pdf"); // Creates a single-page PDF named test.pdf in the current directory.
await createMockPdf(["file1.pdf", "file2.pdf"], "./output", 3);
// Creates two PDFs (file1.pdf & file2.pdf) with 3 pages each in the "output" directory.Retrieves the value of a specified property from an object.
Parameters:
obj: The object from which to retrieve the property.key: The key of the property to retrieve.
Returns: The value of the specified property.
Converts a PDF file to a text file.
Parameters:
pdfFilePath: The path to the PDF file to be converted.config: Optional configuration object.silent: If true, suppresses log output. Defaults to false.
Returns: A promise that resolves to the path of the generated text file.
Executes a given command string in the shell.
Parameters:
cmdStr: The command string to be executed.
Example:
await runCmd("echo Hello, World!");Calculates the difference between two timestamps and returns it as a formatted string.
Parameters:
startTime: The start time in milliseconds since the Unix epoch.endTime: The end time in milliseconds since the Unix epoch.
Returns: A string representing the time difference in the format "HH:MM:SS".
Converts a string of text content into a cleaned array of unique, trimmed, and uppercase strings.
Parameters:
fileTextContent: The content of the file as a single string.
Returns: An array of unique, trimmed, and uppercase strings.
Example:
const content = "hello\nworld\nhello\n";
const result = txtToCleanArr(content);
console.log(result); // Output: ["HELLO", "WORLD"]Lists the names of all entries (files and directories) in the specified directory.
Parameters:
directoryPath: The path to the directory to list. Defaults to the current working directory if not provided.
Returns: An array of strings representing the names of the entries in the directory.
Throws:
Deno.errors.NotFound: If the specified directory does not exist.Deno.errors.PermissionDenied: If the process lacks permissions to read the directory.