Created
March 5, 2024 05:23
-
-
Save hisamafahri/d7fa0ba3c21e89212afda713744e678c to your computer and use it in GitHub Desktop.
axiom like json stringify formatter. https://i.imgur.com/nM3x94w.png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface CustomObject { | |
[key: string]: unknown; | |
} | |
const formatObject = (obj: CustomObject): JSX.Element => ( | |
<span> | |
{"{"} | |
{Object.keys(obj).map((key, index) => ( | |
// eslint-disable-next-line react/no-array-index-key | |
<span key={index}> | |
<b>{key}</b>:{" "} | |
{typeof obj[key] === "object" | |
? formatObject(obj[key] as CustomObject) | |
: (obj[key] as string)} | |
{index < Object.keys(obj).length - 1 && ", "} | |
</span> | |
))} | |
{"}"} | |
</span> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment