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

vv-template-html

v0.0.1-beta.8

Published

A lightweight HTML template engine for JavaScript

Readme

vv-template-html

轻量级的 HTML 模板加载与渲染库(TemplateHTML)。

特性

  • 全局单例:TemplateHTML
  • 按需加载并缓存模板(.html)
  • 简单的渲染 API:getTemplate / render
  • 支持多种 baseUrl 格式
  • 提供 TypeScript 类型定义

快速开始

在页面中引入构建产物:

<script src="template-html.min.js"></script>
<!-- 或使用 CDN 引入 -->
<script src="https://cdn.jsdelivr.net/npm/vv-template-html@latest/template-html.min.js"></script>
<script src="https://unpkg.com/vv-template-html@latest/template-html.min.js"></script>
<script>
  (async function () {
    console.log(TemplateHTML.VERSION);
    TemplateHTML.baseUrl = "/template/"; // 可选
    await TemplateHTML.render("main", {}, document.body, (main) => {
      console.log(main);
    });
  })();
</script>

示例文件:index.html

API 概览

  • TemplateHTML.VERSION: string(只读)
  • TemplateHTML.AUTHOR: string(只读)
  • TemplateHTML.baseUrl: string(可读写,支持多种格式)
  • TemplateHTML.templates: { [key: string]: HTMLElement }(只读缓存)
  • TemplateHTML.getTemplate(templateName: string, params: object): Promise<HTMLElement>
  • TemplateHTML.customProtocol(protocol: string): void
  • TemplateHTML.render(templateName: string, params: object, element: HTMLElement, callback?: (element: HTMLElement) => void): Promise<void>

自定义错误类:TemplateHTMLError(继承自 Error)

baseUrl 支持格式

  • file:// 协议路径
  • /./../ 开头的相对路径(会基于 location.origin 解析)
  • http:// 或 https:// 完整 URL

设置示例:

TemplateHTML.baseUrl = "file:///C:/templates/";
TemplateHTML.baseUrl = "/template/";
TemplateHTML.baseUrl = "https://cdn.example.com/templates/";
TemplateHTML.baseUrl = "template://";

错误处理

  • 无效模板名、无法加载、模板空等情况会抛出 TemplateHTMLError,请在调用处捕获处理。

TypeScript

项目包含类型定义文件 template-html.d.ts,在 TypeScript 项目中可直接使用全局 TemplateHTML 和 TemplateHTMLError 类型。

贡献与许可

  • 作者:IFTC
  • 许可证:MIT

欢迎提交 issue 或 PR 以改进功能或修复 Bug。