UNPKG

@shirokuma-library/mcp-knowledge-base

Version:

MCP server for AI-powered knowledge management with semantic search, graph analysis, and automatic enrichment

41 lines (40 loc) 1.3 kB
export function isValidType(type) { if (!type || type.length === 0) { return false; } const pattern = /^[a-z0-9_]+$/; return pattern.test(type); } export function normalizeType(type) { if (!type) { throw new Error('Type cannot be empty'); } let normalized = type.toLowerCase() .replace(/[^a-z0-9_]/g, '_'); normalized = normalized.replace(/^_+|_+$/g, ''); normalized = normalized.replace(/_+/g, '_'); if (normalized.length === 0 || /^_+$/.test(normalized)) { if (/[a-z0-9]/i.test(type)) { throw new Error('Type contains no valid characters'); } else if (/^[\u0001-\u007F]+$/.test(type)) { throw new Error('Type contains no valid characters'); } else if (/^[\u{1F000}-\u{1FAFF}]/u.test(type)) { throw new Error('Type contains no valid characters'); } else { return ''; } } return normalized; } export function validateType(type, autoNormalize = false) { if (autoNormalize) { return normalizeType(type); } if (isValidType(type)) { return type; } throw new Error(`Invalid type format: "${type}". Type must contain only lowercase letters (a-z), numbers (0-9), and underscores (_)`); }