835fe898343189fca5fd92a2998cf4c2c251fa72d5e5daf334602783df32a5461b1c59ecbf59611c681c72484a381cc07c352f413326768148cbb210b2b5cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. @license
  3. Rollup.js v3.29.4
  4. Sat, 21 Sep 2024 06:29:06 GMT - commit 2ef77c00ec2635d42697cff2c0567ccc8db34fb4
  5. https://github.com/rollup/rollup
  6. Released under the MIT License.
  7. */
  8. 'use strict';
  9. Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  10. const getLogFilter = filters => {
  11. if (filters.length === 0)
  12. return () => true;
  13. const normalizedFilters = filters.map(filter => filter.split('&').map(subFilter => {
  14. const inverted = subFilter.startsWith('!');
  15. if (inverted)
  16. subFilter = subFilter.slice(1);
  17. const [key, ...value] = subFilter.split(':');
  18. return { inverted, key: key.split('.'), parts: value.join(':').split('*') };
  19. }));
  20. return (log) => {
  21. nextIntersectedFilter: for (const intersectedFilters of normalizedFilters) {
  22. for (const { inverted, key, parts } of intersectedFilters) {
  23. const isFilterSatisfied = testFilter(log, key, parts);
  24. if (inverted ? isFilterSatisfied : !isFilterSatisfied) {
  25. continue nextIntersectedFilter;
  26. }
  27. }
  28. return true;
  29. }
  30. return false;
  31. };
  32. };
  33. const testFilter = (log, key, parts) => {
  34. let rawValue = log;
  35. for (let index = 0; index < key.length; index++) {
  36. if (!rawValue) {
  37. return false;
  38. }
  39. const part = key[index];
  40. if (!(part in rawValue)) {
  41. return false;
  42. }
  43. rawValue = rawValue[part];
  44. }
  45. let value = typeof rawValue === 'object' ? JSON.stringify(rawValue) : String(rawValue);
  46. if (parts.length === 1) {
  47. return value === parts[0];
  48. }
  49. if (!value.startsWith(parts[0])) {
  50. return false;
  51. }
  52. const lastPartIndex = parts.length - 1;
  53. for (let index = 1; index < lastPartIndex; index++) {
  54. const part = parts[index];
  55. const position = value.indexOf(part);
  56. if (position === -1) {
  57. return false;
  58. }
  59. value = value.slice(position + part.length);
  60. }
  61. return value.endsWith(parts[lastPartIndex]);
  62. };
  63. exports.getLogFilter = getLogFilter;
  64. //# sourceMappingURL=getLogFilter.js.map