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

repage

v2.0.2

Published

Extensions for page.js, a client-side micro-router

Downloads

24

Readme

repage.js

Extensions to visionmedia/page.js, an Express-inspired client-side router.

Status CodeClimate Coveralls

Basic usage

Use repage as you typically would use page.js. (This new page object is a decorated version of the original page.js page.)

var page = require('repage');

page('/', index);
page('/user/:user', show);
page('/user/:user/edit', edit);
page('/user/:user/album', album);
page('/user/:user/album/sort', sort);
page('*', notfound);
page();

Quick reference

The new page object implements all the API of visionmedia/page.js, plus other convenient extensions described later. As such, refer to the page.js API first.

// routing:
page('/', index)           // calls `index()` when navigating to /
page('*', notfound)        // calls `notfound()` for all pages
page.base('/blog')         // sets the base path

// navigation:
page('/users')             // navigate to /users
page.replace('/users')     // replaces the current state with /users

These are features only available in repage.js:

page('/user/:id', { id: 20 })           // navigates to /user/20
page('/search', { q: 'hello' })         // navigates to /search?q=hello
page.replace('/search', { q: 'hello' }) // navigates by replacing

page.uri('/user/:id', { id: 20 })       // returns "/user/20" (string)
page.redirect('/users')                 // redirects to /users from a route

page.back()                             // goes back, or returns home if available

Installation

Via npm or bower

The npm version lists page.js as a dependency, while the bower version ships as a standalone .js file.

$ npm install --save repage
$ bower install --save repage

npm version

Standalone

Download or hotlink: repage.js. It will then be exported as window.page.

API

page()

page([options])

Starts the page.js engine by binding event listeners to dispatch routes. See page.js API for details.

var page = require('repage');
page('/', index);
page('/user/:user', show);
page('*', notfound);
page();

page(path)

page(path, [params])

Navigate to the given path.

$('.view').click(function (e) {
  e.preventDefault();
  page('/user/12');
});

You may also specify params for params to be replaced in the paths placeholders. (Only in repage.js)

page('/user/:id', { id: 12 });
// same as `page('/user/12')`

replace()

page.replace(path, [params])

Works like page(path), but replaces the current state instead of pushing it. Great for form submission pages.

You may also specify params for params to be replaced in the paths placeholders, like in page('path'). (Only in repage.js)

$('.submit').on('click', function () {
  $.post('/submit', function (article) {
    alert("data saved");
    page.replace('/article/:id', { id: article.id });
  });
});

len

page.len

Number of pages navigated to. (Only in repage.js)

page.len == 0;
page('/login');
page.len == 1;

uri()

page.uri(path, options)

Builds a URI path with dynamic parameters, mimicking Express's conventions. (Only in repage.js)

page.uri('/api/users/:id', { id: 24 });
=> "/api/users/24"

Also builds query strings.

page.uri('/api/trip/:id', { id: 24, token: 'abcdef' });
=> "/api/trip/24?token=abcdef"

Great for using with req.params or req.query.

querystring()

page.querystring(data)

Converts an object into a query string. (Only in repage.js)

page.querystring({ name: 'john smith', count: 3 })
=> "name=john%20smith&count=3"

back()

page.back([path])

Goes back. If path is given, it will navigate to that instead when there's no page to go back to. (Only in repage.js)

document.getElementById('back').onclick = function() {
  // either goes back, or returns to the homepage when there's
  // no page to go back to.
  page.back('/');
};

redirect()

page.redirect(path, params)

Navigates to path. Works like page(path) or page.replace(), but suitable to be used inside a route. (Only in repage.js)

page('/login', function (ctx) {
  page.redirect('/sessions/new');
});

page('/dashboard', function (ctx) {
  if (!authenticated)
    page.redirect('/login');
});

teardown()

page.teardown()

Removes all traces of repage.js. Mostly useful in tests.

Thanks

repage.js © 2014+, Rico Sta. Cruz. Released under the MIT License. Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz