Skip to content

Commit be76cd5

Browse files
committed
docs(string): add truncateMiddle examples
1 parent 3e6dff2 commit be76cd5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/string.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ export function initials(name: Maybe<string>): Optional<string> {
4444
* There are cases where important information is at the end of the string and truncating the end isn't helpful.
4545
* This function solves that.
4646
*
47+
* @example
48+
* ```ts
49+
* truncateMiddle('very-long-file-name.txt', 10, 4); // 'very-long&hellip;name.txt'
50+
* truncateMiddle('Hello, world!', 5, 6); // 'Hello&hellip;world!'
51+
* truncateMiddle('Hello, world!', 5, 0); // 'Hello&hellip;'
52+
* truncateMiddle('Hello, world!', 0, 6); // '&hellip;world!'
53+
* truncateMiddle('Hello, world!', 0, 0); // 'Hello, world!'
54+
* ```
55+
*
4756
* @license https://github.com/kahwee/truncate-middle#license
48-
* @param str - String to be truncated
49-
* @param frontLen - Number of characters to be remained in front
50-
* @param backLen - Number of characters to be remained at the back
51-
* @param truncateStr - String that replaces the truncated portion
52-
* @returns Truncated string. Defaults to '&hellip;' if unspecified
5357
*/
5458
export function truncateMiddle(
5559
str: Maybe<string>,

0 commit comments

Comments
 (0)