import { unfurlGoogleMapsUrl } from "google-maps-link-parser";
const redirectSteps = [
{
status: 302,
location: "https://www.google.com/maps/@24.7136,46.6753,15z",
},
{ status: 200 },
];
let redirectIndex = 0;
const mockFetch = async () => {
const step = redirectSteps[redirectIndex++];
if (!step) {
throw new Error("Unexpected fetch call");
}
return new Response("", {
status: step.status,
headers: step.location ? { Location: step.location } : {},
});
};
const result = await unfurlGoogleMapsUrl("https://maps.app.goo.gl/abc123?g_st=ic", {
fetch: mockFetch,
raw: { enabled: true },
});
console.log(result.resolution.status); // => "resolved"
console.log(result.resolution.resolvedUrl); // => "https://www.google.com/maps/@24.7136,46.6753,15z"