one
Version:
One is a new React Framework that makes Vite serve both native and web.
54 lines (53 loc) • 2.24 kB
JavaScript
var dynamicNameRe = /^\[([^[\]]+?)\]$/;
function matchDynamicName(name) {
var _name_match,
paramName = (_name_match = name.match(dynamicNameRe)) === null || _name_match === void 0 ? void 0 : _name_match[1];
if (paramName != null) return paramName.startsWith("...") ? {
name: paramName.slice(3),
deep: !0
} : {
name: paramName,
deep: !1
};
}
function matchDeepDynamicRouteName(name) {
var _name_match;
return (_name_match = name.match(/^\[\.\.\.([^/]+?)\]$/)) === null || _name_match === void 0 ? void 0 : _name_match[1];
}
function testNotFound(name) {
return name.endsWith("+not-found");
}
function matchGroupName(name) {
var _name_match;
return (_name_match = name.match(/^(?:[^\\(\\)])*?\(([^\\/]+)\).*?$/)) === null || _name_match === void 0 ? void 0 : _name_match[1];
}
function matchArrayGroupName(name) {
var _name_match;
return (_name_match = name.match(/(?:[^\\(\\)])*?\(?([^\\/()]+,[^\\/()]+)\)?.*?$/)) === null || _name_match === void 0 ? void 0 : _name_match[1];
}
function getNameFromFilePath(name) {
return removeSupportedExtensions(removeFileSystemDots(name));
}
function getContextKey(name) {
var normal = "/" + getNameFromFilePath(name);
return normal.endsWith("_layout") ? normal.replace(/\/?_layout$/, "") : normal;
}
function removeSupportedExtensions(name) {
return name.replace(/(\+(api|spa|ssg|ssr))?\.[jt]sx?$/g, "");
}
function removeFileSystemDots(filePath) {
return filePath.replace(/^(?:\.\.?\/)+/g, "");
}
function stripGroupSegmentsFromPath(path) {
return path.split("/").reduce(function (acc, v) {
return matchGroupName(v) == null && acc.push(v), acc;
}, []).join("/");
}
function stripInvisibleSegmentsFromPath(path) {
return stripGroupSegmentsFromPath(path).replace(/\/?index$/, "");
}
function isTypedRoute(name) {
return !name.startsWith("+") && !name.endsWith(".d.ts") && name.match(/(_layout|[^/]*?\+[^/]*?)\.[tj]sx?$/) === null;
}
export { getContextKey, getNameFromFilePath, isTypedRoute, matchArrayGroupName, matchDeepDynamicRouteName, matchDynamicName, matchGroupName, removeFileSystemDots, removeSupportedExtensions, stripGroupSegmentsFromPath, stripInvisibleSegmentsFromPath, testNotFound };
//# sourceMappingURL=matchers.native.js.map