32 lines
1006 B
TypeScript
32 lines
1006 B
TypeScript
import type { InertiaLinkProps } from '@inertiajs/react';
|
|
import { clsx } from 'clsx';
|
|
import type { ClassValue } from 'clsx';
|
|
import { twMerge } from 'tailwind-merge';
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export function toUrl(url: NonNullable<InertiaLinkProps['href']>): string {
|
|
return typeof url === 'string' ? url : url.url;
|
|
}
|
|
|
|
export function formatCurrency(amount: number): string {
|
|
return new Intl.NumberFormat('id-ID', {
|
|
style: 'currency',
|
|
currency: 'IDR',
|
|
minimumFractionDigits: 0,
|
|
}).format(amount);
|
|
}
|
|
|
|
export function generateRandomColors(count: number): string[] {
|
|
const colors: string[] = [];
|
|
for (let i = 0; i < count; i++) {
|
|
const hue = Math.floor(Math.random() * 360);
|
|
const saturation = 65 + Math.floor(Math.random() * 20);
|
|
const lightness = 45 + Math.floor(Math.random() * 20);
|
|
colors.push(`hsl(${hue}, ${saturation}%, ${lightness}%)`);
|
|
}
|
|
return colors;
|
|
}
|