UNPKG

@azure-rest/maps-route

Version:
47 lines 1.82 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.toColonDelimitedLatLonString = toColonDelimitedLatLonString; exports.createRouteDirectionsBatchRequest = createRouteDirectionsBatchRequest; function toLatLonString(coordinates) { return `${coordinates[0]},${coordinates[1]}`; } /** * Transform an array of [Latitude, Longtitute] to a string in the following format: * "Latitude_1,Longtitute_1:Latitude_2,Longtitute_2:..." * * @param coordinates - An array of Latitude/Longtitute pair to transform. * @returns The transformed string. */ function toColonDelimitedLatLonString(coordinates) { return coordinates.map((c) => toLatLonString(c)).join(":"); } /** * Create a batch request body of a bunch of route direction requests. * * @param queryParamProperties - An object of the query parameters for a route direction request * @returns The composed batch request. */ function createRouteDirectionsBatchRequest(queryParamProperties) { return { batchItems: queryParamProperties.map((queryParam) => ({ query: "?" + Object.entries(queryParam) .map(([k, v]) => { // Skip if no value if (typeof v === "undefined" || v === null) { return ""; } // Check name mappings: Array values if ((k === "departAt" || k === "arriveAt") && v instanceof Date) { return `${k}=${v.toISOString()}`; } return `${k}=${v}`; }) .filter((s) => s !== "") .join("&"), })), }; } //# sourceMappingURL=helpers.js.map