topkat-utils
Version:
A comprehensive collection of TypeScript/JavaScript utility functions for common programming tasks. Includes validation, object manipulation, date handling, string formatting, and more. Zero dependencies, fully typed, and optimized for performance.
85 lines (84 loc) • 3.46 kB
TypeScript
/// <reference types="node" />
import { Color } from './types';
type NotInfoLogLevel = 'error' | 'warn';
type LogLevels = NotInfoLogLevel | 'info';
export declare const logger: {
log(str: string, level?: LogLevels): void;
toHtml(inputLogs?: string[]): string;
toText(inputLogs?: string[]): string;
raw: string[];
json: string[];
};
/**
// console colored output
// * console.log(C.green(C.dim('Hey bro !')))
// * or C.log() // will use color defined by themes
// * or C.line('MY TITLE', 53)
// * or C.gradientize(myLongString)
*/
export declare const C: {
dim: (str: string) => string;
green: (str: string) => string;
red: (str: string) => string;
yellow: (str: string) => string;
grey: (str: string) => string;
magenta: (str: string) => string;
cyan: (str: string) => string;
blue: (str: string) => string;
primary: (str: string) => string;
reset: string;
output: (code: number, str?: string) => string;
rgb: (r: number, g?: number, b?: number) => string;
bg: (r?: number, g?: number, b?: number) => string;
/** Output a line of title */
line(title?: string, length?: number, clr?: Color, char?: string): void;
/** Eg: ['cell1', 'cell2', 'cell3'], [25, 15] will start cell2 at 25 and cell 3 at 25 + 15
* @param {Array} limits default divide the viewport
*/
cols(strings: string[], limits?: number[], clr?: Color): void;
/** Console log alias */
log(...stringsCtxMayBeFirstParam: any[]): void;
logClr(str: string, clr?: Color): void;
info(...str: string[]): void;
success(...str: string[]): void;
/** First param **false** to avoid logging stack trace */
error: (...errors: any[]) => any;
/** First param **false** to avoid logging stack trace */
warning: (...str: any[]) => any;
customError: (color: Color, ...str: string[]) => any;
customWarning: (color: Color, ...str: string[]) => any;
applicationError: (color: Color, ...str: string[]) => any;
warningLight: (_: any, ...str: string[]) => any;
dimStrSplit(...logs: string[]): string;
/** Gratientize lines of text (separated by \n) */
gradientize(str?: string, rgb1?: Color, rgb2?: Color, bgRgb?: Color, paddingY?: number): void;
debugModeLog(title: string, ...string: string[]): void;
/** allow to clear the last lines written to console */
clearLastLines(n?: number): void;
};
/**
* Call this at each steps of your progress and change the step value
* @param {Number} step Number of "char" to output
* @param {String} char Default: '.'
* @param {String} msg String before char. Final output will be `${str}${char.repeat(step)}`
*/
export declare function cliProgressBar(step: number, char?: string, msg?: string): void;
type loadingSpinnerTypes = 'arrow' | 'dots';
/** This allow an intuitive inline loading spinner with a check mark when loading as finished or a red cross for errors */
export declare class cliLoadingSpinner {
/** Please use it like spinner.start('myStuff') then spinner.end()
* @param {String} type in: ['arrow', 'dots']
*/
frameRate: number;
animFrames: string[];
activeProcess: any;
frameNb: number;
progressMessage: string;
interval: any;
constructor(type?: loadingSpinnerTypes, activeProcess?: NodeJS.Process);
start(msg: string): void;
end(error?: boolean): void;
error(): void;
}
export declare function dim(str?: string): string;
export {};