|
|
@ -1,7 +1,7 @@ |
|
|
|
exports.parse = url_parse; |
|
|
|
exports.resolve = url_resolve; |
|
|
|
exports.resolveObject = url_resolveObject; |
|
|
|
exports.format = url_format; |
|
|
|
exports.parse = urlParse; |
|
|
|
exports.resolve = urlResolve; |
|
|
|
exports.resolveObject = urlResolveObject; |
|
|
|
exports.format = urlFormat; |
|
|
|
|
|
|
|
// define these here so at least they only have to be compiled once on the first module load.
|
|
|
|
var protocolPattern = /^([a-z0-9]+:)/, |
|
|
@ -18,7 +18,7 @@ var protocolPattern = /^([a-z0-9]+:)/, |
|
|
|
path = require("path"), // internal module, guaranteed to be loaded already.
|
|
|
|
querystring = require('querystring'); |
|
|
|
|
|
|
|
function url_parse (url, parseQueryString) { |
|
|
|
function urlParse (url, parseQueryString) { |
|
|
|
if (url && typeof(url) === "object" && url.href) return url; |
|
|
|
|
|
|
|
var out = { href : url }, |
|
|
@ -84,10 +84,10 @@ function url_parse (url, parseQueryString) { |
|
|
|
}; |
|
|
|
|
|
|
|
// format a parsed object into a url string
|
|
|
|
function url_format (obj) { |
|
|
|
function urlFormat (obj) { |
|
|
|
// ensure it's an object, and not a string url. If it's an obj, this is a no-op.
|
|
|
|
// this way, you can call url_format() on strings to clean up potentially wonky urls.
|
|
|
|
if (typeof(obj) === "string") obj = url_parse(obj); |
|
|
|
if (typeof(obj) === "string") obj = urlParse(obj); |
|
|
|
|
|
|
|
var protocol = obj.protocol || "", |
|
|
|
host = (obj.host !== undefined) ? obj.host |
|
|
@ -122,15 +122,15 @@ function url_format (obj) { |
|
|
|
return protocol + host + pathname + search + hash; |
|
|
|
}; |
|
|
|
|
|
|
|
function url_resolve (source, relative) { |
|
|
|
return url_format(url_resolveObject(source, relative)); |
|
|
|
function urlResolve (source, relative) { |
|
|
|
return urlFormat(urlResolveObject(source, relative)); |
|
|
|
}; |
|
|
|
|
|
|
|
function url_resolveObject (source, relative) { |
|
|
|
function urlResolveObject (source, relative) { |
|
|
|
if (!source) return relative; |
|
|
|
|
|
|
|
source = url_parse(url_format(source)); |
|
|
|
relative = url_parse(url_format(relative)); |
|
|
|
source = urlParse(urlFormat(source)); |
|
|
|
relative = urlParse(urlFormat(relative)); |
|
|
|
|
|
|
|
// hash is always overridden, no matter what.
|
|
|
|
source.hash = relative.hash; |
|
|
|