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

Davis

v0.8.2

Published

Simple, degradable JavaScript routing using HTML5 pushState.

Downloads

4

Readme

Davis.js

Description

Davis.js is a small JavaScript library using HTML5 history.pushState that allows simple Sinatra style routing for your JavaScript apps.

Why

Using the history pustState and popstate events allows the links and forms in your app to have hrefs and actions that point to real end points on your server. This allows complex JavaScript apps to degrade gracefully when JavaScript is unavailable and combining this with a template system that can be used both client and server side allows for large amounts of code reuse.

Davis.js is heavily inspired by Sammy.js (hence the name), it is however intentionally much lighter than Sammy.js because I never use any of the template rendering etc that it includes. All Davis.js does is provide a simple routing layer, nothing more, nothing less.

Requirements

Davis.js requires jQuery 1.4.2+ as well as a modern browser that supports HTML5 history.pushState and the onpopstate event. At the moment that means FireFox 4+, Safari 5+, Chrome, iOS Safari 4+*, Android Browser 2.2+, Opera 11.50+.

In all other browsers Davis.js is currently unsupported, all links and forms will have their default behaviour. You can bind to the 'unsupported' event on an app to handle this situation in your code. Fallback to location.hash and onhashchange is a possibility in the future.

*Whilst pushState is supported in iOS it has several, fairly serious bugs. Davis will not fire the unsupported event though as technically iOS does support davis.

Installation

Download davis.min.js and include it on your page after jquery.

Example

A very simple example of a Davis.js app:

var app = Davis(function () {
  this.get('/welcome/:name', function (req) {
    $('body').append('<h1>Hello there, ' + req.params['name'] + '!</h1>')
  })
})

$(document).ready(function () {
  // append a link to trigger the route
  $('body').append('<a href="/welcome/bob">Greet</a>');
  
  app.start();
})

We create a new instance of a Davis.App using the Davis.js function, passing in a function that will draw the routes for the application. Inside this function this is the instance of our application.

We define a simple get route with a 'name' parameter and a callback that will append a message to the html body. Inside the route callback this is set to the request that matches the route, this request is also passed as a parameter to the callback.

Once the app is configure it needs to be started. You start a Davis.js app by calling the start method, this must be done once the document is ready. Now if you click on the link that we appended to the body our route should be called and a friendly greeting printed on the page.

To use Davis your html file must be loaded from a server rather than just opening the file in your browser.

More

API docs

Example using davis.js and a mustache templates shared between the client and the server, code

Contributing

Contributions are more than welcome, to make the process easier and quicker please follow these guidelines:

  • Open an issue detailing the bug fix or feature in your patch.
  • Add test cases for your code.
  • Don't change the version or build new versions as part of you patch.

Running examples

First you'll need node installed for the server. Then execute the following command and visit one of the examples: http://localhost:3000/examples/todo.html.

$ make test

Feedback

Any feedback or suggestions are welcome via issues.