# @weedzcokie/router

> [![Build Status](https://travis-ci.org/weedz/router.svg?branch=master)](https://travis-ci.org/weedz/router) [![Coverage Status](https://coveralls.io/repos/github/weedz/router/badge.svg?branch=master)](https://coveralls.io/github/weedz/router?branch=master

Latest version **1.0.3** (published 2020-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @weedzcokie/router
pnpm add @weedzcokie/router
yarn add @weedzcokie/router
bun add @weedzcokie/router
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-09-21 |
| First published | 2020-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Linus Björklund |
| Maintainers | weedzcokie |
| Keywords | router |

## Links

- npm: https://www.npmjs.com/package/@weedzcokie/router
- Repository: https://github.com/weedz/router
- Homepage: https://github.com/weedz/router#readme
- Issues: https://github.com/weedz/router/issues
- npm.io page: https://npm.io/package/@weedzcokie/router

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-09-21
- 1.0.2 — 2020-07-01
- 1.0.1 — 2020-05-09
- 1.0.0 — 2020-04-30

## README

# Router

[![npm](https://img.shields.io/npm/v/@weedzcokie/router?style=flat-square)](https://www.npmjs.com/package/@weedzcokie/router)
[![Build Status](https://travis-ci.org/weedz/router.svg?branch=master)](https://travis-ci.org/weedz/router)
[![Coverage Status](https://coveralls.io/repos/github/weedz/router/badge.svg?branch=master)](https://coveralls.io/github/weedz/router?branch=master)

Examples:

```javascript
import { Router, RouteTree } from "router";
const router = new Router();

router.set("GET", "/test", ...); // 1
router.set("GET", "/test/:msg", ...); // 2
router.set("GET", "/test/:param1/:param2", ...); // 3
router.set("GET", "/test/:param1/1/:param2", ...); // 4
router.set("GET", "/splat/*/test", ...); // 5
router.set("GET", "/splat1/*", ...); // 6
router.set("GET", "/wildcardparam/*/:param", ...); // 7
router.set("GET", "/wildcardparam/*/test/:param", ...); // 8
router.anyOf(["GET", "POST"], "/or/ping|pong", ...); // 9
router.set("GET", "/or/ping|pong/:param", ...); // 10

router.find("/test", "GET");    // matches 1
router.find("/test/Hello world", "GET");    // 2, params.msg = "Hello world"
router.find("/test/Hello/world!", "GET");    // 3, params.param1 = "Hello", params.param2 = "world!"
router.find("/test/Hello/1/world!", "GET");    // 4, params.param1 = "Hello", params.param2 = "world!"
router.find("/splat/1/2/3", "GET");    // does not match
router.find("/splat/1/2/test", "GET");    // matches 5
router.find("/splat1/1/2/3", "GET");    // matches 6
router.find("/wildcardparam/1/2/YO!", "GET");    // matches 7, params.param = "Yo"
router.find("/wildcardparam/1/2/test/YO!", "GET");    // matches 8, params.param = "Yo"
router.find("/or/pong", "GET");    // matches 9
router.find("/or/ping", "GET");    // matches 9
router.find("/or/ping", "POST");    // matches 9
router.find("/or/pong/Hello", "GET");    // matches 10, params.param = "Hello"

// "use"
function api(router: Router, base: RouteTree) {
    router.setAt(base, "GET", "/test", function() {
        return true;
    });
    router.setAt(base, "GET", "/msg/:msg", function(param) {
        return param.msg;
    });
}
router.use("/api", api);
router.find("/api/test", "GET");
router.find("/api/msg/hello", "GET");
```

---
_Source: https://npm.io/package/@weedzcokie/router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
