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 🙏

© 2024 – Pkg Stats / Ryan Hefner

regierung

v2.0.0

Published

Govern your website's JavaScript

Downloads

5

Readme

Regierung

npm

~~Organize~~ Govern your website's JavaScript

This package is a bare-bones implementation of the awesome Conditioner library. It solves the same problem but with less features and less complexity.

If you're building a plain-old website, this is for you. If you're building a client-side app and using a framework, you can happily move on.

It's less than 1 Kb minified and gzipped.

Install

With npm do:

npm i regierung

If you're using Yarn, you know what to do.

Usage

Regierung is glue for 3 things: your HTML, your JavaScript code and your bundler.

JavaScript should be organized in modules. Modules are functions that take a DOM element, and can optionally return another function for cleaning up.

You have a module:

function ToUppercase (element) {
  let oldValue = element.textContent

  element.textContent = oldValue.toUpperCase()

  return () => {
    element.textContent = oldValue
  }
}

In your HTML:

<p data-module="ToUppercase">
  Alles wird besser, aber nichts wird gut.
</p>

Then when your website loads, you can do:

import { run } from 'regierung'

run()

And you get:

ALLES WIRD BESSER, ABER NICHTS WIRD GUT.

Without any configuration, Regierung expects all modules to be globally available, that is attached to window. But you're probably doing better…

Code splitting

Regierung truly shines when used together with a modern module bundler like Webpack, Parcel or Rollup.

This way you can have your modules organized in files, and they will be loaded only when needed.

You need to tell Regierung how to find your modules, using dynamic import:

import { run } from 'regierung'

run({
  getModule: name => import(`./modules/${name}.js`).then(x => x.default)
})

The module from earlier:

// ./modules/upper.js
export default function (element) {
  let oldValue = element.textContent

  element.textContent = oldValue.toUpperCase()

  return () => {
    element.textContent = oldValue
  }
}

The HTML:

<p data-module="upper">
  Alles wird besser, aber nichts wird gut.
</p>

Notice you give it the name of the file in the data-module attribute (upper), and you specify the path to it in the getModule callback (./modules/${name}.js).

Media queries

You can have your modules run based on a media query, via the data-module-media attribute:

<p data-module="upper" data-module-media="(min-width: 60em)">
  Alles wird besser, aber nichts wird gut.
</p>

This uses the matchMedia API, so it will react to the browser window resizing.

Contributing

PRs accepted.

License

Apache 2.0