Skip to content

Repository files navigation

Mouri (もURI)

A simple, easy to use, and relatively performant (see 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

Deno

import{assertEquals}from"https://deno.land/std@0.122.0/testing/asserts.ts";importurifrom"https://deno.land/x/mouri/mod.ts";constAPI_URL="https://api.example.com/";constuserPostsUrl=(id: string,limit: number,offset: number)=>{returnuri`${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

import{strictasassert}from'assert';importurifrom'mouri';constAPI_URL="https://api.example.com/";constuserPostsUrl=(id,limit,offset)=>{returnuri`${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

NameRunsTotal (ms)Average (ms)
mouri200012.0580.006
urlcat200037.7780.019
handwritten200046.1360.023

About

A simple, easy to use, and relatively performant way to create and join uri parts together.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages