attribs.ts 466 B

1234567891011121314151617181920212223
  1. const attribs = Object.entries(
  2. {
  3. class: 'className',
  4. tabindex: 'tabIndex',
  5. },
  6. )
  7. interface AttribsType {
  8. [name: string]: string
  9. }
  10. export function transformAttribs(elementAttribs: AttribsType): void {
  11. if (elementAttribs) {
  12. attribs.forEach((attrib) => {
  13. const [name, replaceName] = attrib
  14. if (elementAttribs[name]) {
  15. elementAttribs[replaceName] = elementAttribs[name]
  16. delete elementAttribs[name]
  17. }
  18. })
  19. }
  20. }