MCPcopy Create free account
hub / github.com/Shazbot/WH3-Mod-Manager / executeTextSurroundNode

Function executeTextSurroundNode

src/nodeExecutor.ts:2972–3057  ·  view source on GitHub ↗
(
  nodeId: string,
  textValue: string,
  inputData: any,
  config?: unknown,
)

Source from the content-addressed store, hash-verified

2970}
2971
2972async function executeTextSurroundNode(
2973 nodeId: string,
2974 textValue: string,
2975 inputData: any,
2976 config?: unknown,
2977): Promise<NodeExecutionResult> {
2978 console.log(`TextSurround Node ${nodeId}: Processing with config "${textValue}" and input:`, inputData);
2979
2980 if (!inputData) {
2981 return { success: false, error: "Invalid input: No input data provided" };
2982 }
2983
2984 // Parse configuration
2985 let surroundText = textValue;
2986 let groupedTextSelection: "Text" | "Text Lines" = "Text";
2987
2988 const parsedConfig = getNodeConfig<{ surroundText?: string; groupedTextSelection?: "Text" | "Text Lines" }>(
2989 config,
2990 textValue,
2991 );
2992 if (parsedConfig) {
2993 surroundText = parsedConfig.surroundText || "";
2994 groupedTextSelection = parsedConfig.groupedTextSelection || "Text";
2995 } else {
2996 // If not JSON, treat as simple surround text
2997 surroundText = textValue;
2998 }
2999
3000 // Parse the surround configuration (could be prefix/suffix separated by | or just a prefix)
3001 const parts = surroundText.split("|");
3002 let prefix = parts[0] || "";
3003 let suffix = parts[1] || parts[0] || "";
3004
3005 // Process escape sequences
3006 prefix = prefix.replace(/\\n/g, "\n").replace(/\\t/g, "\t").replace(/\\r/g, "\r");
3007 suffix = suffix.replace(/\\n/g, "\n").replace(/\\t/g, "\t").replace(/\\r/g, "\r");
3008
3009 let outputText: any;
3010 let outputTextLines: any;
3011 let outputType = inputData.type || "Text";
3012
3013 // Handle GroupedText input - preserve structure
3014 if (inputData.type === "GroupedText") {
3015 // GroupedText has both text (array of keys) and textLines (array of arrays of values)
3016 // We modify only the selected one and keep the other unchanged
3017
3018 // Default: keep both unchanged
3019 outputText = inputData.text;
3020 outputTextLines = inputData.textLines;
3021
3022 // Only modify the selected field
3023 if (groupedTextSelection === "Text") {
3024 // Modify text array (keys) only
3025 if (inputData.text && Array.isArray(inputData.text)) {
3026 outputText = inputData.text.map((key: string) => `${prefix}${key}${suffix}`);
3027 }
3028 } else {
3029 // Modify textLines array (values) only

Callers 1

executeNodeActionFunction · 0.85

Calls 1

getNodeConfigFunction · 0.85

Tested by

no test coverage detected