Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
typed-html
Advanced tools
[![Build Status](https://travis-ci.org/nicojs/typed-html.svg?branch=master)](https://travis-ci.org/nicojs/typed-html)
Html templates have never been this easy. Type safe using plain TypeScript with a minimal runtime footprint.
This:
// example.tsx
const items = ['item', 'item2'];
function handleClick(event: MouseEvent) { }
const icon = 'icon-add';
<ul>
{items.map(i => <li>{i}</li>)}
</ul>;
<button onClick={click}>
<i class={icon}></i>
</button>
Becomes:
<ul>
<li>item</li>
<li>item2</li>
</ul>
<button on-click="handleClick">
<i class="icon-add"></i>
</button>
Install:
npm install --save typed-html
Configure your TypeScript compiler for JSX:
{
"compilerOptions": {
// ...
"jsx": "react",
"jsxFactory": "elements.createElement"
}
}
Now create a *.tsx file. For example: example.tsx
with the following content:
// example.tsx
import * as elements from 'typed-html';
const w = 'world';
const strongTag = <p>Hello <strong>{w}</strong></p>;
typeof strongTag; // => Just a string of course
All template scenarios are supported with plain TypeScript.
Conditional template with ?
<div>Random > 0.5: {Math.random()>.5 ? <strong>yes</strong> : 'no'}</div>
Repeat a template with Array.map
const items = ['item', 'item2'];
<ul>
{items.map(i => <li>{i}</li>)}
</ul>;
Want a helper template? Just call a function
function listItem(n: number) {
return <li>{n}</li>;
}
<ul>
{[1, 2].map(listItem)}
</ul>
The way this works is by using TypeScript's jsx support, but not for jsx/react interoperability. Instead, it defines the normal html tags as IntrinsicElements
in the JSX namespace.
At runtime, the elements.createElement
function is called for every html tag. It simply converts the given element to a string with minimal overhead.
FAQs
TypeSafe HTML templates using TypeScript. No need to learn a template library.
The npm package typed-html receives a total of 1,905 weekly downloads. As such, typed-html popularity was classified as popular.
We found that typed-html demonstrated a not healthy version release cadence and project activity because the last version was released 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.