aboutsummaryrefslogtreecommitdiff
path: root/node_modules/typed-rest-client/Util.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/typed-rest-client/Util.js')
-rw-r--r--node_modules/typed-rest-client/Util.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/node_modules/typed-rest-client/Util.js b/node_modules/typed-rest-client/Util.js
new file mode 100644
index 0000000..32981d1
--- /dev/null
+++ b/node_modules/typed-rest-client/Util.js
@@ -0,0 +1,35 @@
+"use strict";
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+Object.defineProperty(exports, "__esModule", { value: true });
+const url = require("url");
+const path = require("path");
+/**
+ * creates an url from a request url and optional base url (http://server:8080)
+ * @param {string} resource - a fully qualified url or relative path
+ * @param {string} baseUrl - an optional baseUrl (http://server:8080)
+ * @return {string} - resultant url
+ */
+function getUrl(resource, baseUrl) {
+ const pathApi = path.posix || path;
+ if (!baseUrl) {
+ return resource;
+ }
+ else if (!resource) {
+ return baseUrl;
+ }
+ else {
+ const base = url.parse(baseUrl);
+ const resultantUrl = url.parse(resource);
+ // resource (specific per request) elements take priority
+ resultantUrl.protocol = resultantUrl.protocol || base.protocol;
+ resultantUrl.auth = resultantUrl.auth || base.auth;
+ resultantUrl.host = resultantUrl.host || base.host;
+ resultantUrl.pathname = pathApi.resolve(base.pathname, resultantUrl.pathname);
+ if (!resultantUrl.pathname.endsWith('/') && resource.endsWith('/')) {
+ resultantUrl.pathname += '/';
+ }
+ return url.format(resultantUrl);
+ }
+}
+exports.getUrl = getUrl;