An open API service indexing awesome lists of open source software.

https://github.com/marvinhagemeister/fast-path-to-regexp

Tiny & fast alternative to path-to-regexp
https://github.com/marvinhagemeister/fast-path-to-regexp

path path-to-regexp regex url

Last synced: about 2 months ago
JSON representation

Tiny & fast alternative to path-to-regexp

Awesome Lists containing this project

README

        

# Fast Path To RegExp

Ultra small and super fast library for converting paths
to `RegExp`. Only implements a subset of [path-to-regexp](https://github.com/pillarjs/path-to-regexp).

```txt
:myparam -> named parameters, f.ex. /bar/:foo
* -> wildcard catchall, f.ex. /bar/*/foo
```

## Usage

Installation:

```bash
# via npm
npm install --save @marvinh/path-to-regexp

# via yarn
yarn add @marvinh/path-to-regexp
```

```js
import { PathRegExp } from "@marvinh/path-to-regexp";

const Path = new PathRegExp("foo/:bar/*/bob");

// Returns params on match
Path.match("foo/asd/a/");
// -> {
// matched: "", // The remaining part if any
// params: { bar: "asd" }
// }
```

## License

`MIT`, see [License file](./LICENSE.md).