# code-snippets/4.0.0-beta.1/js/utils/text.ts

Code Snippets, version 4.0.0-beta.1. 22 lines.

- Page: https://pluginprobe.com/plugins/code-snippets/4.0.0-beta.1/code/js/utils/text.ts
- Raw: https://pluginprobe.com/plugins/code-snippets/4.0.0-beta.1/raw/js/utils/text.ts
- Modified: 2026-06-19T15:58:00+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-snippets/4.0.0-beta.1/code/js/utils/text.ts#L10-L20`.

```typescript
export const toCamelCase = (text: string): string =>
	text.replace(/-(?<letter>[a-z])/g, (_, letter: string) => letter.toUpperCase())

export const trimLeadingChar = (text: string, characters: string): string =>
	characters.includes(text.charAt(0)) ? text.slice(1) : text

export const trimTrailingChar = (text: string, characters: string): string =>
	characters.includes(text.charAt(text.length - 1)) ? text.slice(0, -1) : text

export const truncateWords = (text: string, wordCount: number): string => {
	const words = text.trim().split(/\s+/)

	return words.length > wordCount
		? `${words.slice(0, wordCount).join(' ')}…`
		: text
}

export const stripTags = (text: string): string =>
	text
		.replace(/<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi, '')
		.replace(/<\/?[a-z][a-z0-9]*\b[^>]*>/gi, '')

```
