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 🙏

© 2025 – Pkg Stats / Ryan Hefner

html-to-vue3

v0.1.4

Published

Converts HTML to Vue render functions, while giving the ability to swap out certain HTML nodes with Vue Components

Readme

What does it do

This small library takes a well-formed HTML and transforms into vue render functions, while also giving you the possibility to swap in some vue components in place of HTML nodes.

Why has it been made

To solve a basic problem: what if you need to, for example, substitute an anchor tag coming from your headless CMS of choice and transform it into your own Cta.vue element?

Of course there are many ways to do that, for example you could leverage <component :is="{ template: ... }"> power, but this requires the full Vue build (which is 30% bigger), and pull a lot of unnecessary things in. This library is just ~4KB (~2KB gzipped).

Drawbacks

Html needs to be well-formed. This library uses html-parse-stringify, which is super small, but requires to have well formed HTML.

Note: HTML entities are not parsed. Therefore, HTML entities parsing has to be handled beforehand.

How to use it

Install it

npm install --dev html-to-vue or yarn add --dev html-to-vue

Use it like this in a functional vue component

    import { renderHtml } from 'html-to-vue';
	const conf = {
		config: { ... },
		rawHtml: '<div> Hello world! </div>'
	}
    export default {
		functional: true,
		render (h, context) {
			return renderHtml(conf.rawHtml, conf.config, h, context)
		}
	}

Configuration

Below is the default configuration, which you can override

	{
	  // This object sets up the container of the HTML that gets rendered
	  container: {
	    type: 'div'
	  },
	  // This object contains Vue components that substitutes HTML node (look at next section)
	  extraComponentsMap: {},
	  /*
	   You can conditionally pass a function which transform text Nodes (e.g.: to handle html entities)
	   */
	  textTransformer: text => text
	}

extraComponentsMap

extraComponentsMap contains objects with two callbacks: conditions and renderer.

  • conditions(node) should return whether a node has to be swapped or not
  • renderer(node, children, createElement) renders the vue component.

For example, let's say we need to transform each anchor with class="btn" into our own Button.vue component, our extraComponentsMapobject will look like this:

Button.vue:

<template>
  <div class="button">
    <slot />
  </div>
</template>
<script>
  export default {};
</script>
	extraComponentsMap: {
		customButtonConfig: {
			conditions(node) {
				return (
					node.type === 'tag' && // is a tag
					node.name === 'a' && // is an anchor
					node.attrs?.class?.match(/btn\s?/) // has btn class
				)
			},
			renderer(node, children, createElement, context) {
			    const options = getOptionsFromNode(node)
				return createElement(
					Button,
					{
						class: options.class,
						attrs: options.attrs,
						style: options.style,
						on: {
							click: () => {
								const emit_event = context.listeners['click'];
								emit_event("Hello world!");
							}
						}
					},
					[...children] // parsed children, in our case it will probably be just a text child
			}
		}
	}

Helper functions

  • getOptionsFromNode(node): This function takes in a node and spits out an object that matches vue-compliant options from the node attributes