-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathstring_replace_node.py
More file actions
41 lines (31 loc) · 1.02 KB
/
string_replace_node.py
File metadata and controls
41 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class StringReplaceNode:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input_string": ("STRING", {"default": "", "multiline": True}),
},
"optional": {
"placeholders": ("KEY_VALUE", {"default": None}),
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("output_string",)
FUNCTION = "replace_string"
CATEGORY = "RequestNode/Utils"
def replace_string(self, input_string, placeholders=None):
if not placeholders:
return (input_string,)
output_string = input_string
for key, value in placeholders.items():
str_value = str(value)
output_string = output_string.replace(key, str_value)
return (output_string,)
NODE_CLASS_MAPPINGS = {
"StringReplaceNode": StringReplaceNode
}
NODE_DISPLAY_NAME_MAPPINGS = {
"StringReplaceNode": "String Replace Node"
}