one
Version:
One is a new React Framework that makes Vite serve both native and web.
42 lines (41 loc) • 2.2 kB
JavaScript
import { CSS_PRELOAD_JS_POSTFIX, isNative, LOADER_JS_POSTFIX, LOADER_JS_POSTFIX_REGEX, PRELOAD_JS_POSTFIX } from "../constants.native.js";
import { getURL } from "../getURL.native.js";
import { removeSearch } from "./removeSearch.native.js";
function encodeReservedFilenameChars(path) {
return path.replaceAll("=", "=3d").replace(/[<>:"|?*]/g, function (char) {
return `=${char.charCodeAt(0).toString(16).padStart(2, "0")}`;
});
}
function decodeReservedFilenameChars(path) {
return path.replace(/=([0-9a-f]{2})/g, function (_match, hexCode) {
return String.fromCharCode(Number.parseInt(hexCode, 16));
});
}
function cleanUrl(path) {
return encodeReservedFilenameChars(removeSearch(path).replace(/\/$/, "")).replaceAll("_", "__").replaceAll("/", "_");
}
var isClient = typeof window !== "undefined";
var clientSideURL = isClient ? getURL() : "";
function getPreloadPath(currentPath) {
return `${clientSideURL}/assets/${cleanUrl(currentPath.slice(1))}${PRELOAD_JS_POSTFIX}`;
}
function getPreloadCSSPath(currentPath) {
return `${clientSideURL}/assets/${cleanUrl(currentPath.slice(1))}${CSS_PRELOAD_JS_POSTFIX}`;
}
function getLoaderPath(currentPath) {
var includeUrl = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : isNative,
cacheBust = arguments.length > 2 ? arguments[2] : void 0;
var baseURL = includeUrl ? getURL() : "";
var devPath = process.env.NODE_ENV === "development" ? "/_one" : "";
var currentPathUrl = new URL(currentPath, "http://example.com");
var cleanedUrl = cleanUrl(currentPathUrl.pathname.slice(1));
var cacheBustSegment = cacheBust ? `_refetch_${cacheBust}_` : "";
return `${baseURL}${devPath}/assets/${cleanedUrl}${cacheBustSegment}${LOADER_JS_POSTFIX}`;
}
function getPathFromLoaderPath(loaderPath) {
return decodeReservedFilenameChars(loaderPath.replace(LOADER_JS_POSTFIX_REGEX, "").replace(/^(\/_one)?\/assets/, "").replace(/_refetch_\d+_?/, "").replace(/__|_/g, function (match) {
return match === "__" ? "_" : "/";
}));
}
export { decodeReservedFilenameChars, encodeReservedFilenameChars, getLoaderPath, getPathFromLoaderPath, getPreloadCSSPath, getPreloadPath };
//# sourceMappingURL=cleanUrl.native.js.map