(refactor) rename and move entriesWithKeys and getWithKey utilities to ~~/shared/utils

This commit is contained in:
Valentyne Stigloher 2025-08-01 20:36:06 +02:00
parent 9425d88df1
commit 9142a99b22
8 changed files with 7 additions and 6 deletions

View File

@ -16,7 +16,7 @@ const config = useConfig();
const nounsData = await loadNounsData();
const nouns = computed((): Noun[] => {
return withKey(nounsData.classes ?? {})
return entriesWithKeys(nounsData.classes ?? {})
.map((nounClass): NounClassInstance => ({ classKey: nounClass.key, stems: props.stemValues }))
.map((classInstance, i): NounRawWithLoadedWords => ({
id: `template-${i}`,

View File

@ -7,7 +7,7 @@ const nounsData = await loadNounsData();
<template>
<ul v-if="nounsData.groups" class="list-group mt-4">
<li
v-for="nounConventionGroup of withKey(nounsData.groups)"
v-for="nounConventionGroup of entriesWithKeys(nounsData.groups)"
:key="nounConventionGroup.key"
class="list-group-item"
>

View File

@ -11,7 +11,7 @@ if (nounsData === undefined) {
throw new Error('nounsData is undefined');
}
const visibleNounConventions = computed(() => {
return withKey(nounsData.conventions ?? {}).filter((nounConvention) => {
return entriesWithKeys(nounsData.conventions ?? {}).filter((nounConvention) => {
return props.nounConventionGroup.conventions.includes(nounConvention.key);
});
});

View File

@ -30,7 +30,7 @@ const id = useId();
<template>
<h5><T>nouns.submit.regular.stems.header</T></h5>
<p><T>nouns.submit.regular.stems.description</T></p>
<template v-for="stem of withKey(nounsData.stems ?? {})" :key="stem.key">
<template v-for="stem of entriesWithKeys(nounsData.stems ?? {})" :key="stem.key">
<label :for="`${id}-stem-${stem.key}`">{{ stem.name }}</label>
<input
:id="`${id}-stem-${stem.key}`"

View File

@ -25,7 +25,7 @@ const findNounConvention = async (path: string, config: Config) => {
const nounsData = await loadNounsData();
return withKey(nounsData.conventions ?? {})
return entriesWithKeys(nounsData.conventions ?? {})
.find((nounConvention) => nounConvention.key === path);
};

View File

@ -16,6 +16,7 @@ import type {
Gender,
Numerus,
} from '~~/shared/nouns.ts';
import type { WithKey } from '~~/shared/utils/entriesWithKeys.ts';
export class PronounExample {
singular: Example;

View File

@ -1,4 +1,4 @@
import type { WithKey } from '~/utils/withKey.ts';
import type { WithKey } from '~~/shared/utils/entriesWithKeys.ts';
export default <T>(record: Record<string, T> | undefined, key: string | undefined): WithKey<T> | undefined => {
if (key === undefined || record?.[key] === undefined) {