Add initial Code
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { InertiaLinkProps } from '@inertiajs/vue3';
|
||||
import { clsx, type ClassValue } from 'clsx';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
export function urlIsActive(urlToCheck: NonNullable<InertiaLinkProps['href']>, currentUrl: string) {
|
||||
return toUrl(urlToCheck) === currentUrl;
|
||||
}
|
||||
|
||||
export function toUrl(href: NonNullable<InertiaLinkProps['href']>) {
|
||||
return typeof href === 'string' ? href : href?.url;
|
||||
}
|
||||
|
||||
const currencyFormatter = new Intl.NumberFormat('de-DE', {
|
||||
style: 'currency',
|
||||
currency: 'EUR',
|
||||
minimumFractionDigits: 2,
|
||||
})
|
||||
|
||||
export function toCurrency(value: number | undefined) {
|
||||
if (!value) return currencyFormatter.format(0);
|
||||
return currencyFormatter.format(value);
|
||||
}
|
||||
|
||||
export function toLocalDate(value: string) {
|
||||
const date = new Date(value);
|
||||
return date.toLocaleDateString('de-DE', { day: '2-digit', month: 'short', year: 'numeric' });
|
||||
// return date.toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' });
|
||||
// return date.toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: '2-digit' });
|
||||
}
|
||||
|
||||
export function toShortISOString(date: Date | string) {
|
||||
let tempDate = (typeof date === 'string') ? new Date(date) : date
|
||||
return tempDate.toISOString().split('T')[0]
|
||||
}
|
||||
|
||||
export function calcDueDate(date: Date, daysAfterInvoice: number): Date {
|
||||
let dueDate = new Date(date);
|
||||
dueDate.setDate(date.getDate() + daysAfterInvoice);
|
||||
return dueDate;
|
||||
}
|
||||
|
||||
export function randomInt(max: number) {
|
||||
return Math.floor(Math.random() * max);
|
||||
}
|
||||
|
||||
const randomColors = [
|
||||
'bg-rose-200 dark:bg-rose-700',
|
||||
'bg-lime-200 dark:bg-lime-700',
|
||||
'bg-orange-200 dark:bg-orange-700',
|
||||
'bg-sky-200 dark:bg-sky-700',
|
||||
'bg-amber-200 dark:bg-amber-700',
|
||||
'bg-blue-200 dark:bg-blue-700',
|
||||
'bg-purple-200 dark:bg-purple-700'
|
||||
]
|
||||
|
||||
export function bgColorForString(input: string): string {
|
||||
let charCodeSum = 0;
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
charCodeSum += input.charCodeAt(i)
|
||||
}
|
||||
return randomColors[charCodeSum % randomColors.length];
|
||||
}
|
||||
Reference in New Issue
Block a user