Class for URI representation and parsing, modelled after the HTML5 URL class/function.

This differs from Node.js' url module in that Node.js' url has url.parse() etc. methods returning individual hashes on each call, whereas instances of this class-like module have member properties for protocol, host, etc.

Constructor

new URN(urlStr, baseUrlStr)

Parameters

Name Type Description
urlStr string

string containing URL to construct/parse

baseUrlStr string

ignored; must be undefined or empty

See:
http://url.spec.whatwg.org https://developer.mozilla.org/en-US/docs/Web/API/URL http://nodejs.org/docs/latest/api/url.html http://www.ietf.org/rfc/rfc3986.txt http://tools.ietf.org/html/draft-abarth-url-01

Name Description
hash Contains the hash portion of this URI, if any.
host Contains the hostname portion of this URI, if any.
hostname Contains the domain portion of this URI, if any.
href Contains the canonical serialization of the input urlStr, resolved wrt to baseUrlStr if supplied.
is_invalid Is non-empty/contains an error msg on malformed URI.
origin Contains the serialization of the origin (as per RFC 6454) from the input URI, if any.
password Contains the password component of this URI, if any.
pathname Contains the pathname of this URI, if any.
port Contains the port of this URI, if any.
protocol Contains the protocol (lowercase) of this URI, including the terminating colon.
search Contains the search portion of this URI, if any.
username Contains the username component of this URI, if any.

Name Description
reset Resets internal URI components.
set_href Sets href (the URL string), triggering re-parsing of the URI and re-populating component fields.

Member Details

hash :string

Contains the hash portion of this URI, if any.

This is the fragment with "#" prepended to it.

host :string

Contains the hostname portion of this URI, if any.

hostname :string

Contains the domain portion of this URI, if any.

href :string

Contains the canonical serialization of the input urlStr, resolved wrt to baseUrlStr if supplied.

is_invalid :string

Is non-empty/contains an error msg on malformed URI.

origin :string

Contains the serialization of the origin (as per RFC 6454) from the input URI, if any.

password :string

Contains the password component of this URI, if any.

pathname :string

Contains the pathname of this URI, if any.

port :string

Contains the port of this URI, if any.

protocol :string

Contains the protocol (lowercase) of this URI, including the terminating colon.

Restrictions of which protocols are considered valid apply.

reset()

Resets internal URI components.

Contains the search portion of this URI, if any.

This is the query with "?" prepended to it.

set_href(urlStr)

Sets href (the URL string), triggering re-parsing of the URI and re-populating component fields.

Parameters

Name Type Description
urlStr string
username :string

Contains the username component of this URI, if any.