UNPKG

@azure/web-pubsub

Version:
34 lines 1.26 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.parseConnectionString = parseConnectionString; const core_auth_1 = require("@azure/core-auth"); function parseConnectionString(conn) { const parsed = {}; conn.split(";").forEach((i) => { const assignmentPos = i.indexOf("="); if (assignmentPos === -1) return; const key = i.substring(0, assignmentPos).toLowerCase(); const value = i.substring(assignmentPos + 1); parsed[key] = value; }); let endpointPart = parsed["endpoint"]; if (!endpointPart) throw new TypeError("connection string missing endpoint"); if (!endpointPart.startsWith("http")) { endpointPart = `https://${endpointPart}`; } const key = parsed["accesskey"]; if (!key) throw new TypeError("connection string missing access key"); const credential = new core_auth_1.AzureKeyCredential(key); const port = parsed["port"]; const url = new URL(endpointPart); url.port = port; const endpoint = url.toString(); url.port = ""; return { credential, endpoint }; } //# sourceMappingURL=parseConnectionString.js.map