Skip to content

Commit

Permalink
create toJson replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
horrible-little-slime committed Nov 11, 2024
1 parent 5d40b68 commit 295ce05
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1470,3 +1470,19 @@ export function totalFamiliarWeight(
(familiar.feasted ? 10 : 0)
);
}

/**
* 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;
});
}

0 comments on commit 295ce05

Please sign in to comment.