Skip to content

Commit ebe864b

Browse files
committed
implementation substr(start= ,end=)
1 parent 490f6d9 commit ebe864b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/data_weaver3/transforms.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
from typing import Any, Callable, Dict
44
import unicodedata
5+
import ast
56

67
def apply_to_value(value, func, *args, **kwargs):
78
if isinstance(value, dict):
@@ -89,6 +90,11 @@ def remove_accents_val(val):
8990
return ''.join(c for c in unicodedata.normalize('NFD', val) if unicodedata.category(c) != 'Mn')
9091
return apply_to_value(value, remove_accents_val)
9192

93+
def substr(value : str | list | dict, start:int, end:int)->str:
94+
def substr_val(val):
95+
return val[start:end]
96+
return apply_to_value(value,substr_val)
97+
9298
TRANSFORMATIONS: Dict[str, Callable[..., Any]] = {
9399
"capitalize": capitalize,
94100
"lower": lower,
@@ -103,6 +109,7 @@ def remove_accents_val(val):
103109
"join": lambda value, delimiter='': join(value, delimiter),
104110
"replace": lambda value, old, new: replace(value, old, new),
105111
"regex": lambda value, pattern, replace: regex(value, pattern, replace),
112+
"substr": lambda value, start=0, end=-1: substr(value, start, end)
106113
}
107114

108115
def parse_args(args: str) -> dict:

0 commit comments

Comments
 (0)