isCustomElement.js 767 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. const { htmlTypeSelectors } = require('../reference/selectors');
  3. const mathMLTags = require('mathml-tag-names');
  4. const svgTags = require('svg-tags');
  5. /**
  6. * Check whether a type selector is a custom element
  7. *
  8. * @param {string} selector
  9. * @returns {boolean}
  10. */
  11. module.exports = function isCustomElement(selector) {
  12. if (!/^[a-z]/.test(selector)) {
  13. return false;
  14. }
  15. if (!selector.includes('-')) {
  16. return false;
  17. }
  18. const selectorLowerCase = selector.toLowerCase();
  19. if (selectorLowerCase !== selector) {
  20. return false;
  21. }
  22. if (svgTags.includes(selectorLowerCase)) {
  23. return false;
  24. }
  25. if (htmlTypeSelectors.has(selectorLowerCase)) {
  26. return false;
  27. }
  28. if (mathMLTags.includes(selectorLowerCase)) {
  29. return false;
  30. }
  31. return true;
  32. };