49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { type ClassValue, clsx } from 'clsx';
|
|
import { ProductFeaturesSchemas } from '../types';
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return clsx(inputs);
|
|
}
|
|
|
|
export function generateId(lenght?: number): string {
|
|
return Math.random().toString(lenght || 36).substring(2) + Date.now().toString(lenght || 36);
|
|
}
|
|
|
|
export function addMonths(date: Date, months: number): Date {
|
|
const result = new Date(date);
|
|
result.setMonth(result.getMonth() + months);
|
|
return result;
|
|
}
|
|
|
|
export function formatCurrency(amount: number, currency = 'USD'): string {
|
|
return new Intl.NumberFormat('en-US', {
|
|
style: 'currency',
|
|
currency,
|
|
}).format(amount);
|
|
}
|
|
|
|
export function formatDate(date: Date): string {
|
|
return new Intl.DateTimeFormat('en-US', {
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
}).format(date);
|
|
}
|
|
|
|
export function isSubscriptionExpired(endDate: Date): boolean {
|
|
return new Date() > endDate;
|
|
}
|
|
|
|
export function getDaysUntilExpiry(endDate: Date): number {
|
|
const now = new Date();
|
|
const diffTime = endDate.getTime() - now.getTime();
|
|
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
}
|
|
|
|
export function getProductFeaturesSchema<
|
|
T extends keyof typeof ProductFeaturesSchemas
|
|
>(productName: T) {
|
|
return ProductFeaturesSchemas[productName];
|
|
}
|
|
|