@unchainedshop/logger 4.5.0 → 4.6.1

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.
@@ -3,6 +3,11 @@ import { stringify } from 'safe-stable-stringify';
3
3
  import { LogLevel } from "./logger.types.js";
4
4
  const regexCache = new Map();
5
5
  const debugPatternCache = new Map();
6
+ const escapeRegexForDebug = (pattern) => {
7
+ return pattern
8
+ .replace(/[.+?^${}()|[\]\\]/g, '\\$&')
9
+ .replace(/\*/g, '.*');
10
+ };
6
11
  const debugStringContainsModule = (debugString, moduleName) => {
7
12
  if (!debugString)
8
13
  return false;
@@ -13,14 +18,26 @@ const debugStringContainsModule = (debugString, moduleName) => {
13
18
  const loggingMatched = debugString.split(',').reduce((accumulator, name) => {
14
19
  if (accumulator === false)
15
20
  return accumulator;
16
- let regExp = regexCache.get(name);
21
+ const trimmedName = name.trim();
22
+ if (!trimmedName)
23
+ return accumulator;
24
+ let regExp = regexCache.get(trimmedName);
17
25
  if (!regExp) {
18
- const nameRegex = name.replace(/-/i, '\\-?').replace(/:\*/i, '\\:?*').replace(/\*/i, '.*');
19
- regExp = new RegExp(`^${nameRegex}$`, 'm');
20
- regexCache.set(name, regExp);
26
+ const isExclusion = trimmedName.startsWith('-');
27
+ const patternToMatch = isExclusion ? trimmedName.slice(1) : trimmedName;
28
+ const safePattern = escapeRegexForDebug(patternToMatch);
29
+ regExp = new RegExp(`^${safePattern}$`);
30
+ regexCache.set(trimmedName, regExp);
31
+ }
32
+ const isExclusion = trimmedName.startsWith('-');
33
+ const patternToMatch = isExclusion ? trimmedName.slice(1) : trimmedName;
34
+ let testRegExp = regexCache.get(isExclusion ? `-${patternToMatch}` : patternToMatch);
35
+ if (!testRegExp) {
36
+ const safePattern = escapeRegexForDebug(patternToMatch);
37
+ testRegExp = new RegExp(`^${safePattern}$`);
21
38
  }
22
- if (regExp.test(moduleName)) {
23
- if (name.slice(0, 1) === '-') {
39
+ if (testRegExp.test(moduleName)) {
40
+ if (isExclusion) {
24
41
  return false;
25
42
  }
26
43
  return true;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/logger",
3
- "version": "4.5.0",
3
+ "description": "High-performance logging package for the Unchained Engine",
4
+ "version": "4.6.1",
4
5
  "main": "lib/logger-index.js",
5
6
  "types": "lib/logger-index.d.ts",
6
7
  "type": "module",
@@ -11,6 +12,7 @@
11
12
  "prepublishOnly": "npm run clean && npm run build",
12
13
  "watch": "tsc -w",
13
14
  "test": "node --test",
15
+ "test:run:unit": "node --test",
14
16
  "test:watch": "node --test --watch",
15
17
  "benchmark": "node benchmarks/benchmark.ts"
16
18
  },