
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
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 1 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 1 open source maintainer 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.