@tsed/logger
Version:
A multi channel logger written in TypeScript.
43 lines (38 loc) • 1.01 kB
text/typescript
export function truncate(truncation: string, toTruncate: string) {
let len;
if (truncation) {
len = parseInt(truncation.substr(1), 10);
return toTruncate.substring(0, len);
}
return toTruncate;
}
export function pad(padding: string, toPad: string) {
let len;
if (padding) {
if (padding.charAt(0) === "-") {
len = parseInt(padding.substr(1), 10);
// Right pad with spaces
while (toPad.length < len) {
toPad += " ";
}
} else {
len = parseInt(padding, 10);
// Left pad with spaces
while (toPad.length < len) {
toPad = ` ${toPad}`;
}
}
}
return toPad;
}
export function truncateAndPad(toTruncAndPad: string, truncation: string, padding: string) {
let replacement = toTruncAndPad;
replacement = truncate(truncation, replacement);
replacement = pad(padding, replacement);
return replacement;
}
export const StringUtils = {
format(fmt: string | object, ...args: any[]): string {
return "";
}
};