Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brecert/mouri
A simple, easy to use, and relatively performant way to create and join uri parts together.
https://github.com/brecert/mouri
deno join-uri-parts typescript uri
Last synced: 3 days ago
JSON representation
A simple, easy to use, and relatively performant way to create and join uri parts together.
- Host: GitHub
- URL: https://github.com/brecert/mouri
- Owner: brecert
- Created: 2020-09-25T19:55:21.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-23T22:10:50.000Z (almost 3 years ago)
- Last Synced: 2024-12-17T02:32:32.828Z (22 days ago)
- Topics: deno, join-uri-parts, typescript, uri
- Language: TypeScript
- Homepage:
- Size: 42 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mouri (もURI)
A simple, easy to use, and relatively performant (see [benchmarks](#benchmarks))
way to create and join uri parts together.Please note that this is not meant to handle many edge cases, and is meant and
made for simple use cases.# Usage
- [**Documentation**](https://doc.deno.land/https/deno.land/x/mouri/uri.ts)
- [**Examples**](./examples/README.md)## Deno
```ts
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import uri from "https://deno.land/x/mouri/mod.ts";const API_URL = "https://api.example.com/";
const userPostsUrl = (id: string, limit: number, offset: number) => {
return uri`${API_URL}/users/${id}/posts?${{ limit, offset }}`;
};assertEquals(
userPostsUrl("112233445566778899", 10, 5),
"https://api.example.com/users/112233445566778899/posts?limit=10&offset=5",
);
```## Node
`> npm i mouri`
```js
import { strict as assert } from 'assert';
import uri from 'mouri';const API_URL = "https://api.example.com/";
const userPostsUrl = (id, limit, offset) => {
return uri`${API_URL}/users/${id}/posts?${{ limit, offset }}`;
};assert.strictEqual(
userPostsUrl("112233445566778899", 10, 5),
"https://api.example.com/users/112233445566778899/posts?limit=10&offset=5"
);
```# Benchmarks
To run: `deno run .\bench.ts`
## Simple URL joining
pattern:
> `{API_URL}/users/{id}/posts/limit={limit}&offset={offset}`expected result:
> `https://api.example.com/users/112233445566778899/posts/limit=10&offset=5`
|Name|Runs|Total (ms)|Average (ms)|
|:--|--:|--:|--:|
|mouri|2000|12.058|0.006|
|urlcat|2000|37.778|0.019|
|handwritten|2000|46.136|0.023|