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

just-template-it

v0.0.1

Published

Simple templating system.

Downloads

2

Readme

just-template-it

A simple template system.

NPM

Installation

npm install just-template-it [--save]

JavaScript usage.

Initialise the Template system:

var templates = require('just-template-it');
templates.init("/path/to/templates", "type");
// Or just:
var templates = require('just-template-it').init("/path/to/templates", "type");

The above code will initialise the system and set the base path to /path/to/templates, it will also set the file type of the templates to .type (the second param is optional, default filetype is jti).
The path and filetype can be changed by using the setTemplatePath(path, type) function.
Observe: setting new path will remove all currently loaded templates.

To fetch a template use the getTemplate function:

templates.getTemplate('nameOfTemplate', {
  "aString": "Some text...",
  "aObj": {"aInt": 5},
  "array": [1,"test",9]
}, function(error, formattedTemplate) {
  if(error) {
    //
  } else {
    //
  }
});

getTemplate takes three arguments:
First is the name of the template, this is without file end, so the nameOfTemplatetemplate in the above example should in the filesystem be at: /path/to/templates/nameOfTemplate.type.
Second parameter is the data object that the template system should replace placeholders with (see further down in readme for more info about placeholders in the template files).
And the third and last parameter is a callback function. The callback takes two args:
First is error, which will only be set if there was an error during run.
Second is the template, formatted and ready withe all placeholders replaced with the data passed in.

The template files.

The template files is quite simple.
They are basically a text file with placeholders (duh), and depending on what data is passed in, the file will replace the placeholders.

Simple example:

Testing {aString}
{aObj.aInt} is a number.
{array[2]} {array[3]}

Using the above js code, this template will be formatted as:

Testing Some text...
5 is a number.
test 9

Just-template-it supports the following placeholders:

  • Include (includes another template file): - {include|filename}
  • Key-value-pair: "key": "value" - {key}
  • Objects: "obj": {"key":"val"} - {obj.key}
  • Arrays: "arr": [1,2,3] - {arr[1]}

Check out the example code in the example dir if more info about usage is needed.