index.js
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
var hrefInfo = require("./hrefInfo");
var parseHost = require("./host");
var parsePath = require("./path");
var parsePort = require("./port");
var parseQuery = require("./query");
var parseUrlString = require("./urlstring");
var pathUtils = require("../util/path");
function parseFromUrl(url, options, fallback)
{
if (url)
{
var urlObj = parseUrl(url, options);
// Because the following occurs in the relate stage for "to" URLs,
// such had to be mostly duplicated here
var pathArray = pathUtils.resolveDotSegments(urlObj.path.absolute.array);
urlObj.path.absolute.array = pathArray;
urlObj.path.absolute.string = "/" + pathUtils.join(pathArray);
return urlObj;
}
else
{
return fallback;
}
}
function parseUrl(url, options)
{
var urlObj = parseUrlString(url, options);
if (urlObj.valid===false) return urlObj;
parseHost(urlObj, options);
parsePort(urlObj, options);
parsePath(urlObj, options);
parseQuery(urlObj, options);
hrefInfo(urlObj);
return urlObj;
}
module.exports =
{
from: parseFromUrl,
to: parseUrl
};