PluginProbe
ZIP AI – AI Website Builder & AI Agent (Beta) / 0.0.4
ZIP AI – AI Website Builder & AI Agent (Beta) v0.0.4
0.0.10 0.0.9 trunk 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8
zip-ai / src / utils / contentNormalizer.js

contentNormalizer.js in ZIP AI – AI Website Builder & AI Agent (Beta) 0.0.4, at src/utils/contentNormalizer.js

42 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Content Normalizer
3 *
4 * Normalizes message content into a uniform block structure.
5 * Supports string (legacy) and array (structured) content formats.
6 */
7
8 /**
9 * Normalize content into an array of typed blocks.
10 * @param {string|Array} content - Message content (string or block array)
11 * @returns {Array<{type: string, text?: string, componentType?: string, props?: Object}>}
12 */
13 export const normalizeContent = (content) => {
14 if (!content) return [];
15
16 // Already structured — return as-is
17 if (Array.isArray(content)) return content;
18
19 // Legacy string format → single text block
20 return [{ type: 'text', text: content }];
21 };
22
23 /**
24 * Extract plain text from content for copy/clipboard.
25 * @param {string|Array} content - Message content (string or block array)
26 * @returns {string}
27 */
28 export const getTextContent = (content) => {
29 if (!content) return '';
30
31 if (typeof content === 'string') return content;
32
33 if (Array.isArray(content)) {
34 return content
35 .filter((block) => block.type === 'text')
36 .map((block) => block.text)
37 .join('\n\n');
38 }
39
40 return '';
41 };
42