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

ts-template

v1.0.0

Published

template engin

Readme

ts-template

嘿嘿嘿,一个基于模板字符串的模板引擎的最简实现~, 只适用于node环境,

usage 使用

模板字符串的语法,发挥想象吧,嘿嘿嘿~

test.js

const RenderClass = require('ts-template');

const renderVm = new RenderClass({
  rootName: 'root', // 数据跟字段 defaut: 'root'
  baseDir: '' // 模板根目录 defaut: path.join(process.cwd(), 'view');
  cache: true, // 是否缓存 defaut: true
})

renderVm.render('test.html', data)
renderVm.renderString('<div>${root.a} + ${root.b} = ${root.a + root.b}</div>', {
  a:1,
  b:2
})

test.html

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <title>ts-template</title>
  <style type="text/css">
    body {
      background: rebeccapurple;
    }
  </style>
  <script>
    var a = ${root.a};
  </script>
</head>

<body>
  include模板:
  ${await this.include('aa.html')}
  <div>嘿嘿嘿</div>
  1341<br>

  转意:
  ${e(root.b)}

  自运行函数:
  ${(() => { return 'adadfadfasdf' })()}
</body>

</html>

extension 扩展

const RenderClass = require('ts-template');
class SubRenderClass extends RenderClass {
  constructor(opt) {
    super(opt)
  }
  // format函数
  dateFormat(data, 'yyyy-MM-dd') {
    // ...
  }
  // async 函数
  async getFileData(fileName) {
    return new Promise((resolve, reject) => {
      fs.readFile(file, (err, data) => {
        if (err) {
          reject(err);
        } else {
          resolve(data.toString('utf-8'));
        }
      });
    });
  }
} 
const renderVm = new SubRenderClass({
  rootName: 'root', // 数据跟字段 defaut: 'root'
  baseDir: '' // 模板根目录 defaut: path.join(process.cwd(), 'view');
  cache: true, // 是否缓存 defaut: true
})

renderVm.renderString('<div>${_.dateFormat(root.time)}</div> <div>${await _.getFileData(root.file)}</div>', {
  time: 1518344445732,
  file: '/path/to/file.txt'
})
// 或者
renderVm.renderString('<div>${this.dateFormat(root.time)}</div> <div>${await this.getFileData(root.file)}</div>', {
  time: 1518344445732,
  file: '/path/to/file.txt'
})