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

@ublitzjs/router

v0.1.3

Published

![ublitzjs](https://github.com/ublitzjs/core/blob/main/logo.png)

Readme

ublitzjs

@ublitzjs/router package

This package removes your headache when sorting the routes, helps with validation and "asynchronous" quirks of uWS

Contents

  • classes Router and ExtendedRouter, created in openapi-like manner;
  • classes LightController and HeavyController for making structured controllers, including their validation and error-handling;
  • jsonSchemas function, which, isn't as fast as manually written validation schemas along with parsing body, but it lets you write a json parser for LightController and HeavyController in 30 seconds, instead of several minutes.

Router and ExtendedRouter

Router

All the difference is that Router can have only controllers, meanwhile in ExtendedRouter you can pass additional data.

import { Router } from "@ublitzjs/router";
import { App } from "uWebSockets.js";
import { DeclarativeResponse } from "@ublitzjs/core";
var server = App();
var router = new Router({
  //in this current object you create routes
  "/": {}, //you can even leave it like so
  "/:id": {
    // in this object you can create methods as simple uWS handler
    get(res, req) {
      res.end("hello, " + req.getParameter(0));
    },
    post: new DeclarativeResponse().end("hello"),
    // also websockets
    ws: {
      open(ws) {
        ws.send("hello");
      },
    },
    any(res, req) {
      res.end("hello");
    },
    // and HeavyController or LightController, but about it below
  },
});

after defining router you should use some methods of it (which can be chained one by one)

//1.1) with this you tell uBlitz to register routes on such server
router.bind(server);
//1.2) by this you tell to register get and websockets, but NOT post request. This is heavily typed in typescript, so don't worry about misspelling your routes
router.define(/*route*/ "/:id", /*...methods*/ "get", "ws");
//1.3) you can add prefixes. if you use .define after it - route will be prefixed. If you use .prefix again -
router.prefix("/api");
//if you use prefix again - it overwrites previous.
router.prefix(undefined); // no prefix

And also these methods are THE SAME in ExtendedRouter

ExtendedRouter

standard usage

without any extensions it is pointless

import { ExtendedRouter } from "@ublitzjs/router";
var router = new ExtendedRouter({
  "/": {
    get: {
      controller(res, req) {
        res.end("hello, " + req.getParameter(0));
      },
    },
    post: {
      controller: new DeclarativeResponse().end("hello"),
    },
    // also websockets
    ws: {
      controller: {
        open(ws) {
          ws.send("hello");
        },
      },
    },
    any: {
      controller(res, req) {
        res.end("hello");
      },
    },
    // and HeavyController or LightController, but about it below
  },
});

with @ublitzjs/openapi as example

import { ExtendedRouter, type extPaths } from "@ublitzjs/router";
import {
  RouterPlugin,
  type methodAddOns,
  type routeAddOns,
} from "@ublitzjs/openapi";
var router = new ExtendedRouter(
  {
    "/:id": {
      openapi: {
        summary: "route summary",
      },
      get: {
        // as second property
        openapi: {
          summary: "method summary",
        },
        controller(res, req) {
          res.end("hello, " + req.getParameter(0));
        },
      },
      post: {
        controller: new DeclarativeResponse().end("hello"),
      },
      ws: {
        controller: {
          open(ws) {
            ws.send("hello");
          },
        },
      },
    },
  } satisfies extPaths<methodAddOns, routeAddOns>, // this is needed
  [RouterPlugin] // plugin to use openapi
);

LightController, HeavyController, jsonSchemas - here