Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ultrahtml

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ultrahtml

A 1.75kB library for enhancing `html`. `ultrahtml` has zero dependencies and is compatible with any JavaScript runtime.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
680K
increased by10.12%
Maintainers
1
Weekly downloads
 
Created
Source

ultrahtml

A 1.75kB library for enhancing html. ultrahtml has zero dependencies and is compatible with any JavaScript runtime.

Features

  • Tiny, fault-tolerant and friendly HTML-like parser. Works with HTML, Astro, Vue, Svelte, and any other HTML-like syntax.
  • Built-in AST walk utility
  • Built-in transform utility for easy output manipulation
  • Automatic but configurable sanitization, adhering to the HTML Sanitizer API
  • Handy html template utility
walk

The walk function provides full control over the AST. It can be used to scan for text, elements, components, or any other validation you might want to do.

import { parse, walk, ELEMENT_NODE } from 'ultrahtml';

const ast = parse(`<h1>Hello world!</h1>`);
walk(ast, (node) => {
  if (node.type === ELEMENT_NODE && node.name === 'script') {
    throw new Error('Found a script!')
  }
})
render

The render function allows you to serialize an AST back into a string.

import { parse, render } from 'ultrahtml';

const ast = parse(`<h1>Hello world!</h1>`);
const output = await render(ast);
transform

The transform function provides a straight-forward way to swap in-place elements (or Components) and update them with a new value.

import { transform, html } from 'ultrahtml';

const output = await transform(`<h1>Hello world!</h1>`, {
  components: {
    h1: (props, children) => html`<h1 class="ultra">${children}</h1>`
  }
})

console.log(output) // <h1 class="ultra">Hello world!</h1>

Acknowledgements

Keywords

FAQs

Package last updated on 24 Sep 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc