Implement string functions
This commit is contained in:
+2
-2
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
@@ -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
Reference in New Issue
Block a user