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

@cranbee/template

v0.7.0

Published

Cranbee Template Engine

Readme

Cranbee Template Engine

This is a library for working with Cranbee Templates.

Introduction

Let's start with an example.

This is how a template may look like:

<!-- This is a test template -->
<div class="prodlist">
    <div each="{item in items}" class="prodlist__item {item.mods}">
        <img if="{item.imageUrl}" src="{item.imageUrl}"/>
        <div fi="{item.imageUrl}" class="prodlist__noimage"></div>
        <a href="{item.url}" class="prodlist__title">{item.title}</a>
        <div class="prodlist__brand">{item.brand}</div>
        <div if="{item.isAvailable}" class="prodlist__price">€ {item.price}</div>
        <button if="{item.isAvailable}" class="prodlist__add">Add to cart</button>
        <div fi="{item.isAvailable}" class="prodlist_na">Not available</div>
    </div>
</div>

Syntax looks like HTML, but the library does not know about HTML. There are just tags, texts and some special stuff.

Also let's introduce some data:

{
    items: [
        {
            title: "Product A-1",
            brand: "Brand A",
            price: "9.90",
            url: "/products/a-1.html",
            imageUrl: "/images/products/a-1.jpg",
            isAvailable: true,
            mods: "_av"
        },
        {
            title: "Product Z-2",
            brand: "Brand Z",
            url: "/products/z-2.html",
            isAvailable: false,
            mods: "_na"
        }
    ]
}

Then we can run the Template Engine and get a result:

result = f(template, data);

The result for the template and data above will be:

[
    {
        type: "div",
        props: { class: "prodlist" },
        children: [
            {
                type: "div",
                props: { class: "prodlist__item _av" },
                children: [
                    {
                        type: "img",
                        props: { src: "/images/products/a-1.jpg" },
                        children: []
                    },
                    {
                        type: "a",
                        props: { href: "/products/a-1.html", class: "prodlist__title" },
                        children: [{ type: "#", text: "Product A-1" }]
                    },                    
                    {
                        type: "div",
                        props: { class: "prodlist__brand" },
                        children: [{ type: "#", text: "Brand A" }]
                    },
                    {
                        type: "div",
                        props: { class: "prodlist__price" },
                        children: [{ type: "#", text: "€ 9.90" }]
                    },
                    {
                        type: "button",
                        props: { class: "prodlist__add" },
                        children: [{ type: "#", text: "Add to cart" }]
                    }
                ]
            },            
            {
                type: "div",
                props: { class: "prodlist__item _na" },
                children: [
                    {
                        type: "div",
                        props: { class: "prodlist__noimage" },
                        children: []
                    },
                    {
                        type: "a",
                        props: { href: "/products/z-2.html", class: "prodlist__title" },
                        children: [{ type: "#", text: "Product Z-2" }]
                    },
                    {
                        type: "div",
                        props: { class: "prodlist__brand" },
                        children: [{ type: "#", text: "Brand Z" }]
                    },
                    {
                        type: "div",
                        props: { class: "prodlist_na" },
                        children: [{ type: "#", text: "Not available" }]
                    }
                ]
            }
        ]
    }
]

The library lets you get this tree and does not care what you are going to do with it.

Nodes

A template and a result are arrays of nodes. And there are 2 kinds of nodes.

(1) Text nodes:

{
    type: "#",
    text: string
}

(2) Tag nodes:

{
    type: string,   // tag name
    props: object,  // tag properties
    children: array // array of child nodes
}

Installation

$ npm install @cranbee/template

Library API

parse(text: string): array

Parses the template source and returns an array of nodes.

execute(template: array, data: object): array

Executes the template with the data and returns an array of nodes.

pack(template: array): array

Packs the template to a compact view.

unpack(packet: array): array

Unpacks the template.

Example

let Template = require("@cranbee/template");

let source = '<a href="{url}">{title}</a>';
let data = { url: "https://example.com", title: "Example" };

let template = Template.parse(source);
let result = Template.execute(template, data);

console.log("Template nodes:")
console.log(JSON.stringify(template));
console.log();
console.log("Result nodes:")
console.log(JSON.stringify(result));

Output:

Template nodes:
[{"type":"a","props":{"href":"{url}"},"children":[{"type":"#","text":"{title}"}]}]

Result nodes:
[{"type":"a","props":{"href":"https://example.com"},"children":[{"type":"#","text":"Example"}]}]

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

License

MIT