diff --git a/docs/source/config_reference/scripting/scripting_functions.rst b/docs/source/config_reference/scripting/scripting_functions.rst index cc42c52c..61076fa7 100644 --- a/docs/source/config_reference/scripting/scripting_functions.rst +++ b/docs/source/config_reference/scripting/scripting_functions.rst @@ -660,6 +660,24 @@ contains_any :description: Returns true if any element in ``contains_array`` is in ``string``. False otherwise. +join +~~~~ +:spec: ``join(separator: String, array: Array) -> String`` + +:description: + Join all elements in the array together as a string, and insert the + separator between them. + +:usage: + +.. code-block:: python + + { + %join( ", ", ["item1", "item2"] ) + } + + # "item1, item2" + lower ~~~~~ :spec: ``lower(string: String) -> String`` @@ -710,6 +728,23 @@ string :description: Cast to String. +strip +~~~~~ +:spec: ``strip(string: String) -> String`` + +:description: + Strip a string of all its whitespace at the beginning and end. + +:usage: + +.. code-block:: python + + { + %trim(" delete the outer! ") + } + + # "delete the outer!" + titlecase ~~~~~~~~~ :spec: ``titlecase(string: String) -> String`` diff --git a/src/ytdl_sub/script/functions/string_functions.py b/src/ytdl_sub/script/functions/string_functions.py index 7e0e0eb5..43ff87a5 100644 --- a/src/ytdl_sub/script/functions/string_functions.py +++ b/src/ytdl_sub/script/functions/string_functions.py @@ -181,7 +181,8 @@ class StringFunctions: def join(separator: String, array: Array) -> String: """ :description: - Join all elements in the array together as a string, and insert the separator between them. + Join all elements in the array together as a string, and insert the + separator between them. :usage: @@ -212,4 +213,4 @@ class StringFunctions: # "delete the outer!" """ - return String(string.value.strip()) \ No newline at end of file + return String(string.value.strip()) diff --git a/tests/unit/script/functions/test_string_functions.py b/tests/unit/script/functions/test_string_functions.py index de0fd116..bc5bfc32 100644 --- a/tests/unit/script/functions/test_string_functions.py +++ b/tests/unit/script/functions/test_string_functions.py @@ -155,7 +155,11 @@ class TestNumericFunctions: @pytest.mark.parametrize( "value, expected_output", - [("['a', 'b', 'c']", 'a, b, c'), ("['nope', [], {}]", 'nope, [], {}'), ("['a', 1, 3.14, True]", 'a, 1, 3.14, true')], + [ + ("['a', 'b', 'c']", "a, b, c"), + ("['nope', [], {}]", "nope, [], {}"), + ("['a', 1, 3.14, True]", "a, 1, 3.14, true"), + ], ) def test_join(self, value, expected_output): output = single_variable_output(f"{{%join(', ', {value})}}") @@ -163,8 +167,8 @@ class TestNumericFunctions: @pytest.mark.parametrize( "value, expected_output", - [(" delete outer ", 'delete outer'), (" delete me\n\n", 'delete me')], + [(" delete outer ", "delete outer"), (" delete me\n\n", "delete me")], ) def test_strip(self, value, expected_output): output = single_variable_output(f"{{%strip('{value}')}}") - assert output == expected_output \ No newline at end of file + assert output == expected_output