UNPKG

lightswind

Version:

A collection of beautifully crafted React Components, Blocks & Templates for Modern Developers. Create stunning web applications effortlessly by using our 160+ professional and animated react components.

70 lines 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cn = cn; exports.formatCurrency = formatCurrency; exports.generateUniqueId = generateUniqueId; exports.truncateText = truncateText; exports.formatDate = formatDate; exports.debounce = debounce; exports.throttle = throttle; const clsx_1 = require("clsx"); const tailwind_merge_1 = require("tailwind-merge"); // Utility function to merge class names with Tailwind function cn(...inputs) { return (0, tailwind_merge_1.twMerge)((0, clsx_1.clsx)(inputs)); } // Utility function to format a number with currency function formatCurrency(amount, currency = "USD", options) { return new Intl.NumberFormat("en-US", { style: "currency", currency, ...options, }).format(amount); } // Utility function to generate a unique ID function generateUniqueId(prefix = "id") { return `${prefix}-${Math.random().toString(36).substring(2, 9)}`; } // Utility function to truncate text function truncateText(text, maxLength) { if (text.length <= maxLength) return text; return text.substring(0, maxLength) + "..."; } // Utility function to format date function formatDate(date, options) { return new Intl.DateTimeFormat("en-US", { day: "numeric", month: "short", year: "numeric", ...options, }).format(date); } // Utility function to debounce function calls function debounce(func, wait) { let timeout = null; return function (...args) { const later = () => { timeout = null; func(...args); }; if (timeout !== null) { clearTimeout(timeout); } timeout = setTimeout(later, wait); }; } // Utility function to throttle function calls function throttle(func, limit) { let inThrottle = false; return function (...args) { if (!inThrottle) { func(...args); inThrottle = true; setTimeout(() => { inThrottle = false; }, limit); } }; } //# sourceMappingURL=utils.js.map