bananass-utils-console
Version:
Console Utilities for Bananass Framework.🍌
98 lines (97 loc) • 2.71 kB
TypeScript
/**
* Create a new `Logger` instance.
*
* @param {Options} options
* @returns {Logger} A new `Logger` instance.
*
* @example
* import createLogger from 'bananass-utils-console/logger';
*
* const logger = createLogger({
* debug: false,
* quiet: false,
* textPrefix: '>',
* })
*
* logger
* .log('Hello, log!');
* .debug('Hello, debug!');
* .eol();
*/
export default function createLogger(options: Options): Logger;
/**
* Logger options.
*/
export type Options = {
/**
* Enable debug mode.
*/
debug?: boolean;
/**
* Enable quiet mode.
*/
quiet?: boolean;
/**
* Text prefix.
*/
textPrefix?: string | boolean;
};
/**
* @typedef {object} Options Logger options.
* @property {boolean} [debug] Enable debug mode.
* @property {boolean} [quiet] Enable quiet mode.
* @property {string | boolean} [textPrefix] Text prefix.
*/
declare class Logger {
/** @param {Options} options */
constructor(options?: Options);
/**
* Log a message or executes a callback.
*
* The first parameter can be a message or a callback function.
* - If it's a function, it's invoked with subsequent arguments.
* - Otherwise, the message (with a configured text prefix) and additional arguments are logged.
*
* Behavior based on `quiet` option:
* - `quiet === true`: output X
* - `quiet === false`: output O
*
* @param {...any} params
* @returns {Logger}
*/
log(...params: any[]): Logger;
/**
* Log a message or executes a callback in debug mode.
*
* The first parameter can be a message or a callback function.
* - If it's a function, it's invoked with subsequent arguments.
* - Otherwise, the message (with a configured text prefix) and additional arguments are logged in debug mode.
*
* Behavior based on `debug` and `quiet` options:
* - `quiet === true`: output X
* - `quiet === false && debug === true`: output O
* - `quiet === false && debug === false`: output X
*
* @param {...any} params
* @returns {Logger}
*/
debug(...params: any[]): Logger;
/**
* Ends the current line by logging an empty line using the last method called.
*
* This method temporarily sets the text prefix to an undeclared value,
* then invokes either `log()` or `debug()` depending on the previously method called.
* After logging, it restores the original text prefix.
*
* @returns {Logger}
*/
eol(): Logger;
/**
* Get the last method called.
*
* @returns {'log' | 'debug'}
*/
get lastMethodCalled(): "log" | "debug";
#private;
}
export {};