feat: add utils.ts with formatDate and capitalize functions

- Add formatDate(date: Date): string function
- Add capitalize(str: string): string function
- Include JSDoc documentation

Closes #2
This commit is contained in:
imfozilbek
2025-12-25 01:25:24 +05:00
parent 036f0f2c13
commit b26bdf7122

27
src/utils.ts Normal file
View File

@@ -0,0 +1,27 @@
/**
* Utility functions for common operations
*/
/**
* Formats a Date object to a readable string (YYYY-MM-DD)
* @param date - The date to format
* @returns Formatted date string
*/
export function formatDate(date: Date): string {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, "0")
const day = String(date.getDate()).padStart(2, "0")
return `${year}-${month}-${day}`
}
/**
* Capitalizes the first letter of a string
* @param str - The string to capitalize
* @returns String with first letter capitalized
*/
export function capitalize(str: string): string {
if (str.length === 0) {
return str
}
return str.charAt(0).toUpperCase() + str.slice(1)
}