diff --git a/README.md b/README.md index 0989aed..e9fcaff 100644 --- a/README.md +++ b/README.md @@ -220,9 +220,9 @@ schema = ... [ "tsm_mapper", {"English": "eng"}, - "English", + "English" ] - ], + ] }, ... ``` @@ -233,22 +233,45 @@ Works as `tsm_mapper` but with list. Doesn't have a `default` value. Third argum If `remove` set to True, removes values from the list if they don't have a corresponding mapping. Defaults to `False`. +Example without `remove`: + ```py data = {"topic": ["Health", "Military", "Utilities"]} schema = ... - "language": { + "topic": { "validators": [ [ - "tsm_mapper", - {"English": "eng"}, - "English", + "tsm_list_mapper", + {"Military": "Army", "Utilities": "Utility"} ] - ], + ] }, ... ``` +The result here will be `["Health", "Army", "Utility"]` +And here's an example with remove: + +```py +data: dict[str, Any] = {"topic": ["Health", "Military", "Utilities"]} + +tsm_schema = build_schema( + { + "topic": { + "validators": [ + [ + "tsm_list_mapper", + {"Military": "Army", "Utilities": "Utility"}, + True + ] + ] + }, + } +) +``` +This will result in `["Army", "Utility"]`, and the `Health` will be deleted, cause it doesn't have a mapping. + ### Keywords 1. `map` (`str`) - changes the `field.name` in result dict. 2. `validators` (`list[str]`) - a list of transmutators that will be applied to a `field.value`. A transmutator could be a `string` or a `list` where the first item must be transmutator name and others are arbitrary values. Example: