utils.ts 649 B

1234567891011121314151617181920212223
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. export type Classes = Record<string, string>
  3. export const clean = (str: string) => str.replace(/\s{2,}/g, ' ').trim()
  4. export const extendClasses = (
  5. originalClasses: Classes | undefined,
  6. newClasses: Classes,
  7. ) => {
  8. const mergedClasses = { ...newClasses }
  9. Object.entries(originalClasses || {}).forEach(([type, originalClass]) => {
  10. if (!(type in mergedClasses)) {
  11. mergedClasses[type] = originalClass
  12. } else {
  13. mergedClasses[type] = clean(
  14. `${originalClass || ''} ${newClasses[type] || ''}`,
  15. )
  16. }
  17. })
  18. return mergedClasses
  19. }