-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathdependencies.ts
More file actions
21 lines (17 loc) · 974 Bytes
/
dependencies.ts
File metadata and controls
21 lines (17 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import type { Page } from '@sveltejs/kit';
import { useTerminology } from './terminology';
import { Dependencies } from '$lib/constants';
import type { DependenciesResult, Term, TerminologyResult } from './types';
export function useDependencies(pageOrTerms: Page | TerminologyResult): DependenciesResult {
// source is in `TerminologyResult`.
const terminology = 'source' in pageOrTerms ? pageOrTerms : useTerminology(pageOrTerms);
const getDependencies = (term: { title: Term }) => ({
singular: Dependencies[term.title.singular.toUpperCase() as keyof typeof Dependencies],
plural: Dependencies[term.title.plural.toUpperCase() as keyof typeof Dependencies]
});
return {
entity: terminology.entity ? getDependencies(terminology.entity) : undefined,
field: terminology.field ? getDependencies(terminology.field) : undefined,
record: terminology.record ? getDependencies(terminology.record) : undefined
};
}