2025-06-30 18:58:24 +02:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
*/
|
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
|
|
|
|
2025-07-16 19:37:23 +02:00
|
|
|
export function queryToBoolean(item?: null | LocationQueryValue | LocationQueryValue[]) {
|
|
|
|
if (item === undefined)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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]));
|
|
|
|
}
|