MCPcopy Create free account
hub / github.com/dailydotdev/apps / truncateAtWordBoundary

Function truncateAtWordBoundary

packages/shared/src/lib/strings.ts:166–178  ·  view source on GitHub ↗
(
  text: string,
  maxLength: number,
)

Source from the content-addressed store, hash-verified

164 * Appends an ellipsis when truncation occurs.
165 */
166export const truncateAtWordBoundary = (
167 text: string,
168 maxLength: number,
169): string => {
170 if (!text || text.length <= maxLength) {
171 return text || '';
172 }
173
174 const truncated = text.slice(0, maxLength);
175 const lastSpace = truncated.lastIndexOf(' ');
176
177 return `${lastSpace > 0 ? truncated.slice(0, lastSpace) : truncated}...`;
178};
179
180/**
181 * Regex to test if a string contains special characters.

Callers 3

getSeoDescriptionFunction · 0.90
getTemplatedTitleFunction · 0.90
buildCommentsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected