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

crisp-ui

v2.5.0

Published

A lightweight UI and MVC framework

Downloads

5

Readme

Crisp UI

This is a lightweight MVC and templating tool that gets out of your way and lets you do things the way you want. It's dubbed a "tool" and not a "framework", because it doesn't enforce particular workflows or structures.

Usage

Install via NPM:

npm install crisp-ui

Or clone this repo and use the crisp.js or crisp.min.js files

To use the Crisp UI features, require it like this:

require('crisp-ui');

Routing

The router uses the Express-style routing patterns. Params and queries are accesible through the Crisp.Router namespace.

Crisp.Router.route('/pages/:page', () => {
    console.log('You are on page ' + Crisp.Router.params.page + '!');
});

Views

The View class, which is accessible through the Crisp.View namespace, can be used in a number of ways.

Creating a view

The bare minimum for creating a view, so it can be instantiated and stored in memory, is this:

class MyView extends Crisp.View {
    constructor(params) {
        super(params);
    
        this.fetch();
    }
}

Using templates

You can plug in any templating engine you like, or use the one built into Crisp UI

class MyView extends Crisp.View {
    constructor(params) {
        super(params);
        
        // Option 1: Require an external template
        this.template = require('./MyTemplate.js');
    
        this.fetch();
    }
    
    // Option 2: Use the template directly
    template() {
        // Using The built-in Crisp UI templates
        return _.h1({class: 'my-element'}, this.model.title);
        
        // Using EJS
        return ejs.render('<h1><%= title %></h1>', this.model);
    }
}

Instantiating

You can instantiate a View in 3 ways:

// Providing the model directly
new MyView({
    model: { title: 'Hello!' }
});

// Using a URL to fetch the model from
new MyView({
    modelUrl: '/api/data'
});

// Using a custom function
new MyView({
    modelFunction: (resolve) => {
        let data = { title: 'Hello!' };

        resolve(data);
    }
});

Templating

Crisp UI comes with its own optional templating system, which is function based, meaning that you can assign behaviour to your elements as you create them. It extends the browser built-in createElement function and includes a few extra conveniences.

All templating logic exists within the Crisp.Elements namespace, but you can use the _ character as a shortcut.

Creating an element

All HTML5 elements are represented with a dedicated function. The first parameter is an optional object containing the element attributes. Any other argument is assumed to be child content. It can be just a string or other templating logic.

const _ = Crisp.Elements;

_.button({class: 'my-button'},
    'My button',
    _.span({class: 'my-icon'})
)

Assigning behaviour

An advantage of rendering elements using functions is that you can assign behaviour to the elements right as you create them.

const _ = Crisp.Elements;

// Separated handler example
_.button({class: 'my-button'},
    'My button',
    _.span({class: 'my-icon'})
).click(onClickMyButton);

// In-line handler example 
_.button({class: 'my-button'},
    'My button',
    _.span({class: 'my-icon'})
).click((e) => {
    console.log('Clicked a button', e.currentTarget);
})