2025-03-15 22:47:32 +01:00
|
|
|
import type { LocationQueryValue } from 'vue-router';
|
2025-06-14 19:12:31 +02:00
|
|
|
import type { Id } from '~/shared/types/common';
|
2025-03-15 22:47:32 +01:00
|
|
|
|
|
|
|
export function queryToString(item?: null | LocationQueryValue | LocationQueryValue[]) {
|
|
|
|
if (item === null)
|
|
|
|
return "";
|
|
|
|
if (item instanceof Array)
|
|
|
|
return queryToString(item[0])
|
|
|
|
return item;
|
|
|
|
}
|
2025-06-11 21:05:17 +02:00
|
|
|
|
|
|
|
export function queryToNumber(item?: null | LocationQueryValue | LocationQueryValue[]) {
|
|
|
|
if (item === null || item === undefined)
|
|
|
|
return undefined;
|
|
|
|
if (item instanceof Array)
|
|
|
|
return queryToNumber(item[0])
|
|
|
|
return Number.parseInt(item, 10);
|
|
|
|
}
|
2025-06-14 19:12:31 +02:00
|
|
|
|
|
|
|
export function idMap<T extends { id: Id }>(entities: T[]) {
|
|
|
|
return new Map(entities.map(entity => [entity.id, entity]));
|
|
|
|
}
|