UNPKG

one

Version:

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

119 lines 3.76 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var extractPathFromURL_exports = {}; __export(extractPathFromURL_exports, { adjustPathname: () => adjustPathname, extractExpoPathFromURL: () => extractExpoPathFromURL, extractPathFromURL: () => extractPathFromURL, parsePathAndParamsFromExpoGoLink: () => parsePathAndParamsFromExpoGoLink, parsePathFromExpoGoLink: () => parsePathFromExpoGoLink }); module.exports = __toCommonJS(extractPathFromURL_exports); function parsePathAndParamsFromExpoGoLink(url) { const href = parsePathFromExpoGoLink(url); const results = href.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); if (hostname === "exp.host" || hostname === "u.expo.dev") { return ""; } return href.replace(origin, ""); } const isExpoGo = typeof globalThis.expo !== "undefined" && globalThis.expo?.modules?.ExpoGo; if (isExpoGo && // 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]; if (queryParams) { return fromDeepLink("a://?" + queryParams); } return ""; } return fromDeepLink(url); } function isExpoDevelopmentClient(url) { return url.hostname === "expo-development-client"; } function fromDeepLink(url) { let res; try { res = new URL(url); } catch { if (url.startsWith("/")) { return url; } return url.replace(/^[^:]+:\/\//, ""); } if (isExpoDevelopmentClient(res)) { if (!res.searchParams.get("url")) { return ""; } const incomingUrl = res.searchParams.get("url"); return extractExactPathFromURL(decodeURI(incomingUrl)); } let results = ""; if (res.host) { results += res.host; } if (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("&"); if (qs) { results += "?" + qs; } return results; } function extractExpoPathFromURL(_prefixes, url = "") { return extractExactPathFromURL(url).replace(/^\//, ""); } function adjustPathname(url) { if (url.hostname === "exp.host" || url.hostname === "u.expo.dev") { return url.pathname.split("/").slice(2).join("/"); } return url.pathname; } const extractPathFromURL = extractExpoPathFromURL;