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