UNPKG

@neabyte/touchid

Version:

Native macOS Touch ID authentication with device identification, TTL caching, and TypeScript support. Features hardware UUID, device serial, and biometric type detection.

57 lines (56 loc) 1.47 kB
export const isNotEmpty = (value) => { return value.trim().length > 0; }; export const createSuccessResult = (data) => { return { success: true, data }; }; export const createErrorResult = (error) => { return { success: false, error }; }; export const delay = (ms) => { return new Promise(resolve => { setTimeout(resolve, ms); }); }; export const retryWithBackoff = async (operation, maxRetries = 3, baseDelay = 1000) => { let lastError; for (let attempt = 0; attempt <= maxRetries; attempt++) { try { return await operation(); } catch (error) { lastError = error; if (attempt === maxRetries) { throw lastError; } const delayMs = baseDelay * Math.pow(2, attempt); await delay(delayMs); } } throw lastError; }; export const safeAsync = async (operation, fallback) => { try { return await operation(); } catch (error) { console.error('Safe async operation failed:', error); return fallback; } }; export const isValidTimeout = (timeout, min = 1000, max = 300000) => { return typeof timeout === 'number' && timeout >= min && timeout <= max; }; export const createContextError = (message, context) => { const error = new Error(message); if (context) { Object.assign(error, { context }); } return error; };