Created
May 22, 2024 20:45
-
-
Save pdaug/d5d47290f6948a6b8a13cd21c52d7adc to your computer and use it in GitHub Desktop.
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
type ServiceHtmlElementParameters = { | |
tag: string; | |
close?: boolean; | |
attributes?: Record<string, string>; | |
children?: string; | |
}; | |
export const ServiceHtmlElement = function ({ tag, close, attributes, children }: ServiceHtmlElementParameters): string { | |
const attributesEntries = Object.entries(attributes || new Object()); | |
const attributesConverted = attributesEntries.map(function ([key, value]) { | |
const attribute = `${key}="${value}"`; | |
return attribute; | |
}); | |
const attributeJoinned = attributesConverted.join(" "); | |
const element = (children || close) ? | |
`<${tag} ${attributeJoinned}> | |
${children || ""} | |
</${tag}>` | |
: | |
`<${tag} ${attributeJoinned} />`; | |
return element; | |
}; | |
export default ServiceHtmlElement; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wise code!