UNPKG

1.42 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.htmlSelectorFormat = void 0;
11// As per https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
12// * Without mandatory `-` as the application prefix will generally cover its inclusion
13// * And an allowance for upper alpha characters
14// NOTE: This should eventually be broken out into two formats: full and partial (allows for prefix)
15const unicodeRanges = [
16 [0xc0, 0xd6],
17 [0xd8, 0xf6],
18 [0xf8, 0x37d],
19 [0x37f, 0x1fff],
20 [0x200c, 0x200d],
21 [0x203f, 0x2040],
22 [0x2070, 0x218f],
23 [0x2c00, 0x2fef],
24 [0x3001, 0xd7ff],
25 [0xf900, 0xfdcf],
26 [0xfdf0, 0xfffd],
27 [0x10000, 0xeffff],
28];
29function isValidElementName(name) {
30 let regex = '^[a-zA-Z][';
31 regex += '-.0-9_a-zA-Z\\u{B7}';
32 for (const range of unicodeRanges) {
33 regex += `\\u{${range[0].toString(16)}}-\\u{${range[1].toString(16)}}`;
34 }
35 regex += ']*$';
36 return new RegExp(regex, 'u').test(name);
37}
38exports.htmlSelectorFormat = {
39 name: 'html-selector',
40 formatter: {
41 async: false,
42 validate: (name) => typeof name === 'string' && isValidElementName(name),
43 },
44};