Reusable library in capella

I am working on an eventing function using Capella UI and have noticed some redundant code. I would like to refactor it by moving the common logic to a reusable library function or a global location.
Could anyone suggest possible approaches or best practices for achieving this in Capella?