barsa 1b944f57aa Update Configuration Files and Refactor Code Structure
- Adjusted .prettierrc to ensure consistent formatting with a newline at the end of the file.
- Reformatted eslint.config.mjs for improved readability by aligning array elements.
- Updated pnpm-lock.yaml to use single quotes for consistency across dependencies.
- Simplified worktree setup in .cursor/worktrees.json for cleaner configuration.
- Enhanced documentation in .cursor/plans to clarify architecture refactoring.
- Refactored various service files for improved readability and maintainability, including rate-limiting and auth services.
- Updated imports and exports across multiple files for consistency and clarity.
- Improved error handling and logging in service methods to enhance debugging capabilities.
- Streamlined utility functions for better performance and maintainability across the domain packages.
2025-12-25 17:30:02 +09:00

67 lines
1.7 KiB
TypeScript

/**
* Toolkit - Text Formatting
*
* Utilities for text manipulation and formatting.
*/
/**
* Capitalize first letter of a string
*/
export function capitalize(str: string): string {
if (!str) return str;
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}
/**
* Convert string to title case
*/
export function toTitleCase(str: string): string {
return str
.split(" ")
.map(word => capitalize(word))
.join(" ");
}
/**
* Truncate string with ellipsis
*/
export function truncate(str: string, maxLength: number, suffix = "..."): string {
if (str.length <= maxLength) return str;
return str.slice(0, maxLength - suffix.length) + suffix;
}
/**
* Convert camelCase or PascalCase to human-readable text
*/
export function humanize(str: string): string {
return str
.replace(/([A-Z])/g, " $1") // Add space before capital letters
.replace(/^./, match => match.toUpperCase()) // Capitalize first letter
.trim();
}
/**
* Generate initials from a name
*/
export function getInitials(name: string, maxLength = 2): string {
const parts = name.trim().split(/\s+/);
const initials = parts.map(part => part.charAt(0).toUpperCase());
return initials.slice(0, maxLength).join("");
}
/**
* Mask sensitive data (e.g., email, phone)
*/
export function maskString(str: string, visibleStart = 3, visibleEnd = 3, maskChar = "*"): string {
if (str.length <= visibleStart + visibleEnd) {
return str;
}
const start = str.slice(0, visibleStart);
const end = str.slice(-visibleEnd);
const maskedLength = str.length - visibleStart - visibleEnd;
const masked = maskChar.repeat(maskedLength);
return `${start}${masked}${end}`;
}