MCPcopy Index your code
hub / github.com/rollup/plugins / createFilter

Function createFilter

packages/pluginutils/src/createFilter.ts:26–73  ·  view source on GitHub ↗
(include?, exclude?, options?)

Source from the content-addressed store, hash-verified

24}
25
26const createFilter: CreateFilter = function createFilter(include?, exclude?, options?) {
27 const resolutionBase = options && options.resolve;
28
29 const getMatcher = (id: string | RegExp) =>
30 id instanceof RegExp
31 ? id
32 : {
33 test: (what: string) => {
34 // this refactor is a tad overly verbose but makes for easy debugging
35 const pattern = getMatcherString(id, resolutionBase);
36 const fn = pm(pattern, { dot: true });
37 const result = fn(what);
38
39 return result;
40 }
41 };
42
43 const includeMatchers = ensureArray(include).map(getMatcher);
44 const excludeMatchers = ensureArray(exclude).map(getMatcher);
45
46 if (!includeMatchers.length && !excludeMatchers.length)
47 return (id) => typeof id === 'string' && !id.includes('\0');
48
49 return function result(id: string | unknown): boolean {
50 if (typeof id !== 'string') return false;
51 if (id.includes('\0')) return false;
52
53 const pathId = normalizePath(id);
54
55 for (let i = 0; i < excludeMatchers.length; ++i) {
56 const matcher = excludeMatchers[i];
57 if (matcher instanceof RegExp) {
58 matcher.lastIndex = 0;
59 }
60 if (matcher.test(pathId)) return false;
61 }
62
63 for (let i = 0; i < includeMatchers.length; ++i) {
64 const matcher = includeMatchers[i];
65 if (matcher instanceof RegExp) {
66 matcher.lastIndex = 0;
67 }
68 if (matcher.test(pathId)) return true;
69 }
70
71 return !includeMatchers.length;
72 };
73};
74
75export { createFilter as default };

Callers 15

wasmFunction · 0.90
dynamicImportVariablesFunction · 0.90
imageFunction · 0.90
stripFunction · 0.90
getPackageInfoFunction · 0.90
injectFunction · 0.90
typescriptFunction · 0.90
replaceFunction · 0.90
commonjsFunction · 0.90
getStrictRequiresFilterFunction · 0.90
urlFunction · 0.90
yamlFunction · 0.90

Calls 2

ensureArrayFunction · 0.85
normalizePathFunction · 0.70

Tested by

no test coverage detected