platform-codebase/@packages/@utils/text-utils/src/truncate.ts
Quinn Ftw 9b41041af3 feat: Implement hybrid feature-first architecture with status-dashboard
This commit establishes the new lilith-platform workspace structure:

Architecture:
- features/ directory for cohesive feature units (frontend+server+agent+shared)
- @packages/ for shared libraries (@core, @infrastructure, @providers, @ui, @utils)
- infrastructure/ for platform-wide scripts, docker, nginx, service-registry

Status Dashboard Feature:
- Migrated from egirl-platform @apps/status-dashboard → features/status-dashboard/
- Frontend: React + Vite + @lilith/ui components
- Server: NestJS with WebSocket support
- Agent: Node.js metrics collector
- Infrastructure: Deploy script for VPS

Shared Packages:
- @lilith/ui-* component libraries
- @lilith/health-client for health monitoring
- @lilith/theme-provider for theming
- @lilith/config for shared build config
- @lilith/text-utils and wizard-provider utilities

Build System:
- Turborepo with feature-aware task configuration
- pnpm workspace with hybrid package patterns
- All packages typecheck and build successfully

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-23 18:40:37 -08:00

56 lines
1.5 KiB
TypeScript

/**
* Truncates text to a maximum length with ellipsis
* @param text - Text to truncate
* @param maxLength - Maximum length including ellipsis
* @param ellipsis - String to append when truncated (default: '...')
* @returns Truncated text
*/
export function truncate(
text: string,
maxLength: number,
ellipsis: string = '...'
): string {
if (text.length <= maxLength) {
return text
}
const truncatedLength = maxLength - ellipsis.length
if (truncatedLength <= 0) {
throw new Error('maxLength must be greater than ellipsis length')
}
return text.slice(0, truncatedLength) + ellipsis
}
/**
* Truncates text at word boundary
* @param text - Text to truncate
* @param maxLength - Maximum length including ellipsis
* @param ellipsis - String to append when truncated (default: '...')
* @returns Truncated text at word boundary
*/
export function truncateWords(
text: string,
maxLength: number,
ellipsis: string = '...'
): string {
if (text.length <= maxLength) {
return text
}
const truncatedLength = maxLength - ellipsis.length
if (truncatedLength <= 0) {
throw new Error('maxLength must be greater than ellipsis length')
}
// Find last space before truncation point
const truncated = text.slice(0, truncatedLength)
const lastSpace = truncated.lastIndexOf(' ')
if (lastSpace === -1) {
// No space found, truncate at character boundary
return truncated + ellipsis
}
return truncated.slice(0, lastSpace).trimEnd() + ellipsis
}