one
Version:
One is a new React Framework that makes Vite serve both native and web.
91 lines • 3.49 kB
JavaScript
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: !0
});
},
__copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__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: !0
}), 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 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 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.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;