isCustomElement.js 862 B

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