UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

70 lines (69 loc) 2.52 kB
function parsePathAndParamsFromExpoGoLink(url) { const results = parsePathFromExpoGoLink(url).match(/([^?]*)(\?.*)?/); return { pathname: results?.[1] ?? "", queryString: results?.[2] ?? "" }; } function parsePathFromExpoGoLink(url) { return url.match(/exps?:\/\/.*?\/--\/(.*)/)?.[1] ?? ""; } function extractExactPathFromURL(url) { if ( // If a universal link / app link / web URL is used, we should use the path // from the URL, while stripping the origin. url.match(/^https?:\/\//) ) { const { origin, href, hostname } = new URL(url); return hostname === "exp.host" || hostname === "u.expo.dev" ? "" : href.replace(origin, ""); } if (typeof globalThis.expo < "u" && globalThis.expo?.modules?.ExpoGo && // while not exhaustive, `exp` and `exps` are the only two schemes which // are passed through to other apps in Expo Go. url.match(/^exp(s)?:\/\//)) { const pathname = parsePathFromExpoGoLink(url); if (pathname) return fromDeepLink("a://" + pathname); const queryParams = url.match(/exps?:\/\/.*\?(.*)/)?.[1]; return queryParams ? fromDeepLink("a://?" + queryParams) : ""; } return fromDeepLink(url); } function isExpoDevelopmentClient(url) { return url.hostname === "expo-development-client"; } function fromDeepLink(url) { let res; try { res = new URL(url); } catch { return url.startsWith("/") ? url : url.replace(/^[^:]+:\/\//, ""); } if (isExpoDevelopmentClient(res)) { if (!res.searchParams.get("url")) return ""; const incomingUrl = res.searchParams.get("url"); return extractExactPathFromURL(decodeURI(incomingUrl)); } let results = ""; res.host && (results += res.host), res.pathname && (results += res.pathname); const qs = res.search ? ( // @ts-ignore: `entries` is not on `URLSearchParams` in some typechecks. [...res.searchParams.entries()].map(([k, v]) => `${k}=${decodeURIComponent(v)}`).join("&") ) : ""; return qs && (results += "?" + qs), results; } function extractExpoPathFromURL(_prefixes, url = "") { return extractExactPathFromURL(url).replace(/^\//, ""); } function adjustPathname(url) { return url.hostname === "exp.host" || url.hostname === "u.expo.dev" ? url.pathname.split("/").slice(2).join("/") : url.pathname; } const extractPathFromURL = extractExpoPathFromURL; export { adjustPathname, extractExpoPathFromURL, extractPathFromURL, parsePathAndParamsFromExpoGoLink, parsePathFromExpoGoLink }; //# sourceMappingURL=extractPathFromURL.js.map