UNPKG

dynamic-interaction

Version:

Dynamic interaction 动态交互mcp,用于cursor、windsurf、trae 等 AI 智能编辑器 Agent 运行时交互使用

50 lines 1.19 kB
/** * 通用工具函数 */ /** * 生成唯一ID */ export function generateUniqueId(prefix = 'id') { return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; } /** * 防抖函数 */ export function debounce(func, wait) { let timeout = null; return (...args) => { if (timeout !== null) { clearTimeout(timeout); } timeout = window.setTimeout(() => func(...args), wait); }; } /** * 节流函数 */ export function throttle(func, limit) { let inThrottle; return (...args) => { if (!inThrottle) { func(...args); inThrottle = true; setTimeout(() => inThrottle = false, limit); } }; } /** * 截断文本 */ export function truncateText(text, maxLength) { const plainText = text .replace(/\*\*(.*?)\*\*/g, '$1') .replace(/\*(.*?)\*/g, '$1') .replace(/\[(.*?)\]\(.*?\)/g, '$1') .replace(/#{1,6}\s+/g, '') .replace(/`{1,3}([\s\S]*?)`{1,3}/g, '$1'); if (plainText.length <= maxLength) { return plainText; } return plainText.substring(0, maxLength) + '...'; } //# sourceMappingURL=helpers.js.map