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

mithril-armor

v0.0.5

Published

A composition utility for Mithril.js

Readme

Mithril Armor

...because everyone loves some top-tier armor.

Mithril Armor is this fun little idea I had to make reusable Mithril calls via partial application.

How can I use it?

This script exposes itself as a commonjs module you can use via require.

var armor = require('mithril-armor');

I also prefer using a instead of armor, since Mithril is m.

Developing

  1. npm install
  2. npm run build to output a minified and unminified script into /dist
  3. npm run tests to run tests, of course.

Actual usage

Mithril armor is fairly simple to use. The idea is based on setting up base Mithril objects as high order functions and extending them on a per-instance basis. Let's say we want a button.

var button = a('button');

Great! Now Mithril Armor returns a function that we can further call things on. You can use the button variable to add a danger class to an instance of m('button', ...).

var danger = button({class: 'danger'}) // This is one parameter short

And now we can make several danger buttons:

var perilous  = danger('This is perilous');
var arduous   = danger('This is arduous');
var upsetting = danger('This is upsetting');

At the end of the day, these parameters will be called via mithril, so mixing and matching with Mithril calls isn't a problem.

You can call the final parameter on an element and store it in a variable, or you can feel free to extend off of the base element button that was defined previously

var component = {
  view: function() {
    return m('div', [
      perilous,
      arduous,
      upsetting,
      button({class: 'custom'}, 'Based off button'),
      button({class: 'other'}, 'Other button'),
      m('button', 'THE ORIGINAL. THE O.G.')
    ])
  }
}

Void Elements

Mithril handles things like input or img (and a handful of others) differently, in that they're self-closing elements that don't have child content, these are referenced internally as voids, or void elements. So where other elements will return a function for further extending, this handful of tags that will return a mithril object after the tag and attrs properties have been filled.

var input = a('input')
var text = input({type: 'text'});
var button = input({type: 'button', value: 'Click me!'})

var image = a('img')
var horse = image({src: 'fake/path'})
var cat   = image({src: 'different/fake/path'})

Structuring your armor

I've still been working on the way to best setup families of armor functions. So far I think an object-per-HTML-element approach works well. Not only does it make sense from a grouping perspective, writing the armor extensions in mithril code makes more sense

Assuming we have corresponding styling in place:

var paragraph = {
  base: a('p');
}
// <p class="strong"></p>
paragraph.bold      = paragraph.base({class: 'strong'});

// <p class="emphasis"></p>
paragraph.italic    = paragraph.base({class: 'emphasis'});

// <p class="obnoxious"></p>
paragraph.obnoxious = paragraph.base({class: 'obnoxious'});

As a result, you can reference these easily in mithril calls:

var p = paragraph;

m('div', [
  p.bold('This is some ridiculously bolded text');
  p.italic('Spooky italic text. Boo!');
  p.obnoxious('You get the idea');
])

This approach works especially well if you're like me and you enjoy decoupling EVERYTHING and using require via commonjs. So if you end up having a folder for each of your individual elements (I like to call them iotas), you can easily export the initial object after adding all of your armor extensions to that object.

Notes

What this tool is for

This tool is meant for you to group together and create small pieces of mithril calls (thematically, I like to call them fragments) that you will eventually group together to create Mithril objects.

What this tool is not for

This is not a catch-all tool for every element you're going to run into when you're coding your virtual dom tree, it's meant as a utility to make crafting Mithril calls based on a single established variable. If it doesn't work for your use case, you should ask yourself "Could I just call Mithril directly here?", and most of the time the answer will be YES. that'll be just fine!

Thanks!

Thanks for checking out the repo! Thanks to @lhorie for creating Mithril, @tivac for introducing me to Mithril, and the Mithril gitter chatroom for being awesome people!