22import re
33from typing import Any , Callable , Dict
44import unicodedata
5+ import ast
56
67def 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+
9298TRANSFORMATIONS : 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
108115def parse_args (args : str ) -> dict :
0 commit comments