guards.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.isUniversal = exports.isTag = exports.isString = exports.isSelector = exports.isRoot = exports.isPseudo = exports.isNesting = exports.isIdentifier = exports.isComment = exports.isCombinator = exports.isClassName = exports.isAttribute = undefined;
  4. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  5. var _IS_TYPE;
  6. exports.isNode = isNode;
  7. exports.isPseudoElement = isPseudoElement;
  8. exports.isPseudoClass = isPseudoClass;
  9. exports.isContainer = isContainer;
  10. exports.isNamespace = isNamespace;
  11. var _types = require("./types");
  12. 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);
  13. function isNode(node) {
  14. return (typeof node === "undefined" ? "undefined" : _typeof(node)) === "object" && IS_TYPE[node.type];
  15. }
  16. function isNodeType(type, node) {
  17. return isNode(node) && node.type === type;
  18. }
  19. var isAttribute = exports.isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
  20. var isClassName = exports.isClassName = isNodeType.bind(null, _types.CLASS);
  21. var isCombinator = exports.isCombinator = isNodeType.bind(null, _types.COMBINATOR);
  22. var isComment = exports.isComment = isNodeType.bind(null, _types.COMMENT);
  23. var isIdentifier = exports.isIdentifier = isNodeType.bind(null, _types.ID);
  24. var isNesting = exports.isNesting = isNodeType.bind(null, _types.NESTING);
  25. var isPseudo = exports.isPseudo = isNodeType.bind(null, _types.PSEUDO);
  26. var isRoot = exports.isRoot = isNodeType.bind(null, _types.ROOT);
  27. var isSelector = exports.isSelector = isNodeType.bind(null, _types.SELECTOR);
  28. var isString = exports.isString = isNodeType.bind(null, _types.STRING);
  29. var isTag = exports.isTag = isNodeType.bind(null, _types.TAG);
  30. var isUniversal = exports.isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
  31. function isPseudoElement(node) {
  32. return isPseudo(node) && node.value && (node.value.startsWith("::") || node.value === ":before" || node.value === ":after");
  33. }
  34. function isPseudoClass(node) {
  35. return isPseudo(node) && !isPseudoElement(node);
  36. }
  37. function isContainer(node) {
  38. return !!(isNode(node) && node.walk);
  39. }
  40. function isNamespace(node) {
  41. return isAttribute(node) || isTag(node);
  42. }