rsformat
Version:
Formatting/printing library for JavaScript that takes after rust's string formatting
50 lines (49 loc) • 1.56 kB
TypeScript
import util from 'node:util';
/**
* Type representing a string formatted by `rs`.
* An extension of `String`.
*/
export declare class RsString extends String {
/**
* A version of the string that includes ANSI escape codes for debug formatting.
*/
colored: string;
constructor(strings: TemplateStringsArray, params: any[]);
toString(debugColors?: boolean): string;
}
/**
* Format a template literal with rust-style formatting and return it as a raw and colored string.
*
* @param strings String parts of the template
* @param params Template parameters
*
* @returns An object with raw and colored versions of the formatted parameter
*/
export declare function buildString(strings: TemplateStringsArray, params: any[]): {
raw: string;
colored: string;
};
type AlignDirection = '<' | '^' | '>';
type Sign = '-' | '+' | '';
type FormatType = '?' | 'o' | 'x' | 'X' | 'b' | 'e' | 'E' | 'n' | 'N' | '';
type FormatSpecifier = {
fill: string;
align: AlignDirection;
force_sign: Sign;
pretty: boolean;
pad_zeroes: boolean;
width: number;
precision: number;
type: FormatType;
};
/**
* Format a parameter as a string according to a specifier.
*
* @param param parameter to format
* @param format format specifier object
* @returns `param` as a debug-colored and raw formatted string
*/
export declare function formatParam(param: any, format: FormatSpecifier): [string, string];
/** Re-export of node's `util.styleText`. */
export declare const style: typeof util.styleText;
export {};