UNPKG

one

Version:

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

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