📋 Overview
This document provides comprehensive TypeScript function documentation for the Shared module. The Shared module contains common utilities, services, and components that are used across multiple modules in the Angular admin panel application, including loading indicators, toast notifications, utility functions, and shared pipes.
⏳ LoaderService
File: src/app/shared/services/loader.service.ts
Purpose: Global loading state management for HTTP requests and async operations
🎛️ State Management Methods
Purpose: Shows the global loading spinner
/**
* Shows the global loading spinner
* Updates loading state to true
* Displays loading overlay across the application
* Used for indicating async operations in progress
* @returns {void}
*/
show(): void
void
Purpose: Hides the global loading spinner
/**
* Hides the global loading spinner
* Updates loading state to false
* Removes loading overlay from the application
* Called when async operations complete
* @returns {void}
*/
hide(): void
void
Purpose: Returns observable of current loading state
/**
* Returns observable of current loading state
* Allows components to subscribe to loading changes
* Provides reactive updates for loading indicators
* Used by loading component and interceptors
* @returns {Observable<boolean>} Loading state observable
*/
getLoadingState(): Observable<boolean>
Observable<boolean> - Loading state stream
🍞 ToastService
File: src/app/shared/services/toast.service.ts
Purpose: Global toast notification system for user feedback
📢 Notification Methods
Purpose: Displays success toast notification
/**
* Displays success toast notification
* Shows green-themed success message to user
* Automatically dismisses after configured duration
* Used for confirming successful operations
* @param {string} message - Success message to display
* @param {string} title - Optional toast title
* @returns {void}
*/
showSuccess(message: string, title?: string): void
void
Purpose: Displays error toast notification
/**
* Displays error toast notification
* Shows red-themed error message to user
* Longer display duration for error visibility
* Used for notifying operation failures
* @param {string} message - Error message to display
* @param {string} title - Optional toast title
* @returns {void}
*/
showError(message: string, title?: string): void
void
Purpose: Displays warning toast notification
/**
* Displays warning toast notification
* Shows yellow-themed warning message to user
* Used for cautionary messages and validation warnings
* Intermediate display duration for user attention
* @param {string} message - Warning message to display
* @param {string} title - Optional toast title
* @returns {void}
*/
showWarning(message: string, title?: string): void
void
Purpose: Displays informational toast notification
/**
* Displays informational toast notification
* Shows blue-themed information message to user
* Used for general information and status updates
* Standard display duration for informational content
* @param {string} message - Information message to display
* @param {string} title - Optional toast title
* @returns {void}
*/
showInfo(message: string, title?: string): void
void
🛠️ UtilityService
File: src/app/shared/services/utility.service.ts
Purpose: Common utility functions for data manipulation and formatting
📅 Date and Time Methods
Purpose: Formats date according to specified format string
/**
* Formats date according to specified format string
* Supports various date formats and localization
* Handles timezone conversions and null safety
* Used throughout application for consistent date display
* @param {Date} date - Date object to format
* @param {string} format - Format pattern (YYYY-MM-DD, etc.)
* @returns {string} Formatted date string
*/
formatDate(date: Date, format: string): string
string - Formatted date string
Purpose: Gets the current user's timezone
/**
* Gets the current user's timezone
* Detects browser timezone automatically
* Returns timezone identifier string
* Used for timezone-aware date operations
* @returns {string} Timezone identifier (e.g., 'America/New_York')
*/
getCurrentTimezone(): string
string - Timezone identifier
📊 Data Processing Methods
Purpose: Creates a deep copy of an object
/**
* Creates a deep copy of an object
* Handles nested objects and arrays recursively
* Prevents reference sharing between objects
* Used for immutable data operations
* @param {T} obj - Object to clone
* @returns {T} Deep cloned object
*/
deepClone<T>(obj: T): T
T - Deep cloned object
Purpose: Sorts array by specified property
/**
* Sorts array by specified property
* Supports ascending and descending order
* Handles string, number, and date comparisons
* Returns new sorted array without mutating original
* @param {T[]} array - Array to sort
* @param {string} key - Property name to sort by
* @param {'asc' | 'desc'} direction - Sort direction
* @returns {T[]} Sorted array
*/
sortArray<T>(array: T[], key: string, direction: 'asc' | 'desc'): T[]
T[] - Sorted array
Purpose: Filters array by search term across multiple fields
/**
* Filters array by search term across multiple fields
* Case-insensitive search across specified properties
* Supports partial matching and multiple field search
* Returns filtered array matching search criteria
* @param {T[]} array - Array to filter
* @param {string} searchTerm - Search term
* @param {string[]} fields - Fields to search in
* @returns {T[]} Filtered array
*/
filterArray<T>(array: T[], searchTerm: string, fields: string[]): T[]
T[] - Filtered array
🔧 String Utility Methods
Purpose: Truncates text to specified length with ellipsis
/**
* Truncates text to specified length with ellipsis
* Adds '...' when text exceeds limit
* Preserves word boundaries when possible
* Used for consistent text display in tables and cards
* @param {string} text - Text to truncate
* @param {number} maxLength - Maximum length
* @returns {string} Truncated text with ellipsis
*/
truncateText(text: string, maxLength: number): string
string - Truncated text
Purpose: Generates random alphanumeric string
/**
* Generates random alphanumeric string
* Uses cryptographically secure random generation
* Includes uppercase, lowercase, and numbers
* Used for temporary IDs and unique identifiers
* @param {number} length - Length of string to generate
* @returns {string} Random alphanumeric string
*/
generateRandomString(length: number): string
string - Random string
✅ Validation Methods
Purpose: Validates email address format
/**
* Validates email address format
* Uses RFC-compliant email regex pattern
* Checks for proper email structure and domain
* Returns boolean validation result
* @param {string} email - Email address to validate
* @returns {boolean} True if email is valid
*/
validateEmail(email: string): boolean
boolean - Validation result
Purpose: Validates phone number format
/**
* Validates phone number format
* Supports international and domestic formats
* Handles various phone number patterns
* Used for form validation across modules
* @param {string} phone - Phone number to validate
* @returns {boolean} True if phone number is valid
*/
validatePhoneNumber(phone: string): boolean
boolean - Validation result
🔧 Shared Pipes
Purpose: Custom pipes for data transformation and display formatting
📊 Data Transform Pipes
Purpose: Pipe for truncating text with configurable length
/**
* Pipe for truncating text with configurable length
* Usage: {{ text | truncate:50 }}
* Adds ellipsis when text exceeds limit
* Preserves word boundaries when possible
* @param {string} value - Text to truncate
* @param {number} limit - Maximum character limit
* @returns {string} Truncated text
*/
transform(value: string, limit: number = 100): string
string - Truncated text
Purpose: Pipe for safely rendering HTML content
/**
* Pipe for safely rendering HTML content
* Usage: {{ htmlContent | safeHtml }}
* Sanitizes HTML to prevent XSS attacks
* Allows safe HTML rendering in templates
* @param {string} value - HTML content to sanitize
* @returns {SafeHtml} Sanitized HTML content
*/
transform(value: string): SafeHtml
SafeHtml - Sanitized HTML
Purpose: Pipe for formatting phone numbers
/**
* Pipe for formatting phone numbers
* Usage: {{ phone | phoneFormat }}
* Formats numbers according to regional standards
* Handles international and domestic formats
* @param {string} value - Phone number to format
* @param {string} format - Format type (international, domestic)
* @returns {string} Formatted phone number
*/
transform(value: string, format: string = 'domestic'): string
string - Formatted phone number