is-svg-component.mjs 815 B

123456789101112131415161718192021222324252627282930
  1. import { lowercaseSVGElements } from '../../svg/lowercase-elements.mjs';
  2. function isSVGComponent(Component) {
  3. if (
  4. /**
  5. * If it's not a string, it's a custom React component. Currently we only support
  6. * HTML custom React components.
  7. */
  8. typeof Component !== "string" ||
  9. /**
  10. * If it contains a dash, the element is a custom HTML webcomponent.
  11. */
  12. Component.includes("-")) {
  13. return false;
  14. }
  15. else if (
  16. /**
  17. * If it's in our list of lowercase SVG tags, it's an SVG component
  18. */
  19. lowercaseSVGElements.indexOf(Component) > -1 ||
  20. /**
  21. * If it contains a capital letter, it's an SVG component
  22. */
  23. /[A-Z]/u.test(Component)) {
  24. return true;
  25. }
  26. return false;
  27. }
  28. export { isSVGComponent };