npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@typematter/svelte-unist

v1.0.4

Published

Transform [Unist](https://github.com/syntax-tree/unist) (Universal Syntax Tree) into Svelte 5 components.

Readme

Svelte Unist

Transform Unist (Universal Syntax Tree) into Svelte 5 components.

This package provides the foundational rendering engine for Unist ASTs. It's designed to be extended by specialised packages like @typematter/svelte-hast for HTML and @typematter/svelte-mdast for Markdown.

Features

  • Flexible Rendering: Default rendering for parent and literal nodes with support for custom components
  • Extensible: Designed to be extended via custom component maps
  • Error Boundaries: Built-in error handling with graceful fallbacks
  • Performance Optimised: Context passed efficiently through the component tree
  • Type Safe: Full TypeScript support with proper type inference
  • Svelte 5: Built with modern Svelte 5 runes

Installing

npm install @typematter/svelte-unist

# or
yarn add @typematter/svelte-unist

# or
pnpm add @typematter/svelte-unist

Usage

Basic Usage

<script>
	import { Unist } from '@typematter/svelte-unist';

	const ast = {
		type: 'root',
		children: [{ type: 'text', value: 'Hello, World!' }]
	};
</script>

<Unist {ast} />

With Custom Components

Use specialised packages that provide component implementations for specific AST types:

<script>
	import { Unist } from '@typematter/svelte-unist';
	import { components } from '@typematter/svelte-hast';

	const ast = /* your HAST tree */;
</script>

<Unist {ast} {components} />

With Error Handling

Catch rendering errors and send them to your error tracking service:

<script>
	import { Unist } from '@typematter/svelte-unist';
	import { components } from '@typematter/svelte-mdast';

	const ast = /* your MDAST tree */;

	function handleError(error, reset) {
		console.error('Rendering error:', error);
		// Send to error tracking service
		// Optionally call reset() to retry rendering
	}
</script>

<Unist {ast} {components} onerror={handleError} />

When a custom component fails, the error boundary will:

  1. Call your onerror handler (if provided)
  2. Fall back to default rendering (showing children/literal values)
  3. Add an HTML comment with error details for debugging

API

<Unist>

The main component for rendering Unist ASTs.

Props:

  • ast (required): The Unist AST to render
  • components (optional): Map of node types to Svelte components
  • onerror (optional): Error handler (error: unknown, reset: () => void) => void
  • Additional context properties can be added via module augmentation (e.g., getDefinition for MDAST)

Utilities

The package also exports utility functions for working with Unist trees:

import { visit, collect } from '@typematter/svelte-unist';
import { isHeading } from '@accuser/unist-util-type-guards';

// Visit all heading nodes
visit(ast, isHeading, (node) => {
	console.log('Heading:', node);
});

// Collect all heading nodes into an array
const headings = collect(ast, isHeading);

Extending

Creating Custom Components

You can create your own component mappings:

<!-- MyParagraph.svelte -->
<script>
	let { node } = $props();
</script>

<p class="custom">
	{#each node.children as child}
		<Node node={child} />
	{/each}
</p>
<!-- App.svelte -->
<script>
	import { Unist } from '@typematter/svelte-unist';
	import MyParagraph from './MyParagraph.svelte';

	const components = {
		paragraph: MyParagraph
	};

	const ast = /* your AST */;
</script>

<Unist {ast} {components} />

Extending Context

Specialised packages can extend the UnistContext interface to add domain-specific functionality:

declare module '@typematter/svelte-unist' {
	interface UnistContext {
		// Add custom properties
		getDefinition?: (identifier: string) => Node | undefined;
	}
}

Development

# Install dependencies
pnpm install

# Start development server
pnpm dev

# Run type checking
pnpm check

# Run tests
pnpm test

# Build and package
pnpm build

# Lint code
pnpm lint

# Format code
pnpm format

License

MIT

Copyright

Copyright © 2025 Matthew Gibbons