UNPKG

sicua

Version:

A tool for analyzing project structure and dependencies

95 lines (94 loc) 3.42 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SeoRelated = void 0; const typescript_1 = __importDefault(require("typescript")); class SeoRelated { static extractRouteParams(route) { const params = []; const paramRegex = /:([^/]+)/g; let match; while ((match = paramRegex.exec(route)) !== null) { params.push(match[1]); } return params; } static isInternalLink(href) { // Check if the href is internal return (href.startsWith("/") || href.startsWith("./") || href.startsWith("../") || !href.includes("://")); } static getJsxTagName(node) { if (typescript_1.default.isJsxElement(node)) { const identifier = node.openingElement.tagName; return typescript_1.default.isIdentifier(identifier) ? identifier.text.toLowerCase() : ""; } else { const identifier = node.tagName; return typescript_1.default.isIdentifier(identifier) ? identifier.text.toLowerCase() : ""; } } static extractStaticValue(node) { if (typescript_1.default.isStringLiteral(node)) { return node.text; } if (typescript_1.default.isTemplateExpression(node)) { // Handle template literals with only static parts if (node.templateSpans.length === 0) { return node.head.text; } } if (typescript_1.default.isPropertyAccessExpression(node)) { // Try to handle common router constant patterns const text = node.getText(); if (text.includes("routes.") || text.includes("ROUTES.")) { return this.extractRouteConstant(text); } } return null; } static extractRouteConstant(text) { // Remove common prefixes and get the route path const routePath = text.replace(/^(routes|ROUTES)\./, ""); // Convert camelCase or CONSTANT_CASE to path format return routePath ? "/" + routePath .replace(/([A-Z])/g, "-$1") .toLowerCase() .replace(/^-/, "") .replace(/_/g, "-") : null; } static getCommonElements(arr) { const counts = new Map(); arr.forEach((item) => counts.set(item, (counts.get(item) || 0) + 1)); return Array.from(counts.entries()) .filter(([_, count]) => count > 1) .map(([item]) => item); } static calculateAverage(numbers) { return numbers.length > 0 ? numbers.reduce((a, b) => a + b, 0) / numbers.length : 0; } static getTypeFromThing(thing) { // Use type assertion to access @type since we know it exists on Thing return thing["@type"] || "Unknown"; } // Type guards static isGraph(schema) { return "graph" in schema && Array.isArray(schema.graph); } static isThingWithType(item) { return (typeof item === "object" && item !== null && "@type" in item && typeof item["@type"] === "string"); } } exports.SeoRelated = SeoRelated;