Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nblackburn/micro-match
A micro library for matching urls.
https://github.com/nblackburn/micro-match
micro url-matching
Last synced: about 1 month ago
JSON representation
A micro library for matching urls.
- Host: GitHub
- URL: https://github.com/nblackburn/micro-match
- Owner: nblackburn
- License: mit
- Created: 2016-08-21T22:57:24.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T04:51:21.000Z (over 1 year ago)
- Last Synced: 2024-04-14T05:30:12.170Z (2 months ago)
- Topics: micro, url-matching
- Language: JavaScript
- Homepage:
- Size: 453 KB
- Stars: 34
- Watchers: 1
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Lists
- awesome-micro - micro-match - A simple url matching utility for micro. (Modules / Utilities)
README
# micro match
A simple url matching utility for micro.
## Installation
To install micro match, simply run the following command in your terminal of choice.
```bash
npm install -g micro-match
```Once you have installed micro match, simply include it in your project like so...
```javascript
const { match, test } = require('micro-match');
```## Usage
### Match
The match method allows you to match a route binding to it's real world counterpart and return it's bindings.
```javascript
const {id} = match('/users/:id', '/users/1');
```
Parameters are defined as a comma followed by an alias to bind it's value to.You can also create optional parameters by attaching a `?` suffix. This will allow both `/users` and `/users/1` to be matched.
Now you will be able to access the `id` parameter with the value of `1` and handle it however ever you like.
### Test
The test method allows you check if the pattern matches the given url.
```javascript
test('/users/:id', '/users/1');
```## Changes
Details for each release are documented in the [release notes](CHANGELOG.md).
## License
This utility is licensed under [MIT](http://opensource.org/licenses/mit), see [LICENSE.md](LICENSE.md) for details.