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