# shipharbor

> Small isomorphic router

Latest version **1.0.0** (published 2018-03-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install shipharbor
pnpm add shipharbor
yarn add shipharbor
bun add shipharbor
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-03-25 |
| First published | 2018-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 1 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Tobias Herber |
| Maintainers | tobihrbr |
| Keywords | router, route, isomorphic |

## Links

- npm: https://www.npmjs.com/package/shipharbor
- Repository: https://github.com/herber/shipharbor
- Homepage: https://github.com/herber/shipharbor#readme
- Issues: https://github.com/herber/shipharbor/issues
- npm.io page: https://npm.io/package/shipharbor

## Dependencies (1)

- [matchit](https://npm.io/package/matchit.md) ^1.0.5

## 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.0 (latest) — 2018-03-25

## README

<h1 align="center">Shipharbor</h1>

<p align="center">🚢🌊 Shipharbor is a tiny router, that runs in browsers and in nodejs.</p>

<p align="center">
  <a href="https://travis-ci.org/herber/shipharbor">
    <img src="https://travis-ci.org/herber/shipharbor.svg?branch=master" alt="Build Status">
  </a>

  <a href="https://codecov.io/gh/herber/shipharbor">
    <img src="https://codecov.io/gh/herber/shipharbor/branch/master/graph/badge.svg" />
  </a>
</p>

## Install

```
$ npm install shipharbor
```

## Usage

```js
const Shipharbor = require('shipharbor');
const router = new Shipharbor();

router.add('/', () => {
  console.log('> Home');
});

router.add('/user/:id', (params) => {
  console.log('> User: ' + params.id);
});

router.add('/*', (params) => {
  console.log('> Not found');
});

router.match('/').handler();
// > Home

const match = router.match('/user/my-user');
m.handler(m.params);
// > User: my-user

router.match('/whatever').handler();
// > Not found
```

## API

### shipharbor()

#### add(path, handler)

##### path

Type: `string`

A string representing the path you want to match. This is similar to express's paths.

The supported pattern types are:

* static (`/users`)
* named parameters (`/users/:id`)
* nested parameters (`/users/:id/books/:title`)
* optional parameters (`/users/:id?/books/:title?`)
* any match / wildcards (`/users/*`)

##### handler

Type: `function`

The handler function for a specific path.

#### match(path)

Return: `object|boolean`;

##### path

Type: `string`

The url you want to match against the previously specified routes.

##### Example:

```js
const match = router.match('/route');
// if the route exists:
//  => { handler, params }
// else
//  => false

match.handler(); // executes the handler
```

## License

MIT © [Tobias Herber](http://tobihrbr.com)

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