1 Commits
Author SHA1 Message Date
Michael Poutre 55d735087f feat: Add string list replace node 2023-10-29 18:30:06 -07:00
2 changed files with 43 additions and 1 deletions
+4 -1
View File
@@ -22,6 +22,7 @@ from custom_nodes.Comfy_KepListStuff.nodes.range_nodes import (
IntNumStepsRangeNode,
FloatNumStepsRangeNode,
)
from custom_nodes.Comfy_KepListStuff.nodes.strings import StringReplace
from custom_nodes.Comfy_KepListStuff.nodes.xy import UnzippedProductAny
NODE_CLASS_MAPPINGS = {
@@ -43,7 +44,8 @@ NODE_CLASS_MAPPINGS = {
"Kep_VariableImageBuilder": VariableImageBuilder,
"Kep_ReverseList": ReverseList,
"Kep_RepeatList": RepeatList,
"Kep_JoinListAny": JoinListAny
"Kep_JoinListAny": JoinListAny,
"Kep_ReplaceList": StringReplace,
}
NODE_DISPLAY_NAME_MAPPINGS = {
@@ -55,4 +57,5 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"Kep_RepeatList": "Repeat List",
"Kep_JoinListAny": "Join List Any",
"KepStringListFromNewline": "String List From Newline",
"Kep_ReplaceList": "Replace With List",
}
+39
View File
@@ -0,0 +1,39 @@
from typing import Any, Dict, List, Tuple
from custom_nodes.Comfy_KepListStuff.utils import AnyType
any_type = AnyType("*")
class StringReplace:
def __init__(self) -> None:
pass
@classmethod
def INPUT_TYPES(self) -> Dict[str, Dict[str, Any]]:
return {
"required": {
"String": ("STRING", {"multiline": True}),
"Old": ("STRING", {"multiline": False}),
"New": (any_type, {}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("Strings",)
INPUT_IS_LIST = True
OUTPUT_IS_LIST = (True,)
FUNCTION = "list_replace"
CATEGORY = "List Stuff"
def list_replace(self, String: List[str], Old: List[str], New: List[Any]) -> Tuple[List[str]]:
if len(Old) != 1:
raise ValueError("Old does not support multiple values")
if len(String) != 1:
raise ValueError("String does not support multiple values")
returns = []
for replacement in New:
returns.append(String[0].replace(Old[0], str(replacement)))
return (returns,)