tiny-url.js - URL Object for tinyJS

tiny-url.js adds the function t.u to tiny, which can convert an URL-String to an Objekt similar to location, with some added value.

Download

tiny-url.js [1655b] - tiny-url-min.js.gz [508b]

Hint

The t.u-Method requires only tiny.js. Other scripts are not necessary.

Usage

The function t.u('[URL]') returns an Object with helpful instances and the Method .toString(). The instances are as follows:

Instances

hrefFull URL
protocolURL-Protocol, e.g. 'http:'
hostnameHostname (FQDN), e.g. 'tinyjs.sourceforge.net'
base'//'+hostname
portPort of the TCP connection (if not :80), e.g. 8080
pathnamepath including filename, e.g. '/index-en.html'
searchGET-Parameters-String with prefixing '?', e.g. '?test=true'
hashHash-Parameter of an page-internal link
paramsAn Object with all GET-Parameters

If called without parameters, t.u() uses location.href as URL. Within the function, the instances of location.href are available (including params), so t.u().hostname === t.u.hostname.

toString()-Method

The URL Object has a toString-Method, which is somewhat different from usual toString. It takes zero or one Arguments. Without arguments, it returns an absolute URL, if the first argument is false, it returns a relative URL. If the first argument is an URL, it returns an absolute URL using the argument as base.

Example

href
protocol
hostname
base
port
pathname
search
hash
params

Code

t('#example td').i(function(k, v) {
    if (t.u[v.id]) { v.innerHTML = JSON.stringify(t.u[v.id]); }
});