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

stimp

v1.3.4

Published

Small lib for organize your JS by modules with state management and DOM elements autoselection

Downloads

25

Readme

stimp.js logo

stimp.js

Small lib for organize your JS by modules with state management and DOM elements autoselection

JS docs here

Install

via NPM

npm i stimp

or via Yarn

yarn add stimp

or from CDN:

<script src="https://unpkg.com/stimp@latest/dist/stimp.js"></script>

Features

Apps and modules for project organization

import Stimp from 'stimp';

window.app = new Stimp.App('main'); // create app with name "main"

const helloModule = app.addModule(Stimp.Module, 'hello'); // add module with name "hello"
helloModule.onInit(() => { // add some module code
  console.log('I have just init!');
});

app.init(); // init the app

You can access the module by "app.modules.hello".

State management in React.js style

const statefulModule = app.addModule(Stimp.Module, 'statefulModule', { // add stateful module
  isShow: false, // initial state
});

statefulModule.onInit(() => {
  setInterval(() => {
    statefulModule.setState({ // setting the new state
      isShow: !statefulModule.state.isShow
    });
  }, 1000);
});

statefulModule.onUpdateIsShow = (currentVal, prevVal) => { // add reaction on state change
  console.log(`now isShow is ${currentVal}, but before it was ${prevVal}`);
};

DOM elements auto selection for each module

On frontend you often need to interact with DOM. To do that you need to select elements (by jQuery or native JS functions). Stimp can do it for you without any JS-code. You just need to add some HTML-attributes to target tags. For example, we have this html:

<div -m="menu" class="menu">
  <div class="menu__cont">

    <button -ch="burger" class="menu__burger">open</button>

    <nav -ch="nav">
      <ul>
        <li -ch="navEl" -i="link1"><a href="#">link 1</a></li>
        <li -ch="navEl" -i="link2"><a href="#">link 2</a></li>
        <li -ch="navEl" -i="link3"><a href="#">link 3</a></li>
        <li -ch="navEl" -i="link4"><a href="#">link 4</a></li>
        <li -ch="navEl" -i="link5"><a href="#">link 5</a></li>
        <li -ch="navEl" -i="link6"><a href="#">link 6</a></li>
        <li -ch="navEl" -i="link7"><a href="#">link 7</a></li>
      </ul>
    </nav>

  </div>
</div>

There are 3 custom attributes:

  • "-m" for module scope - use here exact module name
  • "-ch" for module children - use here any value
  • "-i" for module's children list, but with separate it by ID - use here any value

In JS we add this code:

const menu = app.addModule(Stimp.DOMInteractModule, 'menu', { // add dom interactive module
  isShow: false, // initial state
});

menu.onAfterDomInit(() => { // after DOM was selected
  let dom = menu.dom; // access to the DOM elements
  let root = menu.dom.root; // access to the root module element with attribute "-m"
  let burger = menu.dom.burger; // access to the child element with attribute "-ch='burger'"
  let navEls = menu.dom.navEl; // access to the child elements with attribute -ch="navEl" -i="*"
  let firstNavEl = navEls.link1; // access to the child elements with attribute -ch="navEl" -i="link1"

  burger.addEventListener('click', () => { // add some state changing on burger button click
    menu.setState({ isShow: !menu.state.isShow });
  });
});

menu.onUpdateIsShow = (currentVal, prevVal) => { // add reaction on state change
  if (currentVal) { // if isShow is true - add class 'show' to the module root
    menu.dom.root.classList.add('show')
  } else { // if isShow is false - remove class 'show'
    menu.dom.root.classList.remove('show')
  }
};

Modules init by their depends (when module "A" should be initialized before module "B")

In some cases you need to init modules in exact order. To do that you can use module dependencies.

const a = app.addModule(Stimp.DOMInteractModule, 'a', {}); // module a
const b = app.addModule(Stimp.DOMInteractModule, 'b', {}, ['a']); // module b with module a in dependencies
const c = app.addModule(Stimp.DOMInteractModule, 'c', {}, ['a']); // module c with module b in dependencies
const d = app.addModule(Stimp.DOMInteractModule, 'd', {}, ['c', 'a']); // module d with module c and a in dependencies

The modules will init in this order:

  • module a
  • module b and module c in any order
  • module d after module a and c was init