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

@enonic-types/lib-router

v4.0.1

Published

Type definitions for the Enonic XP Router library

Readme

Types for Router library

Type definitions for the Enonic XP Router library.

Install

npm i --save-dev @enonic-types/lib-router

Setup

Add lib-router to compilerOptions.paths in the tsconfig.json file used for your application's server-side TypeScript code:

{
  "compilerOptions": {
    "paths": {
      "/lib/router": ["./node_modules/@enonic-types/lib-router"]
    }
  }
}

Use

import type {Request, Response} from '@enonic-types/core';
import newRouter from '/lib/router';

const router = newRouter();

router.filter((req, next) => {
    return next(req);
});

router.get('/persons', (req) => ({
    body: {persons: []},
    contentType: 'application/json',
}));

router.get('/persons/{id:[0-9]+}', (req) => {
    const id = req.pathParams.id;
    return {
        body: {id},
        contentType: 'application/json',
    };
});

router.route('GET', ['/static', '/static/{path:.*}'], (req) => ({
    body: req.pathParams.path,
}));

export function all(req: Request): Response {
    return router.dispatch(req);
}

All imports from /lib/router should now be typed.

API

newRouter(): Router

Creates a new router instance. This is the default export of /lib/router.

Router

| Method | Description | |------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| | route(method: string, pattern: Pattern, handler: RouteHandler): void | Adds a route matching method and pattern. Use '*' as method to match any method. | | get(pattern: Pattern, handler: RouteHandler): void | Adds a route matching the GET method. | | post(pattern: Pattern, handler: RouteHandler): void | Adds a route matching the POST method. | | put(pattern: Pattern, handler: RouteHandler): void | Adds a route matching the PUT method. | | delete(pattern: Pattern, handler: RouteHandler): void | Adds a route matching the DELETE method. | | head(pattern: Pattern, handler: RouteHandler): void | Adds a route matching the HEAD method. | | patch(pattern: Pattern, handler: RouteHandler): void | Adds a route matching the PATCH method. | | all(pattern: Pattern, handler: RouteHandler): void | Adds a route matching all methods. | | filter(filter: Filter): void | Adds a filter. Filters run in insertion order before route matching. | | dispatch(req: Request): Response | Dispatches the request through the filter chain and the matched route. Returns 404 if no match. |

Pattern

string \| string[] — a path pattern, or several patterns sharing the same handler. Placeholders use the {name} notation and can be restricted with a regular expression, e.g. {id:[0-9]+} or {path:.+}.

RouterRequest

| Property | Type | Description | |--------------|-----------------------------------------|-----------------------------------------------------------------------------| | pathParams | Record<string, string \| undefined> | Path parameters populated from the matched route's placeholders. |

All other properties are inherited from Request.

RouteHandler

(req: RouterRequest) => Response — handler invoked when a route matches.

Filter

(req: Request, next: (req: Request) => Response) => Response — call next(req) to continue the chain, or return a response to short-circuit.

Request and Response are imported from @enonic-types/core.

Documentation

Router library