Created
December 17, 2023 16:20
-
-
Save jonasgeiler/12e0ac83b5dd39d0e1720d7aa47ccf3d to your computer and use it in GitHub Desktop.
Super basic implementation of an XML equivalent of JSON.stringify in JavaScript/TypeScript.
This file contains hidden or 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
const XML = { stringify: (value: any, tag: string) => `<${tag}>` + Object.entries(value).reduce((p, [k, v]) => p + (v && typeof v === 'object' ? XML.stringify(v, k) : `<${k}>${v}</${k}>`), '') + `</${tag}>` }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Result: