
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
tsx-to-html
Advanced tools
A simple jsx runtime to transform your tsx into html strings.
className
hacks// tsconfig.json
{
"jsx": "react-jsx",
"jsxImportSource": "tsx-to-html"
}
import { toHtml } from "tsx-to-html"
toHtml(<div class="foo"></div>) // '<div class="foo"></div>'
You can influence how jsx elements (hast elements) are being transformed into strings
by pushing a properties transformer (Properties -> Properties
) into the
propertiesTransformers
array.
In fact that's what this library is doing to transform class and style objects to strings:
import * as TSX from "tsx-to-html";
TSX.propertiesTransformers.push((properties) => {
if ("class" in properties && isObject(properties["class"])) {
properties["class"] = Object.entries(properties["class"])
.filter(([, enabled]) => enabled)
.map(([key]) => key)
.join(" ");
}
return properties;
});
You can use a Record<string, boolean>
to define which classes will be included
in the output
toHtml(<div class={{foo: true, bar: false}}></div>) // '<div class="foo"></div>'
Inline styles can be given via a CSSStyleDeclaration
object, similar to react.
toHtml(<div style={{display: "flex", flexDirection: "column"}}></div>) // '<div style="display:flex;flex-direction:column"></div>'`
Every other lib I've seen writes a lot of pre-existing logic themselves. Why not just re-use libraries like hastscript who have millions of downloads per week and will probably do their job better and faster?
FAQs
A simple jsx runtime to transform your tsx into html strings.
The npm package tsx-to-html receives a total of 13 weekly downloads. As such, tsx-to-html popularity was classified as not popular.
We found that tsx-to-html demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.