The url module provides utilities for URL resolution and parsing.

Static methods

staticdomainToASCII(domain:String):String

Returns the Punycode ASCII serialization of the domain. If domain is an invalid domain, the empty string is returned.

It performs the inverse operation to url.domainToUnicode().

staticdomainToUnicode(domain:String):String

Returns the Unicode serialization of the domain. If domain is an invalid domain, the empty string is returned.

It performs the inverse operation to url.dmainToASCII().

staticfileURLToPath(url:URL):String

staticfileURLToPath(url:String):String

This function ensures the correct decodings of percent-encoded characters as well as ensuring a cross-platform valid absolute path string.

staticformat(url:URL, ?options:Null<UrlFormatOptions>):String

staticformat(urlObject:UrlObject):String

staticformat(urlObject:String):String

Returns a customizable serialization of a URL String representation of a WHATWG URL object.

The URL object has both a toString() method and href property that return string serializations of the URL. These are not, however, customizable in any way. The url.format(URL[, options]) method allows for basic customization of the output.

format(urlObject:UrlObject) and format(urlObject:String) are deprecated.

staticparse(urlString:String, ?parseQueryString:Bool, ?slashesDenoteHost:Bool):UrlObject

Deprecated:

Takes a URL string, parses it, and returns a URL object.

If parseQueryString is true, the query property will always be set to an object returned by the Querystring.parse method. If false, the query property on the returned URL object will be an unparsed, undecoded string. Defaults to false.

If slashesDenoteHost is true, the first token after the literal string // and preceding the next / will be interpreted as the host. For instance, given //foo/bar, the result would be {host: 'foo', pathname: '/bar'} rather than {pathname: '//foo/bar'}. Defaults to false.

staticpathToFileURL(path:String):URL

This function ensures that path is resolved absolutely, and that the URL control characters are correctly encoded when converting into a File URL.

staticresolve(from:String, to:String):String

Deprecated:

Resolves a target URL relative to a base URL in a manner similar to that of a Web browser resolving an anchor tag HREF.

Examples:

resolve('/one/two/three', 'four')         // '/one/two/four'
resolve('http://example.com/', '/one')    // 'http://example.com/one'
resolve('http://example.com/one', '/two') // 'http://example.com/two'