UNPKG

one

Version:

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

56 lines (55 loc) 1.87 kB
const dynamicNameRe = /^\[([^[\]]+?)\]$/; function matchDynamicName(name) { const paramName = name.match(dynamicNameRe)?.[1]; if (paramName != null) return paramName.startsWith("...") ? { name: paramName.slice(3), deep: !0 } : { name: paramName, deep: !1 }; } function matchDeepDynamicRouteName(name) { return name.match(/^\[\.\.\.([^/]+?)\]$/)?.[1]; } function testNotFound(name) { return name.endsWith("+not-found"); } function matchGroupName(name) { return name.match(/^(?:[^\\(\\)])*?\(([^\\/]+)\).*?$/)?.[1]; } function matchArrayGroupName(name) { return name.match(/(?:[^\\(\\)])*?\(?([^\\/()]+,[^\\/()]+)\)?.*?$/)?.[1]; } function getNameFromFilePath(name) { return removeSupportedExtensions(removeFileSystemDots(name)); } function getContextKey(name) { const 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((acc, v) => (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.js.map