guards.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.isComment = exports.isCombinator = exports.isClassName = exports.isAttribute = void 0;
  4. exports.isContainer = isContainer;
  5. exports.isIdentifier = void 0;
  6. exports.isNamespace = isNamespace;
  7. exports.isNesting = void 0;
  8. exports.isNode = isNode;
  9. exports.isPseudo = void 0;
  10. exports.isPseudoClass = isPseudoClass;
  11. exports.isPseudoElement = isPseudoElement;
  12. exports.isUniversal = exports.isTag = exports.isString = exports.isSelector = exports.isRoot = void 0;
  13. var _types = require("./types");
  14. var _IS_TYPE;
  15. var IS_TYPE = (_IS_TYPE = {}, _IS_TYPE[_types.ATTRIBUTE] = true, _IS_TYPE[_types.CLASS] = true, _IS_TYPE[_types.COMBINATOR] = true, _IS_TYPE[_types.COMMENT] = true, _IS_TYPE[_types.ID] = true, _IS_TYPE[_types.NESTING] = true, _IS_TYPE[_types.PSEUDO] = true, _IS_TYPE[_types.ROOT] = true, _IS_TYPE[_types.SELECTOR] = true, _IS_TYPE[_types.STRING] = true, _IS_TYPE[_types.TAG] = true, _IS_TYPE[_types.UNIVERSAL] = true, _IS_TYPE);
  16. function isNode(node) {
  17. return typeof node === "object" && IS_TYPE[node.type];
  18. }
  19. function isNodeType(type, node) {
  20. return isNode(node) && node.type === type;
  21. }
  22. var isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  23. exports.isAttribute = isAttribute;
  24. var isClassName = isNodeType.bind(null, _types.CLASS);
  25. exports.isClassName = isClassName;
  26. var isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  27. exports.isCombinator = isCombinator;
  28. var isComment = isNodeType.bind(null, _types.COMMENT);
  29. exports.isComment = isComment;
  30. var isIdentifier = isNodeType.bind(null, _types.ID);
  31. exports.isIdentifier = isIdentifier;
  32. var isNesting = isNodeType.bind(null, _types.NESTING);
  33. exports.isNesting = isNesting;
  34. var isPseudo = isNodeType.bind(null, _types.PSEUDO);
  35. exports.isPseudo = isPseudo;
  36. var isRoot = isNodeType.bind(null, _types.ROOT);
  37. exports.isRoot = isRoot;
  38. var isSelector = isNodeType.bind(null, _types.SELECTOR);
  39. exports.isSelector = isSelector;
  40. var isString = isNodeType.bind(null, _types.STRING);
  41. exports.isString = isString;
  42. var isTag = isNodeType.bind(null, _types.TAG);
  43. exports.isTag = isTag;
  44. var isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  45. exports.isUniversal = isUniversal;
  46. function isPseudoElement(node) {
  47. return isPseudo(node) && node.value && (node.value.startsWith("::") || node.value.toLowerCase() === ":before" || node.value.toLowerCase() === ":after" || node.value.toLowerCase() === ":first-letter" || node.value.toLowerCase() === ":first-line");
  48. }
  49. function isPseudoClass(node) {
  50. return isPseudo(node) && !isPseudoElement(node);
  51. }
  52. function isContainer(node) {
  53. return !!(isNode(node) && node.walk);
  54. }
  55. function isNamespace(node) {
  56. return isAttribute(node) || isTag(node);
  57. }