66 * the import.meta.glob operation only runs once during the module initialization.
77 * @example
88 * ```typescript
9- * import { AvatarManager } from '@components/Avatar/avatars'
9+ * import { AvatarManager, normalizeNameToFilename } from '@components/Avatar/avatars'
1010 *
1111 * const avatar = AvatarManager.getInstance().getAvatar('kevin-brown')
1212 * const allAvatars = AvatarManager.getInstance().getAll()
13+ * const filename = normalizeNameToFilename('Chris Southam') // 'chris-southam'
1314 * ```
1415 */
1516
@@ -22,6 +23,24 @@ type ImageMetadata = {
2223
2324type AvatarMap = Record < string , ImageMetadata >
2425
26+ /**
27+ * Normalize a person's name to a filename format
28+ * @param name - The person's name (e.g., "Chris Southam")
29+ * @returns The normalized filename (e.g., "chris-southam")
30+ * @example
31+ * ```typescript
32+ * normalizeNameToFilename('Chris Southam') // 'chris-southam'
33+ * normalizeNameToFilename('Kevin Brown') // 'kevin-brown'
34+ * ```
35+ */
36+ export function normalizeNameToFilename ( name : string ) : string {
37+ return name
38+ . toLowerCase ( )
39+ . trim ( )
40+ . replace ( / \s + / g, '-' ) // Replace spaces with hyphens
41+ . replace ( / [ ^ a - z 0 - 9 - ] / g, '' ) // Remove non-alphanumeric chars except hyphens
42+ }
43+
2544class AvatarManagerClass {
2645 private static instance : AvatarManagerClass
2746 private readonly avatarMap : Readonly < AvatarMap >
@@ -111,26 +130,3 @@ class AvatarManagerClass {
111130// Export singleton instance
112131export const AvatarManager = AvatarManagerClass
113132
114- // Backward-compatible exports for existing code
115- const instance = AvatarManager . getInstance ( )
116-
117- /**
118- * @deprecated Use AvatarManager.getInstance().getAll() instead
119- */
120- export const avatarMap = instance . getAll ( )
121-
122- /**
123- * Get avatar image by filename
124- * @deprecated Use AvatarManager.getInstance().getAvatar() instead
125- */
126- export function getAvatarImage ( filename : string ) : ImageMetadata | undefined {
127- return instance . getAvatar ( filename )
128- }
129-
130- /**
131- * Get all available avatar filenames
132- * @deprecated Use AvatarManager.getInstance().getAvailableAvatars() instead
133- */
134- export function getAvailableAvatars ( ) : readonly string [ ] {
135- return instance . getAvailableAvatars ( )
136- }
0 commit comments