@holz/pattern-filter 0.8.2 → 0.8.3-rc.152
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/holz-pattern-filter.cjs +1 -1
- package/dist/holz-pattern-filter.js +14 -17
- package/dist/src/__tests__/pattern-filter.test.d.ts +1 -0
- package/dist/src/__tests__/string-match.test.d.ts +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/{holz-pattern-filter.d.ts → src/pattern-filter.d.ts} +24 -27
- package/dist/src/string-match.d.ts +16 -0
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=e=>e.split(/[\s,]+/).filter(Boolean).reduce((e,t)=>(t[0]===`-`?e.exclude.push(n(t.slice(1))):e.include.push(n(t)),e),{include:[],exclude:[]}),t=(e,t)=>e.exclude.every(e=>!e.test(t))&&e.include.some(e=>e.test(t)),n=e=>{let t=e.replace(/\*/g,`.*?`);return RegExp(`^${t}$`)},r=({processor:n,pattern:r})=>{let i=e(r);return e=>{t(i,e.origin.join(`:`))&&n(e)}};exports.createPatternFilter=r;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
l(e, r.origin.join(":")) && t(r);
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export {
|
|
17
|
-
i as createPatternFilter
|
|
1
|
+
//#region src/string-match.ts
|
|
2
|
+
var e = (e) => e.split(/[\s,]+/).filter(Boolean).reduce((e, t) => (t[0] === "-" ? e.exclude.push(n(t.slice(1))) : e.include.push(n(t)), e), {
|
|
3
|
+
include: [],
|
|
4
|
+
exclude: []
|
|
5
|
+
}), t = (e, t) => e.exclude.every((e) => !e.test(t)) && e.include.some((e) => e.test(t)), n = (e) => {
|
|
6
|
+
let t = e.replace(/\*/g, ".*?");
|
|
7
|
+
return RegExp(`^${t}$`);
|
|
8
|
+
}, r = ({ processor: n, pattern: r }) => {
|
|
9
|
+
let i = e(r);
|
|
10
|
+
return (e) => {
|
|
11
|
+
t(i, e.origin.join(":")) && n(e);
|
|
12
|
+
};
|
|
18
13
|
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { r as createPatternFilter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createPatternFilter } from './pattern-filter';
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
import { LogProcessor } from '@holz/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export declare const createPatternFilter: ({ processor, pattern, }: Config) => LogProcessor;
|
|
26
|
-
|
|
27
|
-
export { }
|
|
1
|
+
import { LogProcessor } from '@holz/core';
|
|
2
|
+
/**
|
|
3
|
+
* Only forwards logs who's origin matches the given pattern. It works the
|
|
4
|
+
* same as the popular `debug` module.
|
|
5
|
+
*
|
|
6
|
+
* Patterns allow wildcards and negation. For example, the pattern `my-app*`
|
|
7
|
+
* will match all logs with the origin `my-app` or `my-app:foo` or
|
|
8
|
+
* `my-app:foo:bar`. The pattern `*, -my-app` will match all logs except those
|
|
9
|
+
* with the origin `my-app`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* createPatternFilter({
|
|
13
|
+
* pattern: 'my-app*, -spammy:library',
|
|
14
|
+
* processor: backend,
|
|
15
|
+
* })
|
|
16
|
+
*/
|
|
17
|
+
export declare const createPatternFilter: ({ processor, pattern, }: Config) => LogProcessor;
|
|
18
|
+
interface Config {
|
|
19
|
+
/** A set of patterns to test against `log.origin`. */
|
|
20
|
+
pattern: string;
|
|
21
|
+
/** Where to send logs if they pass the filter. */
|
|
22
|
+
processor: LogProcessor;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a string of multiple patterns into a set of regular expressions. We
|
|
3
|
+
* use a pattern string (instead of regexes) because it's easier to persist in
|
|
4
|
+
* storage or specify through a CLI.
|
|
5
|
+
*
|
|
6
|
+
* Special thanks to `debug-js` for the inspiration. I read their code as
|
|
7
|
+
* a guide for this implementation.
|
|
8
|
+
*/
|
|
9
|
+
export declare const parse: (input: string) => PatternFilters;
|
|
10
|
+
/** Detect if a string matches a set of patterns. */
|
|
11
|
+
export declare const matches: (filters: PatternFilters, input: string) => boolean;
|
|
12
|
+
interface PatternFilters {
|
|
13
|
+
include: Array<RegExp>;
|
|
14
|
+
exclude: Array<RegExp>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holz/pattern-filter",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3-rc.152+a4ea736",
|
|
4
4
|
"description": "Only print log messages that match a pattern",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -33,20 +33,20 @@
|
|
|
33
33
|
],
|
|
34
34
|
"scripts": {
|
|
35
35
|
"prepack": "vite build",
|
|
36
|
-
"test:unit": "vitest --color --passWithNoTests",
|
|
36
|
+
"test:unit": "vitest run --color --passWithNoTests",
|
|
37
37
|
"test:types": "tsc"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@holz/core": "^0.8.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@holz/core": "^0.8.
|
|
44
|
-
"@vitest/coverage-v8": "^
|
|
45
|
-
"typescript": "^
|
|
46
|
-
"vite": "^
|
|
47
|
-
"vite-plugin-dts": "^
|
|
48
|
-
"vite-tsconfig-paths": "^
|
|
49
|
-
"vitest": "^
|
|
43
|
+
"@holz/core": "^0.8.3-rc.152+a4ea736",
|
|
44
|
+
"@vitest/coverage-v8": "^4.0.0",
|
|
45
|
+
"typescript": "^6.0.0",
|
|
46
|
+
"vite": "^8.0.0",
|
|
47
|
+
"vite-plugin-dts": "^5.0.0",
|
|
48
|
+
"vite-tsconfig-paths": "^6.0.0",
|
|
49
|
+
"vitest": "^4.0.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "a4ea7361cad7340841a12ca7c7366ffbd25eaa35"
|
|
52
52
|
}
|