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 🙏

© 2025 – Pkg Stats / Ryan Hefner

set-hello-badge-1-text-and-attribute

v0.0.6

Published

Set Hello Badge Tutorial #1: Demonstrates the data-set-text and data-set-attribute attributes.

Readme

Screenshot of the final result

Set Hello Badge Tutorial: Text & Attribute (Part 1 of 4)

This is a very simple example for the Set template engine (Git it now!)

It demonstrates how to set up Set for use with Express and how to use the data-set-text and data-set-attribute Set attributes to set the value of the text and attribute of a DOM element.

Usage

  1. Clone the repository.
  2. Run npm install to install the dependencies.
  3. Run npm start to start the server.

Once the server is running, go to http://localhost:3000 to see the example and http://localhost:3000/hello-badge.html to see the template source.

Read the notes below to find out how it works and take a peek at the source code.

How it works

Templates in Set are pure HTML 5. Set uses data- attributes with the set namespace (data-set-) to populate templates either on the server or on the client (or both).

In this simple example, we create a simple name badge that links back to the user’s home page.

The name of the user and the link to their homepage are variables (perhaps from a database, although in this example we hard code them).

The template

Let’s start by creating a template called hello-badge.html in the /views folder. It will contain a paragraph tag to hold the title of the label (’Hello, my name is’) and a nested span into which the name of the user will be added when the Set template is compiled.

<p>Hello, my name is <span data-set-text='name'>Inigo Montoya</span></p>

The attribute data-set-text tells Set to replace the text of the span tag with the property name that’s in the data provided to the template.

Since Set templates are pure HTML, you can design in the browser with the template even before the server is ready (and work on both can continue in parallel). Unlike Moustache‐style template engines like Handlebars, etc., your template is What You See Is What You Get.

Next, we wrap the paragraph tag in an anchor tag for the link. This time, instead of the text of the anchor tag, we want to change its href attribute, so we use the data-set-attribute attribute instead.

<a data-set-attribute='href homepage'><p>Hello, my name is <span data-set-text='name'>Inigo Montoya</span></p></a>

To specify multiple attributes, just separate them with a semicolon.

The server

The server couldn’t be simpler. Here’s all the code:

express = require 'express'
set = require 'indie-set'

app = express()
app.engine 'html', set.__express
app.set 'view engine', 'html'
app.use express.static('views')

data = {
		name: 'Aral'
	,	homepage: 'http://aralbalkan.com'
}

app.get '/', (request, response) ->
	response.render 'hello-badge', data

app.listen 3000

We set up Express and create a static data object with name and homepage properties. When the default route is called on the server with a GET request, we render the hello-world.html template, passing it the data object.

That’s it!

Unlike other unobtrusive frameworks like Plates and Notemplate, Set has no mapping code to write. It just works.

Continue learning about Set in Part 2: Repetition.

Table of Contents

This is just a very simple example. Check out the Set web site for more complicated ones.