add format check, update prettier rules, apply rules consistently

This commit is contained in:
Gregor Vostrak
2025-07-29 18:58:31 +02:00
parent b11672732b
commit cb30487a21
323 changed files with 3728 additions and 5579 deletions

View File

@@ -40,13 +40,7 @@ export function formatCents(
currencySymbol?: string,
numberFormat?: NumberFormat
) {
return formatMoney(
amount / 100,
currency,
format,
currencySymbol,
numberFormat
);
return formatMoney(amount / 100, currency, format, currencySymbol, numberFormat);
}
export function getOrganizationCurrencySymbol(currency: string) {

View File

@@ -28,8 +28,7 @@ export default class Prando {
} else {
// Pseudo-random seed
this._seed = this.getSafeSeed(
Prando.MIN +
Math.floor((Prando.MAX - Prando.MIN) * Math.random())
Prando.MIN + Math.floor((Prando.MAX - Prando.MIN) * Math.random())
);
}
this.reset();
@@ -59,9 +58,7 @@ export default class Prando {
*/
public nextInt(min = 10, max = 100): number {
this.recalculate();
return Math.floor(
this.map(this._value, Prando.MIN, Prando.MAX, min, max + 1)
);
return Math.floor(this.map(this._value, Prando.MIN, Prando.MAX, min, max + 1));
}
/**
@@ -176,9 +173,7 @@ export default class Prando {
minTo: number,
maxTo: number
): number {
return (
((val - minFrom) / (maxFrom - minFrom)) * (maxTo - minTo) + minTo
);
return ((val - minFrom) / (maxFrom - minFrom)) * (maxTo - minTo) + minTo;
}
private hashCode(str: string): number {

View File

@@ -1,16 +1,15 @@
import {computed, type Ref, watch} from "vue";
import {onKeyStroke} from "@vueuse/core";
export function useSelectEvents<Type>(filteredItems: Ref<Array<Type>>,
highlightedItemId: Ref<string | null>,
getKeyFromItem: (item: Type) => string,
open: Ref<boolean>) {
import { computed, type Ref, watch } from 'vue';
import { onKeyStroke } from '@vueuse/core';
export function useSelectEvents<Type>(
filteredItems: Ref<Array<Type>>,
highlightedItemId: Ref<string | null>,
getKeyFromItem: (item: Type) => string,
open: Ref<boolean>
) {
function moveHighlightUp() {
if (highlightedItem.value) {
const currentHightlightedIndex = filteredItems.value.indexOf(
highlightedItem.value
);
const currentHightlightedIndex = filteredItems.value.indexOf(highlightedItem.value);
if (currentHightlightedIndex === 0) {
highlightedItemId.value = getKeyFromItem(
filteredItems.value[filteredItems.value.length - 1]
@@ -20,36 +19,30 @@ export function useSelectEvents<Type>(filteredItems: Ref<Array<Type>>,
filteredItems.value[currentHightlightedIndex - 1]
);
}
}
else {
highlightedItemId.value = getKeyFromItem(filteredItems.value[filteredItems.value.length - 1]);
} else {
highlightedItemId.value = getKeyFromItem(
filteredItems.value[filteredItems.value.length - 1]
);
}
}
function moveHighlightDown() {
if (highlightedItem.value) {
const currentHightlightedIndex = filteredItems.value.indexOf(
highlightedItem.value
);
const currentHightlightedIndex = filteredItems.value.indexOf(highlightedItem.value);
if (currentHightlightedIndex === filteredItems.value.length - 1) {
highlightedItemId.value = getKeyFromItem(
filteredItems.value[0]
);
highlightedItemId.value = getKeyFromItem(filteredItems.value[0]);
} else {
highlightedItemId.value = getKeyFromItem(
filteredItems.value[currentHightlightedIndex + 1]
);
}
}
else{
} else {
highlightedItemId.value = getKeyFromItem(filteredItems.value[0]);
}
}
const highlightedItem = computed(() => {
return filteredItems.value.find(
(item) => getKeyFromItem(item) === highlightedItemId.value
);
return filteredItems.value.find((item) => getKeyFromItem(item) === highlightedItemId.value);
});
onKeyStroke('ArrowDown', (e) => {
@@ -72,4 +65,3 @@ export function useSelectEvents<Type>(filteredItems: Ref<Array<Type>>,
}
});
}

View File

@@ -13,7 +13,6 @@ import updateLocale from 'dayjs/plugin/updateLocale';
import { computed } from 'vue';
import { formatNumber } from './number';
export type DateFormat =
| 'point-separated-d-m-yyyy'
| 'slash-separated-mm-dd-yyyy'
@@ -28,7 +27,7 @@ const dateFormatMap: Record<DateFormat, string> = {
'slash-separated-dd-mm-yyyy': 'DD/MM/YYYY',
'hyphen-separated-dd-mm-yyyy': 'DD-MM-YYYY',
'hyphen-separated-mm-dd-yyyy': 'MM-DD-YYYY',
'hyphen-separated-yyyy-mm-dd': 'YYYY-MM-DD'
'hyphen-separated-yyyy-mm-dd': 'YYYY-MM-DD',
};
export type TimeFormat = '12-hours' | '24-hours';
@@ -131,9 +130,7 @@ export function getLocalizedDateFromTimestamp(timestamp: string) {
*/
export function formatDate(date: string, format: DateFormat = 'point-separated-d-m-yyyy'): string {
if (date?.includes('+')) {
console.warn(
'Date contains timezone information, use formatDateLocalized instead'
);
console.warn('Date contains timezone information, use formatDateLocalized instead');
}
return getDayJsInstance()(date).format(dateFormatMap[format]);
}
@@ -142,11 +139,18 @@ export function formatDate(date: string, format: DateFormat = 'point-separated-d
* Returns a formatted date.
* @param date - date in the format of 'YYYY-MM-DD'
*/
export function formatDateLocalized(date: string, format: DateFormat = 'point-separated-d-m-yyyy'): string {
export function formatDateLocalized(
date: string,
format: DateFormat = 'point-separated-d-m-yyyy'
): string {
return getLocalizedDayJs(date).format(dateFormatMap[format]);
}
export function formatDateTimeLocalized(date: string, dateFormat?: DateFormat, timeFormat?: TimeFormat): string {
export function formatDateTimeLocalized(
date: string,
dateFormat?: DateFormat,
timeFormat?: TimeFormat
): string {
const format = `${dateFormatMap[dateFormat ?? 'point-separated-d-m-yyyy']} ${timeFormat === '12-hours' ? 'hh:mm A' : 'HH:mm'}`;
return getLocalizedDayJs(date).format(format);
}
@@ -162,16 +166,16 @@ export function formatWeek(date: string | null): string {
export function formatHumanReadableDate(date: string) {
const dateObj = dayjs(date);
const today = dayjs();
if (dateObj.isToday()) {
return 'Today';
} else if (dateObj.isYesterday()) {
return 'Yesterday';
}
// Calculate difference in days
const diffInDays = today.diff(dateObj, 'day');
if (diffInDays > 0 && diffInDays <= 30) {
// For dates in the past (2-30 days ago)
return `${diffInDays} ${diffInDays === 1 ? 'day' : 'days'} ago`;
@@ -180,7 +184,7 @@ export function formatHumanReadableDate(date: string) {
const futureDays = Math.abs(diffInDays);
return `In ${futureDays} ${futureDays === 1 ? 'day' : 'days'}`;
}
// For dates older than 30 days, show the actual date
return dateObj.format('MMM D, YYYY');
}
@@ -189,7 +193,11 @@ export function formatWeekday(date: string) {
return dayjs(date).format('dddd');
}
export function formatStartEnd(start: string, end: string | null, timeFormat: TimeFormat = '24-hours') {
export function formatStartEnd(
start: string,
end: string | null,
timeFormat: TimeFormat = '24-hours'
) {
if (end) {
return `${formatTime(start, timeFormat)} - ${formatTime(end, timeFormat)}`;
} else {