diff --git a/src/lib.ts b/src/lib.ts index 8cc4f7e1ea..8f3abc554b 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1471,6 +1471,22 @@ export function totalFamiliarWeight( ); } +/** + * JSON-ify an object with mafia constants rendered legibly + * @param obj The object to convert to a JSON string + * @returns A JSON string + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function toMafiaJson(obj: any): string { + return JSON.stringify(obj, (_, value) => { + const mafiaClass = MafiaClasses.find( + (mafiaClass) => value instanceof mafiaClass, + ); + if (mafiaClass) return `[${mafiaClass.name}]${value}`; + return value; + }); +} + export const familiarTags = Object.freeze([ "animal", "insect",