one
Version:
One is a new React Framework that makes Vite serve both native and web.
126 lines (124 loc) • 4.22 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 getPathFromState_mods_exports = {};
__export(getPathFromState_mods_exports, {
appendBaseUrl: () => appendBaseUrl,
getPathWithConventionsCollapsed: () => getPathWithConventionsCollapsed
});
module.exports = __toCommonJS(getPathFromState_mods_exports);
var import_matchers = require("../router/matchers.native.js");
var import_shared = require("./_shared.native.js");
function getPathWithConventionsCollapsed(param) {
var {
pattern,
route,
params,
preserveGroups,
preserveDynamicRoutes,
shouldEncodeURISegment = true,
initialRouteName
} = param;
var segments = pattern.split("/");
return segments.map(function (p, i) {
var name = (0, import_shared.getParamName)(p);
if (p.startsWith("*")) {
var _route_name;
if (preserveDynamicRoutes) {
if (name === "not-found") {
return "+not-found";
}
return `[...${name}]`;
}
if (params[name]) {
if (Array.isArray(params[name])) {
return params[name].join("/");
}
return params[name];
}
if (route.name.startsWith("[") && route.name.endsWith("]")) {
return "";
}
if (i === 0) {
return route;
}
if (p === "*not-found") {
return "";
}
return (_route_name = route.name) === null || _route_name === void 0 ? void 0 : _route_name.split("/").slice(i + 1).join("/");
}
if (p.startsWith(":")) {
var _ref;
if (preserveDynamicRoutes) {
return `[${name}]`;
}
var value = params[name];
if (value === void 0 && p.endsWith("?")) {
return void 0;
}
return (_ref = shouldEncodeURISegment ? encodeURISegment(value) : value) !== null && _ref !== void 0 ? _ref : "undefined";
}
if (!preserveGroups && (0, import_matchers.matchGroupName)(p) != null) {
if (segments.length - 1 === i) {
if (initialRouteName) {
if (segmentMatchesConvention(initialRouteName)) {
return "";
}
return shouldEncodeURISegment ? encodeURIComponentPreservingBrackets(initialRouteName) : initialRouteName;
}
}
return "";
}
return shouldEncodeURISegment ? encodeURIComponentPreservingBrackets(p) : p;
}).map(function (v) {
return v !== null && v !== void 0 ? v : "";
}).join("/");
}
function encodeURIComponentPreservingBrackets(str) {
return encodeURIComponent(str).replace(/%5B/g, "[").replace(/%5D/g, "]");
}
function appendBaseUrl(path) {
var baseUrl = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : process.env.EXPO_BASE_URL;
if (process.env.NODE_ENV !== "development") {
if (baseUrl) {
return `/${baseUrl.replace(/^\/+/, "").replace(/\/$/, "")}${path}`;
}
}
return path;
}
function segmentMatchesConvention(segment) {
return segment === "index" || (0, import_matchers.matchDynamicName)(segment) != null || (0, import_matchers.matchGroupName)(segment) != null;
}
function encodeURISegment(str) {
var {
preserveBrackets = false
} = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
str = String(str).replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]/g, function (char) {
return encodeURIComponent(char);
});
if (preserveBrackets) {
str = str.replace(/%5B/g, "[").replace(/%5D/g, "]");
}
return str;
}
//# sourceMappingURL=getPathFromState-mods.native.js.map