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

staplerjs

v1.0.1

Published

Use javascript variables directly in your HTML.

Readme

staplerjs

Use javascript variables directly in your HTML.

StaplerJS is NOT a templating engine that allows you to reuse HTML snippets and fill it with data. No, instead of taking the data as the source of the application it makes the view leading. Is it usefull? I have no idea! Let me know if you see any benefit.

Installation

Bower

bower install staplerjs

NPM

npm install staplerjs

Basic usage

HTML

<html>
<head>
  <title>Hello $stapler.space</title>
</head>
<body>
  <h1>Hello $stapler.space</h1>
  <input type="text" value="$stapler.space" />

  <script src="/staplerjs/dist/stapler.min.js"></script>
</body>
</html>

JavaScript

var scope = { space: "world" };

Stapler(document.documentElement, scope);

scope.space = "room";

Documentation

Variables in HTML

A variable in your HTML is recognized by a scope name prefix. The default scope name is $stapler, but you can define your own as well (see Bind scope to HTML).

A variable as text content of an element can be used as follows:

<h1>$stapler.title</h1>
<p>$stapler.post.content</p>
<footer>© tsoffereins $stapler.year</footer>

You can alse use a variable as the value of an attribute:

<a href="$stapler.link">click me</h1>

Input-like elements also support two-way binding; for example:

<input type="text" value="$stapler.title" />

This will print the value of foo in the input field, but will also update foo when t;he user changes the text.

Scope

A scope is the base object you use to feed your HTML. This object can have nested objects and keys with any value except for array.

var scope = { 
  title: "StaplerJS",
  blog: {
    content: "lorem ipsum dolor sit amet"
  },
  year: 2018,
  link: "dev.tsoffereins.com"
};

When a variable points to a function in the scope, this function is executed and the return value used in the view.

var scope = { 
  title: function() {
    return "Stapler" + "JS";
  }
};

Bind scope to HTML

A scope is bound to a piece of HTML using the Stapler function.

Stapler(document.body, scope);

If you want a custom name for your scope (instead of $stapler), you can pass it as the first parameter; make sure it is not too common. The scope name is used in the regular expression to find matches in your html, special characters are escaped.

Stapler('$myScope', document.body, scope);

Changing the scope.

The scope variable is an object and therefor a reference, changing its contents will result in the view being updated with the new value.

scope.title = "Anything";
<h1>$stapler.title</h1> <!-- prints "Anything" -->

StaplerJS uses smart parsing when the scope is bound to the HTML; this means that only the nodes that contain the changed variable will be updated; it won't rerender anything else.

Since the view is in the lead, it does not matter if the data is absent. Whenever the data appears on the scope it will be used by the view again.

scope.blog = null;
<h1>$stapler.blog.content</h1> <!-- prints "" -->
scope.blog = { content: "foo bar" };
<h1>$stapler.blog.content</h1> <!-- prints "foo bar" -->

Support

You can reach me via Twitter: @tsoffereins

Please file issues here at GitHub.