Skip to content

A simple url builder based on the URL object for Deno with typescript

Notifications You must be signed in to change notification settings

roonie007/url-parse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

url-parse

A simple url parser/builder based on the ES6 URL object for Deno with typescript.

Usage

Using a String

import { urlParse } from "https://deno.land/x/url_parse/mod.ts";

const url = urlParse("http://www.google.com"); // Returns an URL object

console.log(url.toString());
// http://www.google.com/

console.log(url);
/**
 * {
 *    href: "http://www.google.com/",
 *    origin: "http://www.google.com",
 *    protocol: "http:",
 *    username: "",
 *    password: "",
 *    host: "www.google.com",
 *    hostname: "www.google.com",
 *    port: "",
 *    pathname: "/",
 *    hash: "",
 *    search: ""
 * }
 */

Using an object

Supports any protocol like mongodb, ssh, etc...

import { urlParse } from "https://deno.land/x/url_parse/mod.ts";

const url = urlParse({
  protocol: "https",
  hostname: "google.com",
  pathname: "search/hey", // "search/hey" or ["search", "hey"]
  username: "username",
  password: "password",
  port: 3000, // 3000 or "3000"
  query: [{ key: "hello", value: "world" }],
}); // Returns an URL object

console.log(url.toString());
// https://username:[email protected]:3000/search/hey?hello=world

License

MIT

About

A simple url builder based on the URL object for Deno with typescript

Resources

Stars

Watchers

Forks

Packages

No packages published