Skip to content

global url


methods


url.hashed


function url.hashed(str: string) ->  Url {
    scheme = string,
    authority = string,
    filename = string,
    path = string,
    port = string,
    query = string,
    queries = table,
    fragment = string,
    original = string,
    noscheme = boolean,
}

A string is split into a hash table with these keys using the following function: The hash variant is more tolerant than the split. In the hash there is also a key original that holds the original URL and and the boolean noscheme indicates if there is a scheme at all.

Example:

url.hashed("foo://example.com:2010/alpha/beta?gamma=delta#epsilon")
t = {
    ["authority"] = "example.com:2010",
    ["filename"] = "example.com:2010/alpha/beta",
    ["fragment"] = "epsilon",
    ["host"] = "example.com",
    ["noscheme"] = false,
    ["original"] = "foo://example.com:2010/alpha/beta?gamma=delta#epsilon",
    ["path"] = "alpha/beta",
    ["port"] = 2010,
    ["queries"] = {["gamma"] = "delta"},
    ["query"] = "gamma=delta",
    ["scheme"] = "foo"
}

url.hashed("alpha/beta")
t = {
    ["authority"] = "",
    ["filename"] = "alpha/beta",
    ["fragment"] = "",
    ["noscheme"] = true,
    ["original"] = "alpha/beta",
    ["path"] = "alpha/beta",
    ["query"] = "",
    ["scheme"] = "file"
}

url.split


function url.split(str: string) ->  string[]

Example:

url.split("foo://example.com:2010/alpha/beta?gamma=delta#epsilon")
t={ "foo", "example.com:2010", "alpha/beta", "gamma=delta", "epsilon" }

url.split("alpha/beta")
t = {"", "", "", "", ""}

url.construct


function url.construct(hash: Url {
    scheme = string,
    authority = string,
    filename = string,
    path = string,
    port = string,
    query = string,
    queries = table,
    fragment = string,
    original = string,
    noscheme = boolean,
}) ->  string

url.hasscheme


function url.hasscheme(str: string) ->  (string|false)

Example:

url.hasscheme("http://www.pragma-ade.com/cow.png") -- 'http'
url.hasscheme("www.pragma-ade.com/cow.png") -- false

url.addscheme


function url.addscheme(
  str: string,
  scheme: string
) ->  string

Example:

url.addscheme("www.pragma-ade.com/cow.png","http://")
-- http://:///www.pragma-ade.com/cow.png

url.addscheme("www.pragma-ade.com/cow.png")
-- file:///www.pragma-ade.com/cow.png

url.filename


function url.filename(filename: string) ->  string

Example:

url.filename("http://www.pragma-ade.com/cow.png")
--http://www.pragma-ade.com/cow.png

url.query


function url.query(str: string) ->  table

Example:

url.query("a=b&c=d")
t = {
  ["a"]="b",
  ["c"]="d",
}

😱 Types incomplete or incorrect? 🙏 Please contribute!

@see url.toquery

url.toquery


function url.toquery(data: table) ->  string

Example:

url.toquery({ a = "b", c = "d" }) --"a=b&c=d"

😱 Types incomplete or incorrect? 🙏 Please contribute!

@see url.query

url.barepath


function url.barepath(path: string)

url.decode


function url.decode(str: string)

url.encode


function url.encode(str: string)

url.escape


function url.escape(str: string)

url.unescape


function url.unescape(str: string)

url.unescapeget


function url.unescapeget(str: string)