add join string n-elements.

This commit is contained in:
Wutipong Wongsakuldej
2023-11-21 04:07:11 +07:00
parent 40fab79eff
commit ecf49d10ec
2 changed files with 34 additions and 0 deletions
+3
View File
@@ -2,12 +2,14 @@ from .create_n_token_node import CreateNTokenStringNode
from .join_string_node import JoinStringsNode
from .split_string_node import SplitStringNode
from .join_string_list_node import JoinStringListNode
from .join_string_list_n_element_node import JoinStringListNElementNode
NODE_CLASS_MAPPINGS = {
"Text Utils - String Subparts": CreateNTokenStringNode,
"Text Utils - Join Strings": JoinStringsNode,
"Text Utils - Split String to List": SplitStringNode,
"Text Utils - Join String List": JoinStringListNode,
"Text Utils - Join String List N-Elements": JoinStringListNElementNode,
}
NODE_DISPLAY_NAME_MAPPINGS = {
@@ -15,4 +17,5 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"Text Utils - Join Strings": "Join Strings",
"Text Utils - Split String to list": "Split String to List",
"Text Utils - Join String List": "Join String List to one string",
"Text Utils - Join String List N-Elements": "Join N-Element of String List to one string",
}
+31
View File
@@ -0,0 +1,31 @@
class JoinStringListNElementNode:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"texts": ("STRING", {"forceInput": True}),
"separator": ("STRING", {"default": "/"}),
"n": ("INT", {"default": 0, "min": 0, "max": 10000, "step": 1}),
"start_from": (["front", "back"],)
},
}
INPUT_IS_LIST = True
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("TEXT",)
FUNCTION = "perform_join_string_list"
CATEGORY = "text utility"
def perform_join_string_list(self, texts, separator, n, start_from):
separator = separator[0]
n = n[0]
start_from = start_from[0]
if start_from == "front":
return (separator.join(texts[0: n]), )
else:
l = len(texts)
start = l - n
if start < 0:
start = 0
return (separator.join(texts[start: l]), )