New SQL tables structure

This commit is contained in:
Clément Pons
2025-04-30 17:44:54 +02:00
parent 871861e66e
commit df3577f673
25 changed files with 2755 additions and 358 deletions

View File

@@ -12,11 +12,26 @@ export function unifySlug(slug: string | string[]): string
{
return (Array.isArray(slug) ? slug.join('/') : slug);
}
export function group<
T,
K extends keyof T,
V extends keyof T,
KeyType extends string | number | symbol = Extract<T[K], string | number | symbol>
>(
table: T[],
key: K & (T[K] extends string | number | symbol ? K : never),
value: V
): Record<KeyType, T[V]> {
return table.reduce((p, v) => {
p[v[key] as KeyType] = v[value];
return p;
}, {} as Record<KeyType, T[V]>);
}
export function parsePath(path: string): string
{
return path.toLowerCase().trim().replaceAll(" ", "-").normalize("NFD").replaceAll(/[\u0300-\u036f]/g, "").replaceAll('(', '').replaceAll(')', '');
}
export function parseId(id: string | undefined): string |undefined
export function parseId(id: string | undefined): string | undefined
{
return id;
return id?.normalize('NFD')?.replace(/[\u0300-\u036f]/g, '')?.replace(/^\d\. */g, '')?.replace(/\s/g, "-")?.replace(/%/g, "-percent")?.replace(/\?/g, "-q")?.toLowerCase();