-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringToggle.py
More file actions
23 lines (21 loc) · 938 Bytes
/
StringToggle.py
File metadata and controls
23 lines (21 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from .common import FlexibleOptionalInputType, AnyType
optional = FlexibleOptionalInputType(AnyType('STRING'))
optional.update({
'previous': ('STRING', {'forceInput': True, 'default': '', 'multiline': True})
})
class StringToggle:
@classmethod
def INPUT_TYPES(cls) -> dict:
return {
'required': { 'separator': ('STRING', {'default': ', '}) },
'optional': optional
}
RETURN_TYPES = ('STRING',)
FUNCTION = 'join'
CATEGORY = 'utils'
def join(self, separator: str, previous: str = '', **kwargs) -> tuple[str]:
arguments = {}
for (argtype, unique), value in [(k.split('_'),v) for k,v in kwargs.items() if '_' in k]:
arguments.setdefault(argtype, {})[unique] = value
strings = ([previous] if previous else []) + [text for unique, text in arguments['text'].items() if arguments['append'][unique]]
return (separator.join(strings),)