@typoerr/router
TypeScript icon, indicating that this package has built-in type declarations

0.0.32 • Public • Published

@typoerr/router

npm npm bundle size

Router for Node.js and Browser.

Install

npm i @typoerr/router

https://www.npmjs.com/package/@typoerr/router

Path expression

See lukeed/regexparam.

Example

import { route, compose, ResolveHint } from '@typoerr/router'

const router = compose([
  route('GET', '/', (ctx) => ctx.pathname),
  route('GET', '/err', (ctx) => Promise.reject(ctx.pathname)),
])

async function main(context: ResolveHint) {
  const notfound = () => Promise.reject(new Error('404 NotFound'))
  try {
    const reulst = await router(context, notfound)
    console.assert(result === context.pathname)
  } catch(err) {
    console.error(err)
  }
}

And See test/example/*.test.ts.

API

See src/route.ts and test/route.test.ts.

Inspired

Readme

Keywords

none

Package Sidebar

Install

npm i @typoerr/router

Weekly Downloads

2

Version

0.0.32

License

MIT

Unpacked Size

17.7 kB

Total Files

20

Last publish

Collaborators

  • typoerr