This is a perfect scenario to introduce a Custom Pipe.
https://angular.dev/guide/templates/pipes
Pipes are useful when you need to call a function from a template. The main advantage is Pipes are memoized, meaning they only recalculate when the input value changes.
Otherwise, it's likely your function will be called every change-detection cycle. Gross!
Just import the pipe into multiple different components to reuse the logic.