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