diff --git a/__init__.py b/__init__.py index bea349e..e2ee80f 100644 --- a/__init__.py +++ b/__init__.py @@ -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), diff --git a/nodes/combiner.py b/nodes/combiner.py new file mode 100644 index 0000000..9ad7861 --- /dev/null +++ b/nodes/combiner.py @@ -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,)