UNPKG

one

Version:

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

99 lines (97 loc) 3.82 kB
"use strict"; 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 path_exports = {}; __export(path_exports, { getPathWithRecoveredDynamicSegment: () => getPathWithRecoveredDynamicSegment, getPathnameWithRecoveredDynamicSegment: () => getPathnameWithRecoveredDynamicSegment, getSafeWindowPath: () => getSafeWindowPath, getSafeWindowPathname: () => getSafeWindowPathname, hasLostDynamicSegment: () => hasLostDynamicSegment, normalizeRoutePathname: () => normalizeRoutePathname, stripTrailingSlash: () => stripTrailingSlash }); module.exports = __toCommonJS(path_exports); var import_getStateFromPath_mods = require("../fork/getStateFromPath-mods.native.js"); function stripPathSuffix(path) { var queryIndex = path.indexOf("?"); var hashIndex = path.indexOf("#"); var end = path.length; if (queryIndex >= 0) end = Math.min(end, queryIndex); if (hashIndex >= 0) end = Math.min(end, hashIndex); return path.slice(0, end); } function stripTrailingSlash(pathname) { return pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname; } function normalizeRoutePathname(pathname) { return stripTrailingSlash((0, import_getStateFromPath_mods.stripBaseUrl)(stripPathSuffix(pathname))); } function hasLostDynamicSegment(path) { return stripPathSuffix(path).split("/").includes("undefined"); } function getSafeWindowPathname() { if (typeof window === "undefined" || !window.location || typeof window.location.pathname !== "string") { return void 0; } return window.location.pathname; } function getSafeWindowPath() { var pathname = getSafeWindowPathname(); if (pathname === void 0) return void 0; return pathname + (window.location.search || ""); } function getPathWithRecoveredDynamicSegment(paths) { var fallbackPath = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : getSafeWindowPath(); var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = paths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var path = _step.value; if (path !== void 0 && !hasLostDynamicSegment(path)) { return path; } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return fallbackPath; } function getPathnameWithRecoveredDynamicSegment(pathname) { var fallbackPath = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : getSafeWindowPath(); var _getPathWithRecoveredDynamicSegment; return normalizeRoutePathname((_getPathWithRecoveredDynamicSegment = getPathWithRecoveredDynamicSegment([pathname], fallbackPath)) !== null && _getPathWithRecoveredDynamicSegment !== void 0 ? _getPathWithRecoveredDynamicSegment : pathname); } //# sourceMappingURL=path.native.js.map