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

4p_template

v0.4.1

Published

A template Engine for Express/NodeJs

Downloads

26

Readme

4p_jstemplate

4p Logo

Important if you use NodeJs, jsdom 3.1.2 is required

npm install -S 'jquery@>=2.1'
npm install -S '[email protected]'

(Note that version 3.1.2 of jsdom is required, because as of jsdom version 4.0.0, jsdom no longer works with Node.js. If you use Io.js rather than Node.js, you can use the latest 4.x release of jsdom.) https://github.com/UncoolAJ86/node-jquery https://www.npmjs.com/package/jsdom

    /* GET home page. */
    router.get('/', function(req, res) {
        var file = 'views/index.html'; // our template file template
        fs.readFile(file, function (err, content) {
            if (err) throw err;

            // init template
            var tpl = $4p_template.template(content.toString()); 

            // some data
            var template_data = { 
                bar: 'hello world',
                deep: {'foo': {'bar': 'this data is in deep.foo.bar'}},
                list: ['hop', 'hip', 'hap', 'yip', 'yep']
            };     

            t = tpl.element.html(tpl.render(template_data)); // render to dom

            // tpl.element is a jquery instance of our template element
            tpl.element.find('li').css('color', 'red'); // play with it !

            // handle more complex structure and play with dom
            tpl.renderAfter('table', ''); // render <table>
            for (i = 1; i <= 11; i++) {
                tpl.renderAfter('table-line', {cell: [i, i * i]});  // push rendered data in table                
            }

            var rendered = t.html(); // get html
            res.send(t.html()); // send output     
        });
    };

test it: http://jsfiddle.net/mkdgs/FvBnX/

i've made this template engine, with some idea similar to handlebar, but all presentational template logic is in javascript (we have don't need to learn a new template language again) and it's easy to mix html and javascript, like php with html.

you can reuse your template and define repetitive subpart of it.

in template all data is mapped to a $4p.templateData object and has three method is(), iterate(), v()

$4p.templateData object can contain value mixed value scalar, array, or object

is('with','data','path') is used to traverse data tree, this return a $4p.templateData. that's return the data object corresponding to the data path. if the data path not exist he return a $4p.templateData with null value, so if there no value your code is not breaking and you have not to worry about he data was or was not defined.

iterate() is used to make a loop throught $4p.templateData object if it's contain object or array value

v() return the data value passed in template contained in this object

give me a feedback ;)

The templating part is inspired, like many other, from our Guru: http://ejohn.org/blog/javascript-micro-templating/