UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

63 lines 3.22 kB
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.cjs"), import_shared = require("./_shared.cjs"); function getPathWithConventionsCollapsed({ pattern, route, params, preserveGroups, preserveDynamicRoutes, shouldEncodeURISegment = !0, initialRouteName }) { const segments = pattern.split("/"); return segments.map((p, i) => { const name = (0, import_shared.getParamName)(p); if (p.startsWith("*")) 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?.split("/").slice(i + 1).join("/"); if (p.startsWith(":")) { if (preserveDynamicRoutes) return `[${name}]`; const value = params[name]; return value === void 0 && p.endsWith("?") ? void 0 : (shouldEncodeURISegment ? encodeURISegment(value) : value) ?? "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(v => v ?? "").join("/"); } function encodeURIComponentPreservingBrackets(str) { return encodeURIComponent(str).replace(/%5B/g, "[").replace(/%5D/g, "]"); } function appendBaseUrl(path, baseUrl = 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; } function encodeURISegment(str, { preserveBrackets = !1 } = {}) { return str = String(str).replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]/g, char => encodeURIComponent(char)), preserveBrackets && (str = str.replace(/%5B/g, "[").replace(/%5D/g, "]")), str; }