source: node_modules/rollup/dist/getLogFilter.js

Last change on this file was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 @license
3 Rollup.js v4.34.4
4 Wed, 05 Feb 2025 21:30:40 GMT - commit 19312a762c3cda56a0f6dc80a0887a4499db2257
5
6 https://github.com/rollup/rollup
7
8 Released under the MIT License.
9*/
10'use strict';
11
12Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
13
14const getLogFilter = filters => {
15 if (filters.length === 0)
16 return () => true;
17 const normalizedFilters = filters.map(filter => filter.split('&').map(subFilter => {
18 const inverted = subFilter.startsWith('!');
19 if (inverted)
20 subFilter = subFilter.slice(1);
21 const [key, ...value] = subFilter.split(':');
22 return { inverted, key: key.split('.'), parts: value.join(':').split('*') };
23 }));
24 return (log) => {
25 nextIntersectedFilter: for (const intersectedFilters of normalizedFilters) {
26 for (const { inverted, key, parts } of intersectedFilters) {
27 const isFilterSatisfied = testFilter(log, key, parts);
28 if (inverted ? isFilterSatisfied : !isFilterSatisfied) {
29 continue nextIntersectedFilter;
30 }
31 }
32 return true;
33 }
34 return false;
35 };
36};
37const testFilter = (log, key, parts) => {
38 let rawValue = log;
39 for (let index = 0; index < key.length; index++) {
40 if (!rawValue) {
41 return false;
42 }
43 const part = key[index];
44 if (!(part in rawValue)) {
45 return false;
46 }
47 rawValue = rawValue[part];
48 }
49 let value = typeof rawValue === 'object' ? JSON.stringify(rawValue) : String(rawValue);
50 if (parts.length === 1) {
51 return value === parts[0];
52 }
53 if (!value.startsWith(parts[0])) {
54 return false;
55 }
56 const lastPartIndex = parts.length - 1;
57 for (let index = 1; index < lastPartIndex; index++) {
58 const part = parts[index];
59 const position = value.indexOf(part);
60 if (position === -1) {
61 return false;
62 }
63 value = value.slice(position + part.length);
64 }
65 return value.endsWith(parts[lastPartIndex]);
66};
67
68exports.getLogFilter = getLogFilter;
69//# sourceMappingURL=getLogFilter.js.map
Note: See TracBrowser for help on using the repository browser.