validation.js 1.3 KB

12345678910111213141516171819202122232425262728
  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.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.htmlSelectorRe = void 0;
  11. exports.validateHtmlSelector = validateHtmlSelector;
  12. exports.validateClassName = validateClassName;
  13. const schematics_1 = require("@angular-devkit/schematics");
  14. // Must start with a letter, and must contain only alphanumeric characters or dashes.
  15. // When adding a dash the segment after the dash must also start with a letter.
  16. exports.htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*((:?-[0-9]+)*|(:?-[a-zA-Z][.0-9a-zA-Z]*(:?-[0-9]+)*)*)$/;
  17. // See: https://github.com/tc39/proposal-regexp-unicode-property-escapes/blob/fe6d07fad74cd0192d154966baa1e95e7cda78a1/README.md#other-examples
  18. const ecmaIdentifierNameRegExp = /^(?:[$_\p{ID_Start}])(?:[$_\u200C\u200D\p{ID_Continue}])*$/u;
  19. function validateHtmlSelector(selector) {
  20. if (selector && !exports.htmlSelectorRe.test(selector)) {
  21. throw new schematics_1.SchematicsException(`Selector "${selector}" is invalid.`);
  22. }
  23. }
  24. function validateClassName(className) {
  25. if (!ecmaIdentifierNameRegExp.test(className)) {
  26. throw new schematics_1.SchematicsException(`Class name "${className}" is invalid.`);
  27. }
  28. }