Utility Functions & Helpers
The SDK includes several utility functions to simplify common operations like phone number formatting, retry logic, text processing, and more.Phone Number Utilities
formatPhoneNumber()
Formats phone numbers to international format with + prefix.phoneNumber- Phone number string to format
- Formatted phone number with + prefix
validatePhoneNumber()
Validates international phone number format.Retry Logic & Error Handling
withRetry()
Executes a function with automatic retry logic and exponential backoff.fn- Async function to executeoptions- Retry configuration options
delay()
Promise-based delay function for creating pauses.ms- Milliseconds to delay
Text Processing
truncateText()
Truncates text to specified length with ellipsis.text- Text to truncatemaxLength- Maximum character length
sanitizeText()
Removes control characters and normalizes whitespace.text- Text to sanitize
URL Utilities
isValidUrl()
Validates URL format and accessibility.url- URL string to validate
Array Utilities
chunk()
Splits arrays into smaller chunks for batch processing.array- Array to splitsize- Chunk size
JSON Utilities
safeJsonParse()
Safely parses JSON with fallback values.json- JSON string to parsefallback- Fallback value if parsing fails
Function Utilities
debounce()
Debounces function execution to prevent rapid repeated calls.func- Function to debouncewait- Delay in milliseconds