UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

37 lines (35 loc) 1.39 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); class UrlUtilities { static ensureProtocol(sourceUrl, protocolFrom, protocolValue) { let sourceUrlHash = ""; const hashIndex = sourceUrl.indexOf("#"); if (hashIndex >= 0) { sourceUrlHash = sourceUrl.substring(hashIndex); sourceUrl = sourceUrl.substring(0, hashIndex); } if (sourceUrl.indexOf("?") <= 0) { return sourceUrl + "?" + protocolFrom + "=" + protocolValue + sourceUrlHash; } let clauseStart = sourceUrl.indexOf(protocolFrom + "="); if (clauseStart > 0) { let clauseEnd = sourceUrl.indexOf("&", clauseStart + protocolFrom.length); if (clauseEnd < clauseStart) { clauseEnd = sourceUrl.length; } if (sourceUrl[clauseStart - 1] === "&") { clauseStart--; } sourceUrl = sourceUrl.substring(0, clauseStart) + sourceUrl.substring(clauseEnd); } if (!sourceUrl.endsWith("?")) { sourceUrl += "&"; } sourceUrl += protocolFrom + "=" + protocolValue + sourceUrlHash; return sourceUrl; } } exports.default = UrlUtilities; //# sourceMappingURL=../maps/core/UrlUtilities.js.map