one
Version:
One is a new React Framework that makes Vite serve both native and web.
132 lines (130 loc) • 4.63 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: 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) {
var _ref, _ref1;
var href = parsePathFromExpoGoLink(url);
var results = href.match(/([^?]*)(\?.*)?/);
return {
pathname: (_ref = results === null || results === void 0 ? void 0 : results[1]) !== null && _ref !== void 0 ? _ref : "",
queryString: (_ref1 = results === null || results === void 0 ? void 0 : results[2]) !== null && _ref1 !== void 0 ? _ref1 : ""
};
}
function parsePathFromExpoGoLink(url) {
var _ref;
var _url_match;
return (_ref = (_url_match = url.match(/exps?:\/\/.*?\/--\/(.*)/)) === null || _url_match === void 0 ? void 0 : _url_match[1]) !== null && _ref !== void 0 ? _ref : "";
}
function extractExactPathFromURL(url) {
var _globalThis_expo_modules, _globalThis_expo;
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?:\/\//)) {
var {
origin,
href,
hostname
} = new URL(url);
if (hostname === "exp.host" || hostname === "u.expo.dev") {
return "";
}
return href.replace(origin, "");
}
var isExpoGo = typeof globalThis.expo !== "undefined" && ((_globalThis_expo = globalThis.expo) === null || _globalThis_expo === void 0 ? void 0 : (_globalThis_expo_modules = _globalThis_expo.modules) === null || _globalThis_expo_modules === void 0 ? void 0 : _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)?:\/\//)) {
var _url_match;
var pathname = parsePathFromExpoGoLink(url);
if (pathname) {
return fromDeepLink("a://" + pathname);
}
var queryParams = (_url_match = url.match(/exps?:\/\/.*\?(.*)/)) === null || _url_match === void 0 ? void 0 : _url_match[1];
if (queryParams) {
return fromDeepLink("a://?" + queryParams);
}
return "";
}
return fromDeepLink(url);
}
function isExpoDevelopmentClient(url) {
return url.hostname === "expo-development-client";
}
function fromDeepLink(url) {
var res;
try {
res = new URL(url);
} catch (unused) {
if (url.startsWith("/")) {
return url;
}
return url.replace(/^[^:]+:\/\//, "");
}
if (isExpoDevelopmentClient(res)) {
if (!res.searchParams.get("url")) {
return "";
}
var incomingUrl = res.searchParams.get("url");
return extractExactPathFromURL(decodeURI(incomingUrl));
}
var results = "";
if (res.host) {
results += res.host;
}
if (res.pathname) {
results += res.pathname;
}
var qs = !res.search ? "" :
// @ts-ignore: `entries` is not on `URLSearchParams` in some typechecks.
[...res.searchParams.entries()].map(function (param) {
var [k, v] = param;
return `${k}=${decodeURIComponent(v)}`;
}).join("&");
if (qs) {
results += "?" + qs;
}
return results;
}
function extractExpoPathFromURL(_prefixes) {
var url = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
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;
}
var extractPathFromURL = extractExpoPathFromURL;
//# sourceMappingURL=extractPathFromURL.native.js.map