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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@momsfriendlydevco/vue-template

v1.0.1

Published

Compile a simple HTML string via Vue style templates

Downloads

14

Readme

@MomsFriendlyDevCo/Vue-Template

Compile a simple HTML string via Vue style templates.

This package exports a single function to compile a Vue-style template and return a render function which can then be provided with data.

import vueTemplate from '@momsfriendlydevco/vue-template';

let template = vueTemplate('<div>Hello {{name}}</div>');

await template({name: 'Joe'}); //~= "<div>Hello Joe</div>"
await template({name: 'Jane'}); //~= "<div>Hello Jane</div>"

All built in Vue directives are supported:

var vueTemplate = require('@momsfriendlydevco/vue-template');

var template = vueTemplate(`
	<body>
		<p>Hello {{user.name.first}} {{user.name.last}}</p>
		<p>
			Your favourite color
			<span v-if="user.color.toLowerCase() == 'blue'">is blue</span>
			<span v-else>is<strong>NOT</strong>blue</span>
		</p>
		<p>
			Your pets are:
			<ol v-if="user.pets && user.pets.length">
				<li v-for="pet in user.pets">
					{{pet.name}} ({{pet.type}})
				</li>
			</ol>
			<span v-else>You have no pets (aw!)</span>
		</p>
	</body>
`);

template({
	user: {
		name: {first: 'Joe', middle: 'H', last: 'Random'},
		color: 'Red',
		pets: [
			{name: 'Pepper', type: 'Cat'},
			{name: 'Meg', type: 'Dog'},
		],
	},
}) //~= Compiled version of the above template

Support table

The below is a non-exhaustive list of templating functions that are supported. If you find a Vue feature that isn't listed below please file an issue or add a test for it.

| Feature | Supported | Notes | |-------------|--------------------|--------------| | v-if | :white_check_mark: | | | v-on | :no_entry_sign: | events | | v-for | :white_check_mark: | | | v-pre | ? | | | v-bind | ? | | | v-else | :white_check_mark: | | | v-else-if | :white_check_mark: | | | v-html | ? | | | v-once | :no_entry_sign: | events | | v-show | ? | | | v-slot | :no_entry_sign: | components | | v-text | ? | | | v-cloak | ? | | | v-model | ? | | | :class | :white_check_mark: | classes | | :style | ? | |

Notes:

  • classes - All styles of class binding are supported (e.g. static, lookup, array lookup, objects, mixed)
  • components - At this point this module does not support custom components
  • events - Events are entirely unsupported as this is a "one-pass" templator that returns HTML and does not react to async states

API

vueTemplate(html)

Compile raw HTML into a Vue render function and return a template wrapper function. See template(data) for documentation on how to use the templator return.

template(data)

Takes an object of context data to use when rendering, renders the template and returns the HTML output. All functions are automatically converted into Vue component methods.