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

tpjs

v3.8.3

Published

最简洁高效的js模板引擎!

Readme

TP 模板引擎

Tp 是一个 “轻量,简洁,高效” 的 javascript 模板引擎!

npm version

简介

+ 轻量,tp是目前能见到最轻量的javascript模板引擎,只有一个不足1.5k的文件。
+ 简洁,tp的语法非常简单,对于一个熟悉html、js的开发人员来说学习难度为 0。
+ 高效,tp支持模板预编译,快于任何一个你所见过的javascript模板引擎。
+ 另外,tp同时支持在浏览器环境使用及服务端javascript环境(Node.js)使用。

联系作者

+ 您可以发邮件到 [email protected]
+ 或者访问 http://www.houfeng.net
+ 关注微博 http://weibo.com/houfeng

在浏览器中吏用

在页面中引入

+ 下载tp
+ 将tp.js或tp-min.js放到项目中合适的位置。
+ 在相关页面用<script src='tp的url'></script>引入tp。

AMD/CMD 方式引用

var tp = require('相对路径');

解析(tp.parse)

代码:

var html='<div>My name is <% $(name) %></div>';
var rs=tp.parse(html,{name:'tp'});

结果:

rs: “<div>My name is tp</div>”

编译(tp.compile)

代码:

var html='<div>My name is <% $(name) %></div>';
var fn=tp.compile(html);
var rs=fn({name:'tp'});

结果:

fn: 编译结果,可以暂存以供调用。
rs: “<div>My name is tp</div>”

HTML元素

HTML:

<script id="list-template" type='text/template'>
<% for(var i in this %>
<li><% $(this[i]) %></li>
<% } %>
</script>

<ul id="list">
</ul>

代码:

//绑定数据:
tp.bind({
	template:'list-template',
	element:'list',
	model:["item-1","item-2"]
}); 
//追加绑定数据:
tp.bind({
	template:'list-template',
	element:'list',
	model:["item-1","item-2"],
	append:true
}); 

结果:

<ul id="list">
<li>item-1</li>
<li>item-2</li>
</ul>

在 Node.js 中使用

安装

[sudo] npm install tpjs [-g]

引用

var tp = require('tpjs');

//解析
var rs = tp.parse(html,options);
//预编译
var fn = tp.compile(html,options);

命令行工具

使用命令行工具需要全局安装 tpjs,如下

[sudo] npm install tpjs -g

CLI 说明

tp <src> <dst>
  1. src: 源文件路径,相对于当前工作目录
  2. dst: 输出的目标路径,相对于当前工作目录