Stylings / Restructuring
This commit is contained in:
@@ -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)
|
||||
|
||||
11
src/utils.ts
11
src/utils.ts
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user