| 1 |
export const toCamelCase = (text: string): string => |
| 2 |
text.replace(/-(?<letter>[a-z])/g, (_, letter: string) => letter.toUpperCase()) |
| 3 |
|
| 4 |
export const trimLeadingChar = (text: string, character: string): string => |
| 5 |
character === text.charAt(0) ? text.slice(1) : text |
| 6 |
|
| 7 |
export const trimTrailingChar = (text: string, character: string): string => |
| 8 |
character === text.charAt(text.length - 1) ? text.slice(0, -1) : text |
| 9 |
|
| 10 |
export const truncateWords = (text: string, wordCount: number): string => { |
| 11 |
const words = text.trim().split(/\s+/) |
| 12 |
|
| 13 |
return words.length > wordCount |
| 14 |
? `${words.slice(0, wordCount).join(' ')}…` |
| 15 |
: text |
| 16 |
} |
| 17 |
|
| 18 |
export const stripTags = (text: string): string => |
| 19 |
text |
| 20 |
.replace(/<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi, '') |
| 21 |
.replace(/<\/?[a-z][a-z0-9]*\b[^>]*>/gi, '') |
| 22 |
|