@geoapify/route-planner-sdk
Version:
TypeScript SDK for the Geoapify Route Planner API. Supports route optimization, delivery planning, and timeline visualization in browser and Node.js
29 lines (28 loc) • 1.48 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
export function universalFetch(url, options) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof fetch !== "undefined") {
// Browser & Node.js 18+ (native fetch support)
return fetch(url, options);
}
else {
// Node.js <18 (dynamically load node-fetch if available)
try {
const fetchModule = (Function("return import('node-fetch')")());
const nodeFetch = (yield fetchModule).default;
return nodeFetch(url, options);
}
catch (error) {
throw new Error("Fetch is not available in this environment. If you are using Node.js <18, install 'node-fetch' manually: npm install node-fetch");
}
}
});
}