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

jstemplate

v0.2.5

Published

A pure Javascript templating engine for node.js

Downloads

25

Readme

JSTemplate - A pure Javascript templating engine for node.js

JSTemplate is a simple and pure-Javascript templating engine for node.js

Installing

npm install jstemplate

A basic template

<%
   var
        title = "Mr";
-%>
Hello <%= title %> <%= args.sir -%>

Processing a template

var
    JSTemplate = require('jstemplate'),
	jst = new JSTemplate({viewDir: 'views'});

jst.process("basic.jst",{sir:process.env.LOGNAME},function(err,output){
    if ( err )
        throw err;
    console.log(output);
});

Settings

The JSTemplate object supports the following settings:

  • viewDir : The directory containing the templates (or views)

  • statInterval : The interval of time (in ms) that a template file is stat()'ed and the modify time is watched to see if the template file was changed. Default to 5000

  • useLayout : Defines if the layout.jst will be used to encapsulate the result of the processed template. Defaults to: true

The syntax

  • <% CODE %> : Everything between <% and %> will be evaluated as javascript. Example: <% var x = 666; %>

  • <%= VARIABLE|STATEMENT %> or <%? VARIABLE|STATEMENT %> : Prints the result of a variable or statement

  • <& file.jst, {a:1,b:2} | p &> : Includes template file.jst and pass {a:1,b:2} as arguments (args variable); Optional | p flag can be passed to just pre-process the template so it can be included with jst.include()

Spaces and indentation

Optionally all tags can finish with a - (example <% args.somevar -%>) telling that the next return's should be discarded;

Accessible variables

These variable are accessible by the template code:

  • args : The object containing the template arguments

  • jst : The global JSTemplate object

API

The JSTemplate object exposes the following API:

  • print(str) : Prints a string

  • dump(obj) : Prints the dump of an object

  • include(file,args) : Includes a template and call it with the specified arguments

  • next() : Calls the next template on the execution stack (ninjas only)

  • html(str) : Converts some data on something that is safe to use on a HTML page

  • url(str) : Converts some data on something linkable (escape)

  • global variable : A place where you can store some global data

Questions and suggestions

Mail me.