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

@tghp/groundwork.js

v2.3.1

Published

A no-nonsense approach to managing and initiating JS.

Readme

groundwork.js

A no-nonsense approach to managing and initiating JS.

Groundwork provides a convenient way to:

  1. Organise code run on every page
  2. Run code against DOM elements in a component-like way

Usage

import Groundwork from "@tghp/groundwork.js";
const groundworkMain = new Groundwork("main");

// Add includes
groundworkMain.includes.add("header", require("./main/includes/globals"));

// Add components
groundworkMain.components.add("video", require("./main/components/video"));

// Initialise
groundworkMain.run();

or

import Groundwork from "@tghp/groundwork.js";
import globalInclude from './main/includes/globals';
import videoComponent from './main/components/video';
const groundworkMain = new Groundwork("main");

// Add includes
groundworkMain.includes.add("header", globalInclude);

// Add components
groundworkMain.components.add("video", videoComponent);

// Initialise
groundworkMain.run();

Refer to concepts below to understand this usage.

Concepts

The Groundwork class

Create an instance of groundwork passing a string. This is akin to a namespace. This namespace is used for any data attributes.

Includes

Includes are run every time, as soon as groundwork is run. Each include should return a method, this method is called with no arguments.

Components

Inspired by Magento 2's data-mage-init, components execute as a result of `data-gw-${namespace}-init` attributes. Pass this attribute JSON where the root key is the name of the component and the value is another object providing arguments to the component (if needed).

For example:

<!-- In this example, no args are passed to the component  -->
<div data-gw-main-init='{"video": {}}'></div>

<!-- In this example, we pass some args to the component -->
<div data-gw-main-init='{"video": { id: 123456, autoplay: false }}'></div>

Components should export a method, this is what is called with the DOM node as the first argument and the args as the second:

module.exports = (elem, args) => {
  // Component logic here
};

Component Instances

If the component function returns something (for example, an object providing an API) groundwork will add an `data-gw-${namespace}` attribute to the DOM element, providing an instance reference that can used with getInstance to get the instance of that component.

Component functions are called using Function.prototype.call() assigning this to the groundwork class, so getInstance is then available to you.