MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / transform

Function transform

apps/web/ui/Message/utilities/transform.ts:1–28  ·  view source on GitHub ↗
(node: any, count = 1)

Source from the content-addressed store, hash-verified

1export default function transform(node: any, count = 1) {
2 count += 1;
3 node.cid = `${node.source || node.id}-${count}`;
4 if (node.type === 'code') {
5 if (node.value.includes('\n')) {
6 node.type = 'pre';
7 }
8 }
9 if (node.type === 'text') {
10 const value = node.value.trim().toLowerCase();
11 if (value.startsWith('{') && value.endsWith('}')) {
12 try {
13 JSON.parse(value);
14 node.type = 'pre';
15 } catch (exception) {}
16 }
17
18 if (value.startsWith('<!doctype html>') && value.endsWith('</html>')) {
19 node.type = 'pre';
20 }
21 }
22 if (node.children) {
23 node.children = node.children.map((node: any, index: number) =>
24 transform(node, count + index)
25 );
26 }
27 return node;
28}

Callers 2

MessageFunction · 0.85
transform.spec.tsFile · 0.85

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected