UNPKG

traceperf

Version:

High-performance function execution tracking and monitoring for Node.js

50 lines 1.54 kB
"use strict"; /** * String utility functions */ Object.defineProperty(exports, "__esModule", { value: true }); exports.padCenter = padCenter; exports.truncate = truncate; exports.padEnd = padEnd; /** * Center a string with padding * * @param str - The string to center * @param length - The total length of the returned string * @param char - The character to use for padding (default: space) * @returns The padded string */ function padCenter(str, length, char = ' ') { if (str.length >= length) return str; const leftPadding = Math.floor((length - str.length) / 2); const rightPadding = length - str.length - leftPadding; return char.repeat(leftPadding) + str + char.repeat(rightPadding); } /** * Truncate a string to a specified length and add ellipsis if needed * * @param str - The string to truncate * @param maxLength - The maximum length allowed * @returns The truncated string */ function truncate(str, maxLength) { if (str.length <= maxLength) return str; const ellipsis = '...'; return str.substring(0, maxLength - ellipsis.length) + ellipsis; } /** * Ensure that the string is at least a certain length * * @param str - The string to pad * @param length - The minimum length desired * @param char - The character to use for padding (default: space) * @returns The padded string */ function padEnd(str, length, char = ' ') { if (str.length >= length) return str; return str + char.repeat(length - str.length); } //# sourceMappingURL=string.js.map