Implement string functions

This commit is contained in:
StableLlama
2025-05-04 22:58:20 +02:00
parent 0a540424ae
commit 187e9d4bf4
5 changed files with 1947 additions and 2 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ __author__ = """Basic data handling"""
__email__ = "stablellama@tutanota.com"
__version__ = "0.0.1"
from .src.basic_data_handling.nodes import NODE_CLASS_MAPPINGS
from .src.basic_data_handling.nodes import NODE_DISPLAY_NAME_MAPPINGS
from .src.basic_data_handling import NODE_CLASS_MAPPINGS
from .src.basic_data_handling import NODE_DISPLAY_NAME_MAPPINGS
WEB_DIRECTORY = "./web"
+11
View File
@@ -0,0 +1,11 @@
from . import string_nodes, list_nodes, dict_nodes
NODE_CLASS_MAPPINGS = {}
NODE_CLASS_MAPPINGS.update(string_nodes.NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(list_nodes.NODE_CLASS_MAPPINGS)
NODE_CLASS_MAPPINGS.update(dict_nodes.NODE_CLASS_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS.update(string_nodes.NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(list_nodes.NODE_DISPLAY_NAME_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(dict_nodes.NODE_DISPLAY_NAME_MAPPINGS)
+60
View File
@@ -0,0 +1,60 @@
from inspect import cleandoc
class DictGet:
"""
Retrieves a value from a dictionary using the specified key.
If the key is not found, the node will return None.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input_dict": ("DICT",),
"key": ("STRING", {"default": ""}),
}
}
RETURN_TYPES = ("ANY",)
CATEGORY = "Basic/DICT"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "get"
def get(self, input_dict, key):
return (input_dict.get(key, None),)
class DictSet:
"""
Adds or updates a key-value pair in a dictionary.
This node takes a dictionary, key, and value as inputs, then returns
a modified dictionary with the new key-value pair.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input_dict": ("DICT",),
"key": ("STRING", {"default": ""}),
"value": ("ANY",),
}
}
RETURN_TYPES = ("DICT",)
CATEGORY = "Basic/DICT"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "set"
def set(self, input_dict, key, value):
input_dict[key] = value
return (input_dict,)
NODE_CLASS_MAPPINGS = {
"DictGet": DictGet,
"DictSet": DictSet,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"DictGet": "get",
"DictSet": "set",
}
+58
View File
@@ -0,0 +1,58 @@
from inspect import cleandoc
class ListAppend:
"""
Adds an item to the end of a list.
This node takes a list and any item as inputs, then returns the modified
list with the new item appended.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input_list": ("LIST",),
"item": ("ANY",),
}
}
RETURN_TYPES = ("LIST",)
CATEGORY = "Basic/LIST"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "append"
def append(self, input_list, item):
input_list.append(item)
return (input_list,)
class ListLength:
"""
Counts the number of items in a list.
This node takes a list as input and returns its length as an integer.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input_list": ("LIST",),
}
}
RETURN_TYPES = ("INT",)
CATEGORY = "Basic/LIST"
DESCRIPTION = cleandoc(__doc__ or "")
FUNCTION = "length"
def length(self, input_list):
return (len(input_list),)
NODE_CLASS_MAPPINGS = {
"ListAppend": ListAppend,
"ListLength": ListLength,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"ListAppend": "append",
"ListLength": "length",
}
File diff suppressed because it is too large Load Diff