Skip to content

A simple, small (1kb), and no-dependencies url concatenator to use in requests and API calls.

Notifications You must be signed in to change notification settings

alessiopremoli/urlify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Urlify

A simple, small (1kb), and no-dependencies url concatenator to use in requests and API calls. After going crazy in counting backslash, setting envs variables, and matching paths I decided to build my (easy) url concatenator, urlify 🚀.

Installation

In your project run:

npm i @alessiopremoli/urlify

import it in your file:

import { urlify } from "@alessiopremoli/urlify";
const { urlify } = require("@alessiopremoli/urlify");

Usage

urlify handles path concatenation and query params mapping:

let id = 1;
let url = urlify(
  "api.myapi.test", // base url
  ["api/", "/v1/", "/pippo", id], // an array of additional uris
  { param1: "param1" } // an object of query params
);

console.log(url); // prints api.myapi.test/api/v1/pippo/1?param1=param1