@azizbecha/strkit
Version:
strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.
13 lines (12 loc) • 525 B
TypeScript
/**
* Truncates the middle of a string and replaces it with an ellipsis (...).
*
* @param str - The input string to truncate.
* @param maxLength - The maximum length of the truncated string (default is 10).
* @returns The truncated string with the middle replaced by ellipsis if necessary.
*
* @example
* truncateMiddle("HelloWorld", 5); // Output: "He...ld"
* truncateMiddle("JavaScript", 15); // Output: "JavaScript" (unchanged)
*/
export default function truncateMiddle(str: string, maxLength?: number): string;