MCPcopy Create free account
hub / github.com/omkarcloud/botasaurus / hide_text_with_asterisk

Function hide_text_with_asterisk

botasaurus/string_utils.py:52–81  ·  view source on GitHub ↗

Hides the text using asterisks, replacing characters with '*'. Args: data: The input data, which can be a dictionary, list, or string. exceptKeys (list): A list of keys to exclude from hiding in dictionaries. Returns: The data with the text hidd

(data, exceptKeys=[])

Source from the content-addressed store, hash-verified

50 return "".join(arr)
51
52def hide_text_with_asterisk(data, exceptKeys=[]):
53 """
54 Hides the text using asterisks, replacing characters with '*'.
55
56 Args:
57 data: The input data, which can be a dictionary, list, or string.
58 exceptKeys (list): A list of keys to exclude from hiding in dictionaries.
59
60 Returns:
61 The data with the text hidden using asterisks.
62
63 Examples:
64 hide_text_with_asterisk("password")
65 Output: "p*s*w**d"
66
67 hide_text_with_asterisk({"username": "john", "password": "secret"}, exceptKeys=["username"])
68 Output: {"username": "john", "password": "s*c**t"}
69
70 hide_text_with_asterisk(["apple", "banana", "cherry"])
71 Output: ["a*p*e", "b*n**a", "c*e**y"]
72 """
73 if isinstance(data, dict):
74 exceptKeys_set = set(exceptKeys)
75 return {key: applyTransformer(value, asteriskText) if key not in exceptKeys_set else value for key, value in data.items()}
76 elif isinstance(data, list):
77 return [hide_text_with_asterisk(element, exceptKeys) for element in data]
78 elif isinstance(data, str):
79 return asteriskText(data)
80 else:
81 return data
82
83def ht(data, exceptKeys=[]):
84 """

Callers 1

htFunction · 0.85

Calls 3

asteriskTextFunction · 0.85
applyTransformerFunction · 0.70
itemsMethod · 0.45

Tested by

no test coverage detected