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

minichoo

v1.0.2

Published

a smaller, standalone version of choo without using any virtual DOM

Downloads

2

Readme

minichoo

a smaller (10KB bundle), standalone version of choo without using any virtual DOM

assumptions

this library assumes there is a div with an id of "app" to mount the app too. this library assumes the browser is modern but should work ok with babel-polyfill

idea

  • when you want choo but smaller and without node api or babel polyfill
  • live off the land: use template strings directly and completely avoid the virtual DOM
  • make it attach to the window like jquery suitable for a small script tag dependency
  • no need to bundle or build

todo:

  • add examples for using forms
  • finish documentation
  • allow mount to attach to any DOM element
  • scrutinize use of innerHTML and template strings for security issues!
  • security review and audit
  • create version using commonjs modules suitable for browserify

include in a html page

<link rel="stylesheet" href="https://unpkg.com/tachyons/css/tachyons.min.css">
<script src="https://unpkg.com/[email protected]/minichoo.min.js"></script>

<div id="app"></div>

example

var app = minichoo()

app.use(function (state, emitter) {
  state.demo = 1;
})

app.route('/', function (state, emitter) {
  state.ready(() => {
    console.log('dom is ready')
  })
  window.increment = function () {
    state.demo++; // this does not re-render the page automatically
    // this is a cheap trick to re-render the page
    window.location = '#/'
  }
  return `
  <article class="vh-100 dt w-100 bg-dark-pink">
    <div class="dtc v-mid tc white ph3 ph4-l">
      <h1 class="f6 f2-m f-subheadline-l fw6 tc">minichoo :: demo: ${state.demo}</h1>
      <a href="#!" class="f6 link dim br1 ba bw2 ph3 pv2 mb2 dib navy" onclick="window.increment()">increment</a>
      <a class="f6 link dim br1 ba bw2 ph3 pv2 mb2 dib navy" href="#/page2">go to page 2</a>
    </div>
  </article>
  `
})

app.route('/page2', function () {
  return `<article class="vh-100 dt w-100 bg-dark-pink">
    <div class="dtc v-mid tc white ph3 ph4-l">
      <h1 class="f6 f2-m f-subheadline-l fw6 tc">minichoo :: page 2</h1>
      <a class="f6 link dim br1 ba bw2 ph3 pv2 mb2 dib navy" href="#/">go home</a>
    </div>
  </article>`
})

app.mount()

minichoo

this is the minichoo source code without deps: (nanorouter and nanobus)...


// minichoo
//
function minichoo () {
  if (! (this instanceof minichoo)) return new minichoo ()
  this.middleware = []
  this.routes = {}
  this.state = {}
  this.params = {}
  var self = this
  this.emitter = Nanobus()
  this.router = Nanorouter()
  setTimeout(() => {
    this.app = document.getElementById("app")
  })
  window.onhashchange = function() {
    var current_route = location.hash.replace(/\#/g, '') || '/#';
    // <a href="#!" will be ignored...
    if (!current_route.includes('!')) self.router.emit(current_route)
  }
}

minichoo.prototype._finish_setup = function () {
  var self = this
  Object.keys(self.routes).forEach(function (route) {
    self.router.on(route, function (params) {
      self.state.params = params
      self.app.innerHTML = self.routes[route](self.state, self.emitter)
    })
  })
}

minichoo.prototype.use = function (middleware) {
  assert.ok(typeof middleware === 'function')
  this.middleware.push(middleware)
}

minichoo.prototype.route = function (route, handler) {
  assert.ok(typeof route === 'string')
  assert.ok(typeof handler === 'function')
  this.routes[route] = handler;
}

minichoo.prototype.mount = function (element) {
  var self = this;
  var default_middleware = function (state, emit) {
    state.ready = function (...args) { return setTimeout(...args); }
    state.form = function addForm (id, callback) {
      var form = document.getElementById(id)
      form.addEventListener('submit', function (e) {
        e.preventDefault()
        var data = new FormData(e.currentTarget)
        callback(data, e)
      })
    }
  }
  default_middleware(self.state, self.emitter)
  self.middleware.forEach(function (middleware) {
    middleware(self.state, self.emitter)
  })
  self._finish_setup()
  setTimeout(function () {
    self.app.innerHTML = self.routes[
    Object.keys(self.routes)[0]
    ](self.state, self.emitter)
  }, 1000)
}

window.minichoo = minichoo;

gotchas

  • uses hash based routing so you must do this: <a href="#/some-route" instead of <a href="/some-route"