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

trek-router

v1.2.0

Published

A fast HTTP router

Downloads

656

Readme

trek-router

A fast HTTP router, inspired by Echo's Router.

Benchmarks

See benchmarks, use GitHub API Routes and Discourse API Routes.

VS

$ npm run benchmark

GitHub API, 203 routes:
trek-router x 5,095 ops/sec ±2.26% (98 runs sampled)
memoryUsage: { rss: 42135552, heapTotal: 32478208, heapUsed: 18689464 }
path-to-regexp x 408 ops/sec ±1.58% (93 runs sampled)
memoryUsage: { rss: 60882944, heapTotal: 51053056, heapUsed: 16037648 }
route-recognizer x 323 ops/sec ±1.27% (90 runs sampled)
memoryUsage: { rss: 63623168, heapTotal: 54136832, heapUsed: 28968984 }
route-trie x 1,229 ops/sec ±1.12% (95 runs sampled)
memoryUsage: { rss: 65597440, heapTotal: 55168768, heapUsed: 27494288 }
routington x 1,201 ops/sec ±0.30% (98 runs sampled)
memoryUsage: { rss: 68001792, heapTotal: 59284480, heapUsed: 28473048 }
Fastest is trek-router

Discourse API, 359 routes:
trek-router x 3,801 ops/sec ±0.09% (101 runs sampled)
memoryUsage: { rss: 70402048, heapTotal: 61348352, heapUsed: 30221032 }
path-to-regexp x 59.41 ops/sec ±0.23% (78 runs sampled)
memoryUsage: { rss: 72286208, heapTotal: 63400192, heapUsed: 28175392 }
route-recognizer x 211 ops/sec ±1.14% (92 runs sampled)
memoryUsage: { rss: 75005952, heapTotal: 64432128, heapUsed: 21000584 }
route-trie x 1,131 ops/sec ±0.85% (97 runs sampled)
memoryUsage: { rss: 74936320, heapTotal: 64432128, heapUsed: 18404472 }
routington x 1,076 ops/sec ±0.45% (100 runs sampled)
memoryUsage: { rss: 74973184, heapTotal: 64432128, heapUsed: 25122008 }
Fastest is trek-router

Usage

import http from 'http';
import finalhandler from 'finalhandler';
import Router from 'trek-router';

let router = Router()

// static route
router.add('GET', '/folders/files/bolt.gif', () => {});
// param route
router.add('GET', '/users/:id', () => {});
// match-any route
router.add('GET', '/books/*', () => {});

let result = router.find('GET', '/users/233')
// => [handler, params]
// => [()=>{}, [{name: id, value: 233}]]

let params = {}
if (result[0]) {
  result[1].forEach(param => params[param.name] = param.value)
  // => { id: 233 }
}

// Not Found
let result = router.find('GET', '/photos/233')
// => [handler, params]
// => [undefined, []]

let server = http.createServer(function(req, res) {
  let result = router.find(req.method, req.url);
  if (result) {
    req.params = result[1];
    return result[0](req, res);
  }
  finalhandler(req, res);
});

server.listen(3000)

Badges

NPM version Build Status codecov Dependency status


fundon.me  ·  GitHub @fundon  ·  Twitter @_fundon