diff --git a/pyproject.toml b/pyproject.toml index f34a211..5b95fce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ # MARK: Project info [project] name = "corelibs" -version = "0.4.0" +version = "0.5.0" description = "Collection of utils for Python scripts" readme = "ReadMe.md" requires-python = ">=3.13" diff --git a/src/CoreLibs/string_handling/string_helpers.py b/src/CoreLibs/string_handling/string_helpers.py index b7c9eae..867378f 100644 --- a/src/CoreLibs/string_handling/string_helpers.py +++ b/src/CoreLibs/string_handling/string_helpers.py @@ -83,4 +83,36 @@ def format_number(number: float, precision: int = 0) -> str: "f}" ).format(number) + +def mask( + data_set: dict[str, str], + mask_keys: list[str] | None = None, + mask_str: str = "***", + skip: bool = False +) -> dict[str, str]: + """ + mask data for output + Checks if mask_keys list exist in any key in the data set either from the start or at the end + + Arguments: + data_set {dict[str, str]} -- _description_ + + Keyword Arguments: + mask_keys {list[str] | None} -- _description_ (default: {None}) + mask_str {str} -- _description_ (default: {"***"}) + skip {bool} -- _description_ (default: {False}) + + Returns: + dict[str, str] -- _description_ + """ + if skip is True: + return data_set + if mask_keys is None: + mask_keys = ["password", "secret"] + return { + key: mask_str + if any(key.startswith(mask_key) or key.endswith(mask_key) for mask_key in mask_keys) else value + for key, value in data_set.items() + } + # __END__