mod-url
npm i mod-url
const mod = ;console;// https://github.com/console;// https://www.google.in/search?q=query#foo
API
.parse(url) -> parse url.
example of accepted url types : github, github.com, www.github.com, http://www.github.com, https://github.com, github.com/path
const gh = mod;
.done() -> get modified string.
console;// https://github.com/
.protocol(string) -> modify protocol scheme.
let url = mod;url = urlprotocol'http';// or// url = mod.parse('github').protocol('http').done();console;// http://github.com/
.subdomain(string) -> modify subdomain.
const url = mod;console;// https://www.github.com/
const url = mod;console;// https://x.y.github.com/
To remove subdomain. Do not pass null argument. Instead pass empty string
const url = mod;console;// https://github.com/
.domain(string) -> modify domain.
const url = mod;console;// https://google.com/search?q=query
const url = mod;console;// https://www.google.in/
const url = mod;console;// https://google.in/
You cannot remove domain. ie .domain('') wont work
.domainext(string) -> modify domain extension
const url = mod;console;// https://google.uk/search?q=query
.port(string | number) -> modify port
const url = modport80;console;// https://google:80.com/
.path(string) -> modify full path
const url = mod;console;// https://google.com/onlypath
const url = mod;console;// https://github.com/
.onlypath(string) -> modify path (excluding query & fragment)
const url = mod;console;// https://google.com/version2?q=query
.query(string) -> modify query
const url = mod;console;// https://google.com/seach?foo=bar&baz=foo
.fragment(string) -> modify fragment
const url = mod;console;// https://google.com/hi#hello
chain modify functions as you want
const url = modprotocol'http'port'90';console;// http://www.something-else:90.foo/random?query=unknown
Do not forget to add .done() at last
DO NOT - (mod-url is mutable)
const url1 = mod;const url2 = mod;console;// https://github.comconsole;// https://github.com
// solution for above behaviorconst url1 = mod;const url2 = mod;console;console;