one
Version:
One is a new React Framework that makes Vite serve both native and web.
106 lines (104 loc) • 4.39 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) {
var href = parsePathFromExpoGoLink(url),
results = href.match(/([^?]*)(\?.*)?/),
_results_,
_results_1;
return {
pathname: (_results_ = results?.[1]) !== null && _results_ !== void 0 ? _results_ : "",
queryString: (_results_1 = results?.[2]) !== null && _results_1 !== void 0 ? _results_1 : ""
};
}
function parsePathFromExpoGoLink(url) {
var _url_match, _url_match_;
return (_url_match_ = (_url_match = url.match(/exps?:\/\/.*?\/--\/(.*)/)) === null || _url_match === void 0 ? void 0 : _url_match[1]) !== null && _url_match_ !== void 0 ? _url_match_ : "";
}
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);
return hostname === "exp.host" || hostname === "u.expo.dev" ? "" : href.replace(origin, "");
}
var isExpoGo = typeof globalThis.expo < "u" && ((_globalThis_expo = globalThis.expo) === null || _globalThis_expo === 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,
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];
return queryParams ? fromDeepLink("a://?" + queryParams) : "";
}
return fromDeepLink(url);
}
function isExpoDevelopmentClient(url) {
return url.hostname === "expo-development-client";
}
function fromDeepLink(url) {
var res;
try {
res = new URL(url);
} catch {
return url.startsWith("/") ? url : url.replace(/^[^:]+:\/\//, "");
}
if (isExpoDevelopmentClient(res)) {
if (!res.searchParams.get("url")) return "";
var incomingUrl = res.searchParams.get("url");
return extractExactPathFromURL(decodeURI(incomingUrl));
}
var results = "";
res.host && (results += res.host), 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("&") : "";
return qs && (results += "?" + qs), results;
}
function extractExpoPathFromURL(_prefixes) {
var url = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
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;
}
var extractPathFromURL = extractExpoPathFromURL;
//# sourceMappingURL=extractPathFromURL.native.js.map