guards.js 2.6 KB

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