diff --git a/__init__.py b/__init__.py index 0f73fec..bc5f0a0 100644 --- a/__init__.py +++ b/__init__.py @@ -1,21 +1,18 @@ -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, + "Text Utils - Join N-Elements of String List": JoinStringListNElementNode, } NODE_DISPLAY_NAME_MAPPINGS = { - "Text Utils - String Subparts": "String Subparts", "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", + "Text Utils - Split String to List": "Split String to List", + "Text Utils - Join String List": "Join String List", + "Text Utils - Join N-Elements of String List": "Join N-Element of String List", } diff --git a/create_n_token_node.py b/create_n_token_node.py deleted file mode 100644 index 9893f23..0000000 --- a/create_n_token_node.py +++ /dev/null @@ -1,25 +0,0 @@ -from .textutils import create_n_token_string - - -class CreateNTokenStringNode: - @classmethod - def INPUT_TYPES(cls): - return { - "required": { - "text": ("STRING", {"default": ""}), - "separator": ("STRING", {"default": "/"}), - "n": ("INT", {"default": 0, "min": 0, "max": 10000, "step": 1}), - "start_from": (["front", "back"],) - }, - } - - RETURN_TYPES = ("STRING",) - RETURN_NAMES = ("TEXT",) - FUNCTION = "perform_create_n_token_string" - CATEGORY = "text utility" - - def perform_create_n_token_string(self, text, separator, n, start_from): - if start_from == "back": - n = -n - - return (create_n_token_string(text, separator, n),) diff --git a/join_string_list_n_element_node.py b/join_string_list_n_element_node.py index b03645d..5cbc14f 100644 --- a/join_string_list_n_element_node.py +++ b/join_string_list_n_element_node.py @@ -5,7 +5,7 @@ class JoinStringListNElementNode: "required": { "texts": ("STRING", {"forceInput": True}), "separator": ("STRING", {"default": "/"}), - "n": ("INT", {"default": 0, "min": 0, "max": 10000, "step": 1}), + "n": ("INT", {"default": 1, "min": 0, "max": 10000, "step": 1}), "start_from": (["front", "back"],) }, } @@ -20,12 +20,13 @@ class JoinStringListNElementNode: 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 + start = 0 + end = n + + if start_from == "back": + end = len(texts) + start = end - n if start < 0: start = 0 - return (separator.join(texts[start: l]), ) + return (separator.join(texts[start: end]), ) diff --git a/split_string_node.py b/split_string_node.py new file mode 100644 index 0000000..32aa868 --- /dev/null +++ b/split_string_node.py @@ -0,0 +1,18 @@ +class SplitStringNode: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "text": ("STRING", {"default": ""}), + "separator": ("STRING", {"default": "/"}), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("TEXT",) + OUTPUT_IS_LIST = (True, ) + FUNCTION = "perform_split_string" + CATEGORY = "text utility" + + def perform_split_string(self, text, separator): + return (text.split(separator), ) diff --git a/test_textutitls.py b/test_textutitls.py deleted file mode 100644 index c611a91..0000000 --- a/test_textutitls.py +++ /dev/null @@ -1,42 +0,0 @@ -import textutils -import unittest - - -class TestTextUtils(unittest.TestCase): - def test_positive_tokens(self): - self.assertEqual(textutils.create_n_token_string( - "hello/world/how/are/you/doing", "/", 0), "") - self.assertEqual(textutils.create_n_token_string( - "hello/world/how/are/you/doing", "/", 1), "hello") - self.assertEqual(textutils.create_n_token_string( - "hello/world/how/are/you/doing", "/", 2), "hello/world") - - def test_negative_tokens(self): - self.assertEqual(textutils.create_n_token_string( - "hello/world/how/are/you/doing", "/", -1), "doing") - self.assertEqual(textutils.create_n_token_string( - "hello/world/how/are/you/doing", "/", -2), "you/doing") - - def test_n_exceed_length(self): - self.assertEqual(textutils.create_n_token_string( - "hello/world/how/are/you/doing", "/", 8), "hello/world/how/are/you/doing") - self.assertEqual(textutils.create_n_token_string( - "hello/world/how/are/you/doing", "/", -6), "hello/world/how/are/you/doing") - - def test_delim_at_the_begining(self): - self.assertEqual(textutils.create_n_token_string( - "/hello/world/how/are/you/doing/", "/", 0), "") - self.assertEqual(textutils.create_n_token_string( - "/hello/world/how/are/you/doing/", "/", 1), "") - self.assertEqual(textutils.create_n_token_string( - "/hello/world/how/are/you/doing/", "/", 2), "/hello") - - def test_delim_at_the_end(self): - self.assertEqual(textutils.create_n_token_string( - "hello/world/how/are/you/doing/", "/", -1), "") - self.assertEqual(textutils.create_n_token_string( - "hello/world/how/are/you/doing/", "/", -2), "doing/") - - -if __name__ == '__main__': - unittest.main() diff --git a/textutils.py b/textutils.py deleted file mode 100644 index 4d720cf..0000000 --- a/textutils.py +++ /dev/null @@ -1,12 +0,0 @@ -def create_n_token_string(str, delim, n): - parts = str.split(delim) - - if n > 0: - return delim.join(parts[0: n]) - else: - l = len(parts) - start = l + n - if start < 0: - start = 0 - - return delim.join(parts[start: l])