From 8156d24ec99ab71f5205ea6b1ca41cbb884917e9 Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Sun, 17 Dec 2023 00:24:01 +0530 Subject: [PATCH] docs: get_abbr --- frappe/utils/data.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index bab8c97ebe..ea786e5153 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -402,6 +402,16 @@ def today() -> str: def get_abbr(string: str, max_len: int = 2) -> str: + """Returns the abbreviation of the given string. + + Examples: + + * "John Doe" => "JD" + * "Jenny Jane Doe" => "JJ" (default, `max_len` = 2) + * "Jenny Jane Doe" => "JJD" (`max_len` = 3) + + Returns "?" if the given string is empty. + """ abbr = "" for part in string.split(" "): if len(abbr) < max_len and part: