Added split and join nodes

This commit is contained in:
exectails
2024-11-25 20:51:22 +01:00
parent 5c8cec67af
commit 1015913b26
2 changed files with 60 additions and 0 deletions
+4
View File
@@ -1,9 +1,13 @@
from .nodes.combiner import ETSplitTextNode, ETJoinTextNode
from .nodes.converter import ETATOI, ETITOA
from .nodes.formatter import ETTextFormatter2Node, ETTextFormatter5Node, ETTextFormatter10Node
from .nodes.scripting import ETPythonTextScript3Node
from .nodes.replacer import ETReplaceTextNode
et_nodes = {
("Split Text", ETSplitTextNode),
("Join Text", ETJoinTextNode),
("ATOI", ETATOI),
("ITOA", ETITOA),
+56
View File
@@ -0,0 +1,56 @@
class ETSplitTextNode:
"""
A node splits text on a string and returns a string list.
"""
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"default": "", "multiline": False, "forceInput": True, "tooltip": "The text to split."}),
"split_by": ("STRING", {"default": ",", "multiline": False, "tooltip": "The string to split the text on."}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
OUTPUT_IS_LIST = (True,)
CATEGORY = "exectails"
FUNCTION = "process"
def process(self, text: str, split_by: str) -> tuple:
result = text.split(split_by)
return (result,)
class ETJoinTextNode:
"""
A node that joins a list of strings.
"""
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"default": "", "multiline": False, "forceInput": True, "tooltip": "The text to replace in."}),
"join_with": ("STRING", {"default": ", ", "multiline": False, "tooltip": "The string to join the elements with."}),
"prefix": ("STRING", {"default": "", "multiline": False, "tooltip": "A string to place before the text."}),
"suffix": ("STRING", {"default": "", "multiline": False, "tooltip": "A string to place after the text."}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
INPUT_IS_LIST = True
CATEGORY = "exectails"
FUNCTION = "process"
def process(self, text: list, join_with: str, prefix: str, suffix: str) -> tuple:
join_with = join_with[0]
prefix = prefix[0]
suffix = suffix[0]
result = prefix + join_with.join(text) + suffix
return (result,)