# route-typo-redirect

> An Express middleware helps accesing to routes with typos

Latest version **1.0.4** (published 2022-06-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install route-typo-redirect
pnpm add route-typo-redirect
yarn add route-typo-redirect
bun add route-typo-redirect
```

## 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.4 |
| Published | 2022-06-12 |
| First published | 2022-05-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Murat TURAN |
| Maintainers | snowron |
| Keywords | typo, express, routes, middleware, typo, redirect, route, redirect |

## Links

- npm: https://www.npmjs.com/package/route-typo-redirect
- Repository: https://github.com/snowron/route-typo-redirect
- Homepage: https://github.com/snowron/route-typo-redirect#readme
- Issues: https://github.com/snowron/route-typo-redirect/issues
- npm.io page: https://npm.io/package/route-typo-redirect

## Dependencies (2)

- [js-levenshtein](https://npm.io/package/js-levenshtein.md) ^1.1.6
- [fuzzy-comparison](https://npm.io/package/fuzzy-comparison.md) ^2.0.0

## 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.4 (latest) — 2022-06-12
- 1.0.3 — 2022-06-08
- 1.0.2 — 2022-06-08
- 1.0.1 — 2022-06-07
- 1.0.0 — 2022-05-28

## README

# route-typo-redirect

Make your users happy with catch typos with middleware and redirect to right one. 

Works with Express

## Install 

```bash 
  npm i route-typo-redirect
```
    
## Usage
Middleware needs your routes with array of strings. It gets the request path and analyzes it with rules and redirects.

```js
const typoRedirect = require('route-typo-redirect')

app.use(typoRedirect({
    routes: ["/chat", "/about/:id", "/home"]
}))

app.use(typoRedirect({
    routes: ["/chat", "/about/:id", "/home"],
    blacklist: ["/user"],
}))

app.use(typoRedirect({
    routes: ["/chat", "/about/:id", "/home"],
    blacklist: ["/user"],
    levenThreshold: 2,
    fuzzyThreshold: 4,
}))
```

Also there is a cool snippet to get all routes from Express

```js
  function availableRoutes() {
    return app._router.stack
      .filter((r) => r.route)
      .map((r) => {
        return r.route.path !== "/" ? r.route.path : null;
      });
  }

  app.use(typoRedirect({
    routes: availableRoutes(),
    blacklist: ["/user"],
    levenThreshold: 2,
    fuzzyThreshold: 4,
}))
```

## Demo

[Example](https://github.com/snowron/route-typo-redirect/blob/master/example/app.js)

[Tests](https://github.com/snowron/route-typo-redirect/blob/master/index.test.js)


```bash
➜ curl "http://localhost:3000/abouc/"           
Found. Redirecting to /about/%                                                                                                                                                                             

➜ curl "http://localhost:3000/abouct/"
Found. Redirecting to /about/%    

➜ curl "http://localhost:3000/chay/123"
Found. Redirecting to /chat/123%     
```

## Tests

```bash
  npm run test
```

## Options

| Parameter        | Type            | Desc                                          |
| :--------------- | :-------------- | :-------------------------------------------- |
| `blacklist`      | `array<string>` | these routes not redirect                     |
| `routes`         | `array<string>` | whitelist routes                              |
| `levenThreshold` | `number`        | the levenstein algorithm's threshold value    |
| `fuzzyThreshold` | `number`        | fuzzy comparasion algorithm's threshold value |

  
## Lisans

[MIT](https://choosealicense.com/licenses/mit/)

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