Added TextSplitter, TextJoiner, ListInfo

This commit is contained in:
Lukas Julian Lambertz
2025-06-21 12:44:47 +02:00
parent 912c03e1bb
commit 81587bdf29
4 changed files with 292 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
"""
DebugPadawan's ComfyUI Essentials
A collection of essential custom nodes for ComfyUI
"""
from .nodes.text_processing import NODE_CLASS_MAPPINGS as TEXT_NODES
from .nodes.text_processing import NODE_DISPLAY_NAME_MAPPINGS as TEXT_DISPLAY_NAMES
# Combine all node mappings
NODE_CLASS_MAPPINGS = {}
NODE_CLASS_MAPPINGS.update(TEXT_NODES)
NODE_DISPLAY_NAME_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS.update(TEXT_DISPLAY_NAMES)
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
# Version info
__version__ = "1.0.0"
__author__ = "DebugPadawan"
+3
View File
@@ -0,0 +1,3 @@
"""
Nodes package for DebugPadawan's ComfyUI Essentials
"""
+172
View File
@@ -0,0 +1,172 @@
"""
Text Processing Nodes for ComfyUI
Provides various text manipulation utilities
"""
class TextSplitter:
"""
Node for splitting text strings by a delimiter
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {
"multiline": True,
"default": "apple,banana,orange"
}),
"delimiter": ("STRING", {
"multiline": False,
"default": ","
}),
},
"optional": {
"strip_whitespace": ("BOOLEAN", {
"default": True
}),
"remove_empty": ("BOOLEAN", {
"default": True
}),
}
}
RETURN_TYPES = ("LIST", "INT")
RETURN_NAMES = ("text_list", "count")
FUNCTION = "split_text"
CATEGORY = "DebugPadawan/Text"
def split_text(self, text, delimiter, strip_whitespace=True, remove_empty=True):
"""
Split text by delimiter and return list with count
Args:
text (str): Input text to split
delimiter (str): Character(s) to split by
strip_whitespace (bool): Whether to strip whitespace from each item
remove_empty (bool): Whether to remove empty strings from result
Returns:
tuple: (list of strings, count of items)
"""
# Split the text
result = text.split(delimiter)
# Strip whitespace if requested
if strip_whitespace:
result = [item.strip() for item in result]
# Remove empty strings if requested
if remove_empty:
result = [item for item in result if item]
return (result, len(result))
class TextJoiner:
"""
Node for joining a list of strings with a delimiter
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text_list": ("LIST",),
"delimiter": ("STRING", {
"multiline": False,
"default": ", "
}),
},
"optional": {
"prefix": ("STRING", {
"multiline": False,
"default": ""
}),
"suffix": ("STRING", {
"multiline": False,
"default": ""
}),
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("joined_text",)
FUNCTION = "join_text"
CATEGORY = "DebugPadawan/Text"
def join_text(self, text_list, delimiter, prefix="", suffix=""):
"""
Join list of strings with delimiter
Args:
text_list (list): List of strings to join
delimiter (str): String to join with
prefix (str): String to add at the beginning
suffix (str): String to add at the end
Returns:
str: Joined string
"""
# Convert all items to strings
str_list = [str(item) for item in text_list]
# Join with delimiter
result = delimiter.join(str_list)
# Add prefix and suffix
result = prefix + result + suffix
return (result,)
class ListInfo:
"""
Node for getting information about a list
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input_list": ("LIST",),
}
}
RETURN_TYPES = ("INT", "STRING", "STRING")
RETURN_NAMES = ("count", "first_item", "last_item")
FUNCTION = "get_list_info"
CATEGORY = "DebugPadawan/Utilities"
def get_list_info(self, input_list):
"""
Get information about a list
Args:
input_list (list): Input list to analyze
Returns:
tuple: (count, first_item, last_item)
"""
count = len(input_list)
first_item = str(input_list[0]) if input_list else ""
last_item = str(input_list[-1]) if input_list else ""
return (count, first_item, last_item)
# Node mappings for ComfyUI
NODE_CLASS_MAPPINGS = {
"DebugPadawan_TextSplitter": TextSplitter,
"DebugPadawan_TextJoiner": TextJoiner,
"DebugPadawan_ListInfo": ListInfo,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"DebugPadawan_TextSplitter": "Text Splitter",
"DebugPadawan_TextJoiner": "Text Joiner",
"DebugPadawan_ListInfo": "List Info",
}
+97
View File
@@ -0,0 +1,97 @@
"""
Utility Nodes for ComfyUI
Provides various helper utilities
"""
class DebugPrint:
"""
Node for debugging - prints values to console
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"value": ("*",),
},
"optional": {
"label": ("STRING", {
"multiline": False,
"default": "Debug"
}),
}
}
RETURN_TYPES = ("*",)
RETURN_NAMES = ("passthrough",)
FUNCTION = "debug_print"
CATEGORY = "DebugPadawan/Debug"
def debug_print(self, value, label="Debug"):
"""
Print value to console for debugging
Args:
value: Any value to print
label (str): Label for the debug output
Returns:
The same value (passthrough)
"""
print(f"[{label}] {type(value).__name__}: {value}")
return (value,)
class ConditionalString:
"""
Node for conditional string output based on boolean input
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"condition": ("BOOLEAN",),
"true_string": ("STRING", {
"multiline": True,
"default": "True"
}),
"false_string": ("STRING", {
"multiline": True,
"default": "False"
}),
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("result",)
FUNCTION = "conditional_string"
CATEGORY = "DebugPadawan/Logic"
def conditional_string(self, condition, true_string, false_string):
"""
Return string based on condition
Args:
condition (bool): Condition to evaluate
true_string (str): String to return if True
false_string (str): String to return if False
Returns:
str: Selected string
"""
return (true_string if condition else false_string,)
# Add these to the main mappings if needed
UTILITY_NODE_CLASS_MAPPINGS = {
"DebugPadawan_DebugPrint": DebugPrint,
"DebugPadawan_ConditionalString": ConditionalString,
}
UTILITY_NODE_DISPLAY_NAME_MAPPINGS = {
"DebugPadawan_DebugPrint": "Debug Print",
"DebugPadawan_ConditionalString": "Conditional String",
}