positionals.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getLimit = exports.isFilter = exports.filterNames = void 0;
  4. exports.filterNames = new Set([
  5. "first",
  6. "last",
  7. "eq",
  8. "gt",
  9. "nth",
  10. "lt",
  11. "even",
  12. "odd",
  13. ]);
  14. function isFilter(s) {
  15. if (s.type !== "pseudo")
  16. return false;
  17. if (exports.filterNames.has(s.name))
  18. return true;
  19. if (s.name === "not" && Array.isArray(s.data)) {
  20. // Only consider `:not` with embedded filters
  21. return s.data.some(function (s) { return s.some(isFilter); });
  22. }
  23. return false;
  24. }
  25. exports.isFilter = isFilter;
  26. function getLimit(filter, data) {
  27. var num = data != null ? parseInt(data, 10) : NaN;
  28. switch (filter) {
  29. case "first":
  30. return 1;
  31. case "nth":
  32. case "eq":
  33. return isFinite(num) ? (num >= 0 ? num + 1 : Infinity) : 0;
  34. case "lt":
  35. return isFinite(num) ? (num >= 0 ? num : Infinity) : 0;
  36. case "gt":
  37. return isFinite(num) ? Infinity : 0;
  38. default:
  39. return Infinity;
  40. }
  41. }
  42. exports.getLimit = getLimit;