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

piece-of-cake

v0.1.0

Published

JavaScript controller library

Readme

PieceOfCake

JavaScript like it should be

Install

npm install piece-of-cake

or just include a script tag, like

<script src="https://unpkg.com/piece-of-cacke"></script>

  1. Define your html like ever:
<body>
    <input placeholder="what to to next?"/>
    <button onclick="addTodo" disabled>Add</button>
    <ul><!-- todo entries shall go here --></ul>

    <script>
        // functions like 'addTodo' and 'onChangeFilter' go here
    </script>
</body>
  1. Extract your event handling functions into there own scope, where they belong:
class MyControllerClass {

     addTodo() {
        const input = document.getElementsByTagName("input")[0]
        const list = document.getElementsByTagName("ul")[0]
        const value = input.value        
        const li = document.createElement("li")
        li.innerText = value
        list.apendChild(li)        
    }
    
}
  1. Extend the PieceOfCake Controller to get access to some useful helper methods (this is optional)
class MyControllerClass extends PieceOfCake.Controller {
    //...
}
  1. Simplify bindings to dom elements you need to access in your event handlers
    <input placeholder="what to to next?"/>
    <button onclick="addTodo" disabled>Add</button>
    <ul data-id="todolist">
        <!-- use a standard data tag here. Nothing special. No Side-effects -->
    </ul>
class MyControllerClass extends {

    get input() {
        return this.find("input")
    }

    get list() {
        return this.findByDataID("todolist")
    }

    addTodo() {
       // ...
    }
    
}
  1. Store your state in its own field, where it belongs:
class MyControllerClass extends {

    get todos() {
        return this._todos || [] // 'this._todos' is a kind of backing field. Nothing special. Just JavaScript
    }

    set todos(value) {
        this._todos = value
    }

    addTodo() {
       // ...
       this.todos = [this.todos, text]
       // ... update todo <ul>
    }
    
}
  1. Connect your rendering logic to methods that update your state to keep your controller clean
class MyControllerClass extends {

    set todos(value) {
        this._todos = value
        this._renderTodos()
    }

    addTodo() {
       this.todos = [this.todos, text]
    }

    _renderTodos() {
        this.list.innerHTML = ""
        this.todos.forEach(text => {
            const li = document.createElement("li")
            li.innerText(text)
            this.list.appendChild(li)
        })
    }
    
}
  1. Make your controller class visible to the library and connect it to a specific sub-tree of your dom it should control
PieceOfCake.controllerClasses.push(MyControllerClass)
    <body data-controller="MyControllerClass">
        <!-- Nothing special with the data-attribute. But you must call it 'conrtoller', otherweise the library won't find it-- >
    </body>
  1. Use optional field and element binding shorthands in your controller
class MyControllerClass extends {
    static elements = {
        input: "input",     // this will bind 'this.input' to an element w/ data-id="input"
        list: "todolist"
    }

    static fields = {
        todos: {                    // this will create a getter and setter for the field 'todos'
            defaultValue: [],       // it creates a backing field w/ default Value []
            set(value) {            // define custom behavour after the backing field was updated here
                this._renderTodos
            }
        }
    }
}

Example

Just look at the basic and advanced to get an idea of how things work.