From a0c57ae864f63016a09a03484d3d7e517c728fd2 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Thu, 23 Apr 2026 10:35:37 +0200 Subject: [PATCH 1/4] add utility functions --- utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 utils.py diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..812cfca --- /dev/null +++ b/utils.py @@ -0,0 +1,18 @@ +def calculate_discount(price, percentage): + return price - (price * percentage / 100) + + +def is_valid_email(email): + return "@" in email and "." in email.split("@")[-1] + + +def format_user_name(first, last): + return f"{first.strip().capitalize()} {last.strip().capitalize()}" + + +def clamp(value, min_value, max_value): + if value < min_value: + return min_value + if value > max_value: + return max_value + return value From 24d19644c6452bbf3e21f1d3e94d44315674d4d5 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Thu, 23 Apr 2026 10:51:45 +0200 Subject: [PATCH 2/4] add truncate_string and parse_int_safe utilities --- utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/utils.py b/utils.py index 812cfca..bd9c550 100644 --- a/utils.py +++ b/utils.py @@ -16,3 +16,16 @@ def clamp(value, min_value, max_value): if value > max_value: return max_value return value + + +def truncate_string(text, max_length): + if len(text) <= max_length: + return text + return text[:max_length] + "..." + + +def parse_int_safe(value): + try: + return int(value) + except (ValueError, TypeError): + return None From f783e90411c37a9de7a58e2b1ce9dcef6b5ce799 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Thu, 23 Apr 2026 11:16:41 +0200 Subject: [PATCH 3/4] add slugify utility --- utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils.py b/utils.py index bd9c550..bb6adbd 100644 --- a/utils.py +++ b/utils.py @@ -29,3 +29,7 @@ def parse_int_safe(value): return int(value) except (ValueError, TypeError): return None + + +def slugify(text): + return text.lower().strip().replace(" ", "-") From 21ed2561059a568546b192f4a1c1a500082b2c7b Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Thu, 23 Apr 2026 11:40:45 +0200 Subject: [PATCH 4/4] add pluralize utility --- utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils.py b/utils.py index bb6adbd..ec3ef5d 100644 --- a/utils.py +++ b/utils.py @@ -33,3 +33,7 @@ def parse_int_safe(value): def slugify(text): return text.lower().strip().replace(" ", "-") + + +def pluralize(word, count): + return word if count == 1 else word + "s"