Stylings / Restructuring

This commit is contained in:
Sebastian Seedorf
2022-08-14 10:49:11 +02:00
parent 7682aeaea1
commit 76f508a847
17 changed files with 333 additions and 137 deletions

View File

@@ -1,8 +1,11 @@
import {EnrichedEntity, Entity} from "../types";
import details from "../../res/details.json";
import manual from "../../res/manual.json";
const factories = (details as Entity[]).map((detail: EnrichedEntity) => {
detail.usedBy = (details as Entity[])
const joined = [...details, ...manual] as Entity[]
const factories = joined.map((detail: EnrichedEntity) => {
detail.usedBy = joined
.filter(f => Object
.keys(f.recipe?.prerequisites ?? {})
.includes(detail.href)

View File

@@ -1,3 +1,5 @@
import {FC, PropsWithChildren} from "react";
export function isNonNullable<T>(any: T): any is NonNullable<T> {
return any !== undefined && any !== null
}
@@ -10,3 +12,12 @@ export function sortByProperty<T>(transform: (val: T) => number | string): (a: T
return a2 === b2 ? 0 : -1
}
}
export function groupBy<T>(arr: T[], transform: (val: T) => string): Record<string, T[]> {
const result: Record<string, T[]> = {}
for (const elem of arr) {
const key = transform(elem)
result[key] = [...(result[key] ?? []), elem]
}
return result
}