UNPKG

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