nightingale-debug 14.2.1 → 16.0.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,37 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [16.0.0](https://github.com/christophehurpeau/nightingale/compare/v15.0.0...v16.0.0) (2025-03-30)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ * drop node 18
11
+
12
+ ### Features
13
+
14
+ * drop node 18 ([1b11a55](https://github.com/christophehurpeau/nightingale/commit/1b11a55dd24c9435be50519a748316079f554414))
15
+
16
+ ### Bug Fixes
17
+
18
+ * fix lib exports ([5b562b2](https://github.com/christophehurpeau/nightingale/commit/5b562b245aac1aa86b728a9433f3c9d28c62fe04))
19
+
20
+ Version bump for dependency: nightingale
21
+
22
+
23
+ ## [15.0.0](https://github.com/christophehurpeau/nightingale/compare/v14.2.1...v15.0.0) (2023-12-25)
24
+
25
+
26
+ ### ⚠ BREAKING CHANGES
27
+
28
+ * update babel and drop browser modern version
29
+
30
+ ### Features
31
+
32
+ * update babel and drop browser modern version ([5c76abc](https://github.com/christophehurpeau/nightingale/commit/5c76abc8bfb595a617fc4c8b795dae7e674ea664))
33
+
34
+ Version bump for dependency: nightingale-levels
35
+
36
+
6
37
  ## [14.2.1](https://github.com/christophehurpeau/nightingale/compare/v14.2.0...v14.2.1) (2023-11-05)
7
38
 
8
39
  Note: no notable changes
package/README.md CHANGED
@@ -1,29 +1,29 @@
1
- <h3 align="center">
1
+ <h1 align="center">
2
2
  nightingale-debug
3
- </h3>
3
+ </h1>
4
4
 
5
5
  <p align="center">
6
- Nightingale debug
6
+ Deprecated: use createFindDebugLevel from nightingale instead
7
7
  </p>
8
8
 
9
9
  <p align="center">
10
- <a href="https://npmjs.org/package/nightingale-debug"><img src="https://img.shields.io/npm/v/nightingale-debug.svg?style=flat-square"></a>
11
- <a href="https://npmjs.org/package/nightingale-debug"><img src="https://img.shields.io/npm/dw/nightingale-debug.svg?style=flat-square"></a>
12
- <a href="https://npmjs.org/package/nightingale-debug"><img src="https://img.shields.io/node/v/nightingale-debug.svg?style=flat-square"></a>
13
- <a href="https://npmjs.org/package/nightingale-debug"><img src="https://img.shields.io/npm/types/nightingale-debug.svg?style=flat-square"></a>
10
+ <a href="https://npmjs.org/package/nightingale-debug"><img src="https://img.shields.io/npm/v/nightingale-debug.svg?style=flat-square" alt="npm version"></a>
11
+ <a href="https://npmjs.org/package/nightingale-debug"><img src="https://img.shields.io/npm/dw/nightingale-debug.svg?style=flat-square" alt="npm downloads"></a>
12
+ <a href="https://npmjs.org/package/nightingale-debug"><img src="https://img.shields.io/node/v/nightingale-debug.svg?style=flat-square" alt="node version"></a>
13
+ <a href="https://npmjs.org/package/nightingale-debug"><img src="https://img.shields.io/npm/types/nightingale-debug.svg?style=flat-square" alt="types"></a>
14
14
  <a href="https://codecov.io/gh/christophehurpeau/nightingale"><img src="https://img.shields.io/codecov/c/github/christophehurpeau/nightingale/master.svg?style=flat-square"></a>
15
15
  </p>
16
16
 
17
17
  ## Install
18
18
 
19
19
  ```sh
20
- npm install --save nightingale-debug
20
+ npm install --save nightingale
21
21
  ```
22
22
 
23
23
  ## Used by:
24
24
 
25
- - [nightingale-console](https://npmjs.org/package/nightingale-console)
26
- - [nightingale-browser-console](https://npmjs.org/package/nightingale-browser-console)
25
+ - ConsoleHandler
26
+ - BrowserConsoleHandler
27
27
 
28
28
  ## Usage with nodejs
29
29
 
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ export { createFindDebugLevel } from "nightingale";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nightingale-debug",
3
- "version": "14.2.1",
4
- "description": "Nightingale debug",
3
+ "version": "16.0.0",
4
+ "description": "Deprecated: use createFindDebugLevel from nightingale instead",
5
5
  "keywords": [
6
6
  "logger"
7
7
  ],
@@ -15,77 +15,28 @@
15
15
  "homepage": "https://github.com/christophehurpeau/nightingale",
16
16
  "type": "module",
17
17
  "engines": {
18
- "node": ">=18.12.0"
18
+ "node": ">=20.9.0"
19
19
  },
20
- "browserslist": {
21
- "production": [
22
- "defaults",
23
- "> 0.2%",
24
- "not ie < 12",
25
- "not safari < 10",
26
- "not ios_saf < 10"
27
- ]
28
- },
29
- "main": "./dist/index-node18.mjs",
30
- "types": "./dist/definitions/index.d.ts",
31
- "module": "./dist/index-browser.es.js",
32
- "browser": "./dist/index-browser.es.js",
20
+ "sideEffects": false,
21
+ "main": "./lib/index.js",
22
+ "types": "./lib/index.d.ts",
33
23
  "exports": {
34
24
  "./package.json": "./package.json",
35
- ".": {
36
- "types": "./dist/definitions/index.d.ts",
37
- "node": {
38
- "import": "./dist/index-node18.mjs"
39
- },
40
- "browser": {
41
- "browser:modern": {
42
- "import": "./dist/index-browsermodern.es.js"
43
- },
44
- "import": "./dist/index-browser.es.js"
45
- }
46
- }
25
+ ".": "./lib/index.js"
47
26
  },
48
- "sideEffects": false,
49
27
  "files": [
50
- "src",
51
- "dist"
28
+ "lib"
52
29
  ],
53
30
  "scripts": {
54
- "build": "yarn clean:build && rollup --config rollup.config.mjs && yarn run build:definitions",
55
- "build:definitions": "tsc -p tsconfig.json",
56
31
  "clean": "yarn clean:build",
57
- "clean:build": "pob-babel-clean-out dist",
58
32
  "lint": "yarn run lint:eslint",
59
- "lint:eslint": "yarn ../.. run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/nightingale-debug",
33
+ "lint:eslint": "yarn ../.. run eslint --quiet packages/nightingale-debug",
60
34
  "test": "yarn ../../ run test -- packages/nightingale-debug",
61
35
  "watch": "yarn clean:build && rollup --config rollup.config.mjs --watch"
62
36
  },
37
+ "pob": {},
63
38
  "prettier": "@pob/root/prettier-config",
64
- "pob": {
65
- "babelEnvs": [
66
- {
67
- "target": "node",
68
- "version": "18"
69
- },
70
- {
71
- "target": "browser",
72
- "version": "modern"
73
- },
74
- {
75
- "target": "browser"
76
- }
77
- ],
78
- "entries": [
79
- "index"
80
- ]
81
- },
82
39
  "dependencies": {
83
- "nightingale-levels": "14.2.1"
84
- },
85
- "devDependencies": {
86
- "@babel/core": "7.23.2",
87
- "@babel/preset-env": "7.23.2",
88
- "pob-babel": "36.6.1",
89
- "typescript": "5.2.2"
40
+ "nightingale": "16.0.0"
90
41
  }
91
42
  }
@@ -1,5 +0,0 @@
1
- import { Level } from 'nightingale-levels';
2
- export type DebugValueType = RegExp | string[] | string;
3
- export type FindDebugLevel = (minLevel: Level, key: string) => Level;
4
- export declare function createFindDebugLevel(debugValue?: DebugValueType): FindDebugLevel;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAK3C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;AAqBxD,MAAM,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,KAAK,CAAC;AAErE,wBAAgB,oBAAoB,CAClC,UAAU,CAAC,EAAE,cAAc,GAC1B,cAAc,CAoEhB"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/index.test.ts"],"names":[],"mappings":""}
@@ -1,94 +0,0 @@
1
- import { Level } from 'nightingale-levels';
2
-
3
- /* eslint-disable complexity */
4
- var specialRegexpChars = /[$()+.?[\\\]^{|}]/;
5
- var createTestFunctionFromRegexp = function createTestFunctionFromRegexp(regexp) {
6
- return function (string) {
7
- return regexp.test(string);
8
- };
9
- };
10
- var createTestFunctionFromRegexpString = function createTestFunctionFromRegexpString(value) {
11
- if (!value.endsWith('/')) throw new Error('Invalid RegExp DEBUG value');
12
- return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));
13
- };
14
- var createTestFunctionFromValue = function createTestFunctionFromValue(value) {
15
- if (value.endsWith(':*')) {
16
- value = value.slice(0, -2);
17
- return function (string) {
18
- return string.startsWith(value);
19
- };
20
- }
21
- return function (string) {
22
- return string === value;
23
- };
24
- };
25
- function createFindDebugLevel(debugValue) {
26
- var isWildcard = false;
27
- var debugValues = [];
28
- var skips = [];
29
- if (!Array.isArray(debugValue)) {
30
- if (debugValue instanceof RegExp) {
31
- debugValues.push(createTestFunctionFromRegexp(debugValue));
32
- debugValue = undefined;
33
- } else if (debugValue) {
34
- debugValue = debugValue.trim();
35
- if (debugValue.startsWith('/')) {
36
- debugValues.push(createTestFunctionFromRegexpString(debugValue));
37
- debugValue = undefined;
38
- } else {
39
- debugValue = debugValue.split(/[\s,]+/);
40
- }
41
- }
42
- }
43
- if (debugValue) {
44
- debugValue.forEach(function (value) {
45
- if (specialRegexpChars.test(value)) {
46
- throw new Error("Invalid debug value: \"" + value + "\" (contains special chars)");
47
- }
48
- if (!value) return;
49
- if (value === '*') {
50
- isWildcard = true;
51
- return;
52
- }
53
- if (value.startsWith('-')) {
54
- skips.push(createTestFunctionFromValue(value.slice(1)));
55
- } else if (!isWildcard) {
56
- debugValues.push(createTestFunctionFromValue(value));
57
- }
58
- });
59
- }
60
- if (isWildcard) {
61
- if (skips.length === 0) {
62
- return function () {
63
- return Level.ALL;
64
- };
65
- } else {
66
- return function (minLevel, key) {
67
- return skips.some(function (skip) {
68
- return skip(key);
69
- }) ? minLevel : Level.ALL;
70
- };
71
- }
72
- }
73
- if (debugValues.length === 0) {
74
- return function (minLevel) {
75
- return minLevel;
76
- };
77
- }
78
- return function (minLevel, key) {
79
- if (minLevel === Level.ALL || !key) {
80
- return minLevel;
81
- }
82
- if (debugValues.some(function (dv) {
83
- return dv(key);
84
- })) {
85
- return skips.some(function (skip) {
86
- return skip(key);
87
- }) ? minLevel : Level.ALL;
88
- }
89
- return minLevel;
90
- };
91
- }
92
-
93
- export { createFindDebugLevel };
94
- //# sourceMappingURL=index-browser.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-browser.es.js","sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable complexity */\nimport { Level } from 'nightingale-levels';\n\nconst specialRegexpChars = /[$()+.?[\\\\\\]^{|}]/;\n\ntype TestFunction = (string: string) => boolean;\nexport type DebugValueType = RegExp | string[] | string;\n\nconst createTestFunctionFromRegexp =\n (regexp: RegExp): TestFunction =>\n (string: string) =>\n regexp.test(string);\n\nconst createTestFunctionFromRegexpString = (value: string): TestFunction => {\n if (!value.endsWith('/')) throw new Error('Invalid RegExp DEBUG value');\n return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));\n};\n\nconst createTestFunctionFromValue = (value: string): TestFunction => {\n if (value.endsWith(':*')) {\n value = value.slice(0, -2);\n return (string: string) => string.startsWith(value);\n }\n\n return (string: string) => string === value;\n};\n\nexport type FindDebugLevel = (minLevel: Level, key: string) => Level;\n\nexport function createFindDebugLevel(\n debugValue?: DebugValueType,\n): FindDebugLevel {\n let isWildcard = false;\n const debugValues: TestFunction[] = [];\n const skips: TestFunction[] = [];\n\n if (!Array.isArray(debugValue)) {\n if (debugValue instanceof RegExp) {\n debugValues.push(createTestFunctionFromRegexp(debugValue));\n debugValue = undefined;\n } else if (debugValue) {\n debugValue = debugValue.trim();\n\n if (debugValue.startsWith('/')) {\n debugValues.push(createTestFunctionFromRegexpString(debugValue));\n debugValue = undefined;\n } else {\n debugValue = debugValue.split(/[\\s,]+/);\n }\n }\n }\n\n if (debugValue) {\n (debugValue as string[]).forEach((value) => {\n if (specialRegexpChars.test(value)) {\n throw new Error(\n `Invalid debug value: \"${value}\" (contains special chars)`,\n );\n }\n\n if (!value) return;\n\n if (value === '*') {\n isWildcard = true;\n return;\n }\n\n if (value.startsWith('-')) {\n skips.push(createTestFunctionFromValue(value.slice(1)));\n } else if (!isWildcard) {\n debugValues.push(createTestFunctionFromValue(value));\n }\n });\n }\n\n if (isWildcard) {\n if (skips.length === 0) {\n return () => Level.ALL;\n } else {\n return (minLevel: Level, key: string) =>\n skips.some((skip) => skip(key)) ? minLevel : Level.ALL;\n }\n }\n\n if (debugValues.length === 0) {\n return (minLevel: Level) => minLevel;\n }\n\n return (minLevel: Level, key: string) => {\n if (minLevel === Level.ALL || !key) {\n return minLevel;\n }\n\n if (debugValues.some((dv) => dv(key))) {\n return skips.some((skip) => skip(key)) ? minLevel : Level.ALL;\n }\n\n return minLevel;\n };\n}\n"],"names":["specialRegexpChars","createTestFunctionFromRegexp","regexp","string","test","createTestFunctionFromRegexpString","value","endsWith","Error","RegExp","slice","createTestFunctionFromValue","startsWith","createFindDebugLevel","debugValue","isWildcard","debugValues","skips","Array","isArray","push","undefined","trim","split","forEach","length","Level","ALL","minLevel","key","some","skip","dv"],"mappings":";;AAAA;AAGA,IAAMA,kBAAkB,GAAG,mBAAmB,CAAA;AAK9C,IAAMC,4BAA4B,GAChC,SADIA,4BAA4BA,CAC/BC,MAAc,EAAA;AAAA,EAAA,OACf,UAACC,MAAc,EAAA;AAAA,IAAA,OACbD,MAAM,CAACE,IAAI,CAACD,MAAM,CAAC,CAAA;AAAA,GAAA,CAAA;AAAA,CAAA,CAAA;AAEvB,IAAME,kCAAkC,GAAG,SAArCA,kCAAkCA,CAAIC,KAAa,EAAmB;AAC1E,EAAA,IAAI,CAACA,KAAK,CAACC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAIC,KAAK,CAAC,4BAA4B,CAAC,CAAA;AACvE,EAAA,OAAOP,4BAA4B,CAAC,IAAIQ,MAAM,CAACH,KAAK,CAACI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACrE,CAAC,CAAA;AAED,IAAMC,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAAIL,KAAa,EAAmB;AACnE,EAAA,IAAIA,KA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A,QAAe,EAAEC,GAAW,EAAK;IACvC,IAAID,QAAQ,KAAKF,KAAK,CAACC,GAAG,IAAI,CAACE,GAAG,EAAE;AAClC,MAAA,OAAOD,QAAQ,CAAA;AACjB,KAAA;AAEA,IAAA,IAAIZ,WAAW,CAACc,IAAI,CAAC,UAACE,EAAE,EAAA;MAAA,OAAKA,EAAE,CAACH,GAAG,CAAC,CAAA;AAAA,KAAA,CAAC,EAAE;AACrC,MAAA,OAAOZ,KAAK,CAACa,IAAI,CAAC,UAACC,IAAI,EAAA;QAAA,OAAKA,IAAI,CAACF,GAAG,CAAC,CAAA;AAAA,OAAA,CAAC,GAAGD,QAAQ,GAAGF,KAAK,CAACC,GAAG,CAAA;AAC/D,KAAA;AAEA,IAAA,OAAOC,QAAQ,CAAA;GAChB,CAAA;AACH;;;;"}
@@ -1,74 +0,0 @@
1
- import { Level } from 'nightingale-levels';
2
-
3
- /* eslint-disable complexity */
4
- const specialRegexpChars = /[$()+.?[\\\]^{|}]/;
5
- const createTestFunctionFromRegexp = regexp => string => regexp.test(string);
6
- const createTestFunctionFromRegexpString = value => {
7
- if (!value.endsWith('/')) throw new Error('Invalid RegExp DEBUG value');
8
- return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));
9
- };
10
- const createTestFunctionFromValue = value => {
11
- if (value.endsWith(':*')) {
12
- value = value.slice(0, -2);
13
- return string => string.startsWith(value);
14
- }
15
- return string => string === value;
16
- };
17
- function createFindDebugLevel(debugValue) {
18
- let isWildcard = false;
19
- const debugValues = [];
20
- const skips = [];
21
- if (!Array.isArray(debugValue)) {
22
- if (debugValue instanceof RegExp) {
23
- debugValues.push(createTestFunctionFromRegexp(debugValue));
24
- debugValue = undefined;
25
- } else if (debugValue) {
26
- debugValue = debugValue.trim();
27
- if (debugValue.startsWith('/')) {
28
- debugValues.push(createTestFunctionFromRegexpString(debugValue));
29
- debugValue = undefined;
30
- } else {
31
- debugValue = debugValue.split(/[\s,]+/);
32
- }
33
- }
34
- }
35
- if (debugValue) {
36
- debugValue.forEach(value => {
37
- if (specialRegexpChars.test(value)) {
38
- throw new Error(`Invalid debug value: "${value}" (contains special chars)`);
39
- }
40
- if (!value) return;
41
- if (value === '*') {
42
- isWildcard = true;
43
- return;
44
- }
45
- if (value.startsWith('-')) {
46
- skips.push(createTestFunctionFromValue(value.slice(1)));
47
- } else if (!isWildcard) {
48
- debugValues.push(createTestFunctionFromValue(value));
49
- }
50
- });
51
- }
52
- if (isWildcard) {
53
- if (skips.length === 0) {
54
- return () => Level.ALL;
55
- } else {
56
- return (minLevel, key) => skips.some(skip => skip(key)) ? minLevel : Level.ALL;
57
- }
58
- }
59
- if (debugValues.length === 0) {
60
- return minLevel => minLevel;
61
- }
62
- return (minLevel, key) => {
63
- if (minLevel === Level.ALL || !key) {
64
- return minLevel;
65
- }
66
- if (debugValues.some(dv => dv(key))) {
67
- return skips.some(skip => skip(key)) ? minLevel : Level.ALL;
68
- }
69
- return minLevel;
70
- };
71
- }
72
-
73
- export { createFindDebugLevel };
74
- //# sourceMappingURL=index-browsermodern.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-browsermodern.es.js","sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable complexity */\nimport { Level } from 'nightingale-levels';\n\nconst specialRegexpChars = /[$()+.?[\\\\\\]^{|}]/;\n\ntype TestFunction = (string: string) => boolean;\nexport type DebugValueType = RegExp | string[] | string;\n\nconst createTestFunctionFromRegexp =\n (regexp: RegExp): TestFunction =>\n (string: string) =>\n regexp.test(string);\n\nconst createTestFunctionFromRegexpString = (value: string): TestFunction => {\n if (!value.endsWith('/')) throw new Error('Invalid RegExp DEBUG value');\n return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));\n};\n\nconst createTestFunctionFromValue = (value: string): TestFunction => {\n if (value.endsWith(':*')) {\n value = value.slice(0, -2);\n return (string: string) => string.startsWith(value);\n }\n\n return (string: string) => string === value;\n};\n\nexport type FindDebugLevel = (minLevel: Level, key: string) => Level;\n\nexport function createFindDebugLevel(\n debugValue?: DebugValueType,\n): FindDebugLevel {\n let isWildcard = false;\n const debugValues: TestFunction[] = [];\n const skips: TestFunction[] = [];\n\n if (!Array.isArray(debugValue)) {\n if (debugValue instanceof RegExp) {\n debugValues.push(createTestFunctionFromRegexp(debugValue));\n debugValue = undefined;\n } else if (debugValue) {\n debugValue = debugValue.trim();\n\n if (debugValue.startsWith('/')) {\n debugValues.push(createTestFunctionFromRegexpString(debugValue));\n debugValue = undefined;\n } else {\n debugValue = debugValue.split(/[\\s,]+/);\n }\n }\n }\n\n if (debugValue) {\n (debugValue as string[]).forEach((value) => {\n if (specialRegexpChars.test(value)) {\n throw new Error(\n `Invalid debug value: \"${value}\" (contains special chars)`,\n );\n }\n\n if (!value) return;\n\n if (value === '*') {\n isWildcard = true;\n return;\n }\n\n if (value.startsWith('-')) {\n skips.push(createTestFunctionFromValue(value.slice(1)));\n } else if (!isWildcard) {\n debugValues.push(createTestFunctionFromValue(value));\n }\n });\n }\n\n if (isWildcard) {\n if (skips.length === 0) {\n return () => Level.ALL;\n } else {\n return (minLevel: Level, key: string) =>\n skips.some((skip) => skip(key)) ? minLevel : Level.ALL;\n }\n }\n\n if (debugValues.length === 0) {\n return (minLevel: Level) => minLevel;\n }\n\n return (minLevel: Level, key: string) => {\n if (minLevel === Level.ALL || !key) {\n return minLevel;\n }\n\n if (debugValues.some((dv) => dv(key))) {\n return skips.some((skip) => skip(key)) ? minLevel : Level.ALL;\n }\n\n return minLevel;\n };\n}\n"],"names":["specialRegexpChars","createTestFunctionFromRegexp","regexp","string","test","createTestFunctionFromRegexpString","value","endsWith","Error","RegExp","slice","createTestFunctionFromValue","startsWith","createFindDebugLevel","debugValue","isWildcard","debugValues","skips","Array","isArray","push","undefined","trim","split","forEach","length","Level","ALL","minLevel","key","some","skip","dv"],"mappings":";;AAAA;AAGA,MAAMA,kBAAkB,GAAG,mBAAmB,CAAA;AAK9C,MAAMC,4BAA4B,GAC/BC,MAAc,IACdC,MAA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QAAQ,GAAGF,KAAK,CAACC,GAAG,CAAA;AAC1D,KAAA;AACF,GAAA;AAEA,EAAA,IAAIX,WAAW,CAACS,MAAM,KAAK,CAAC,EAAE;IAC5B,OAAQG,QAAe,IAAKA,QAAQ,CAAA;AACtC,GAAA;AAEA,EAAA,OAAO,CAACA,QAAe,EAAEC,GAAW,KAAK;IACvC,IAAID,QAAQ,KAAKF,KAAK,CAACC,GAAG,IAAI,CAACE,GAAG,EAAE;AAClC,MAAA,OAAOD,QAAQ,CAAA;AACjB,KAAA;IAEA,IAAIZ,WAAW,CAACc,IAAI,CAAEE,EAAE,IAAKA,EAAE,CAACH,GAAG,CAAC,CAAC,EAAE;AACrC,MAAA,OAAOZ,KAAK,CAACa,IAAI,CAAEC,IAAI,IAAKA,IAAI,CAACF,GAAG,CAAC,CAAC,GAAGD,QAAQ,GAAGF,KAAK,CAACC,GAAG,CAAA;AAC/D,KAAA;AAEA,IAAA,OAAOC,QAAQ,CAAA;GAChB,CAAA;AACH;;;;"}
@@ -1,74 +0,0 @@
1
- import { Level } from 'nightingale-levels';
2
-
3
- /* eslint-disable complexity */
4
- const specialRegexpChars = /[$()+.?[\\\]^{|}]/;
5
- const createTestFunctionFromRegexp = regexp => string => regexp.test(string);
6
- const createTestFunctionFromRegexpString = value => {
7
- if (!value.endsWith('/')) throw new Error('Invalid RegExp DEBUG value');
8
- return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));
9
- };
10
- const createTestFunctionFromValue = value => {
11
- if (value.endsWith(':*')) {
12
- value = value.slice(0, -2);
13
- return string => string.startsWith(value);
14
- }
15
- return string => string === value;
16
- };
17
- function createFindDebugLevel(debugValue) {
18
- let isWildcard = false;
19
- const debugValues = [];
20
- const skips = [];
21
- if (!Array.isArray(debugValue)) {
22
- if (debugValue instanceof RegExp) {
23
- debugValues.push(createTestFunctionFromRegexp(debugValue));
24
- debugValue = undefined;
25
- } else if (debugValue) {
26
- debugValue = debugValue.trim();
27
- if (debugValue.startsWith('/')) {
28
- debugValues.push(createTestFunctionFromRegexpString(debugValue));
29
- debugValue = undefined;
30
- } else {
31
- debugValue = debugValue.split(/[\s,]+/);
32
- }
33
- }
34
- }
35
- if (debugValue) {
36
- debugValue.forEach(value => {
37
- if (specialRegexpChars.test(value)) {
38
- throw new Error(`Invalid debug value: "${value}" (contains special chars)`);
39
- }
40
- if (!value) return;
41
- if (value === '*') {
42
- isWildcard = true;
43
- return;
44
- }
45
- if (value.startsWith('-')) {
46
- skips.push(createTestFunctionFromValue(value.slice(1)));
47
- } else if (!isWildcard) {
48
- debugValues.push(createTestFunctionFromValue(value));
49
- }
50
- });
51
- }
52
- if (isWildcard) {
53
- if (skips.length === 0) {
54
- return () => Level.ALL;
55
- } else {
56
- return (minLevel, key) => skips.some(skip => skip(key)) ? minLevel : Level.ALL;
57
- }
58
- }
59
- if (debugValues.length === 0) {
60
- return minLevel => minLevel;
61
- }
62
- return (minLevel, key) => {
63
- if (minLevel === Level.ALL || !key) {
64
- return minLevel;
65
- }
66
- if (debugValues.some(dv => dv(key))) {
67
- return skips.some(skip => skip(key)) ? minLevel : Level.ALL;
68
- }
69
- return minLevel;
70
- };
71
- }
72
-
73
- export { createFindDebugLevel };
74
- //# sourceMappingURL=index-node18.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-node18.mjs","sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable complexity */\nimport { Level } from 'nightingale-levels';\n\nconst specialRegexpChars = /[$()+.?[\\\\\\]^{|}]/;\n\ntype TestFunction = (string: string) => boolean;\nexport type DebugValueType = RegExp | string[] | string;\n\nconst createTestFunctionFromRegexp =\n (regexp: RegExp): TestFunction =>\n (string: string) =>\n regexp.test(string);\n\nconst createTestFunctionFromRegexpString = (value: string): TestFunction => {\n if (!value.endsWith('/')) throw new Error('Invalid RegExp DEBUG value');\n return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));\n};\n\nconst createTestFunctionFromValue = (value: string): TestFunction => {\n if (value.endsWith(':*')) {\n value = value.slice(0, -2);\n return (string: string) => string.startsWith(value);\n }\n\n return (string: string) => string === value;\n};\n\nexport type FindDebugLevel = (minLevel: Level, key: string) => Level;\n\nexport function createFindDebugLevel(\n debugValue?: DebugValueType,\n): FindDebugLevel {\n let isWildcard = false;\n const debugValues: TestFunction[] = [];\n const skips: TestFunction[] = [];\n\n if (!Array.isArray(debugValue)) {\n if (debugValue instanceof RegExp) {\n debugValues.push(createTestFunctionFromRegexp(debugValue));\n debugValue = undefined;\n } else if (debugValue) {\n debugValue = debugValue.trim();\n\n if (debugValue.startsWith('/')) {\n debugValues.push(createTestFunctionFromRegexpString(debugValue));\n debugValue = undefined;\n } else {\n debugValue = debugValue.split(/[\\s,]+/);\n }\n }\n }\n\n if (debugValue) {\n (debugValue as string[]).forEach((value) => {\n if (specialRegexpChars.test(value)) {\n throw new Error(\n `Invalid debug value: \"${value}\" (contains special chars)`,\n );\n }\n\n if (!value) return;\n\n if (value === '*') {\n isWildcard = true;\n return;\n }\n\n if (value.startsWith('-')) {\n skips.push(createTestFunctionFromValue(value.slice(1)));\n } else if (!isWildcard) {\n debugValues.push(createTestFunctionFromValue(value));\n }\n });\n }\n\n if (isWildcard) {\n if (skips.length === 0) {\n return () => Level.ALL;\n } else {\n return (minLevel: Level, key: string) =>\n skips.some((skip) => skip(key)) ? minLevel : Level.ALL;\n }\n }\n\n if (debugValues.length === 0) {\n return (minLevel: Level) => minLevel;\n }\n\n return (minLevel: Level, key: string) => {\n if (minLevel === Level.ALL || !key) {\n return minLevel;\n }\n\n if (debugValues.some((dv) => dv(key))) {\n return skips.some((skip) => skip(key)) ? minLevel : Level.ALL;\n }\n\n return minLevel;\n };\n}\n"],"names":["specialRegexpChars","createTestFunctionFromRegexp","regexp","string","test","createTestFunctionFromRegexpString","value","endsWith","Error","RegExp","slice","createTestFunctionFromValue","startsWith","createFindDebugLevel","debugValue","isWildcard","debugValues","skips","Array","isArray","push","undefined","trim","split","forEach","length","Level","ALL","minLevel","key","some","skip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CAACC,QAAe,EAAEC,GAAW,KAClCZ,KAAK,CAACa,IAAI,CAAEC,IAAI,IAAKA,IAAI,CAACF,GAAG,CAAC,CAAC,GAAGD,QAAQ,GAAGF,KAAK,CAACC,GAAG,CAAA;AAC1D,KAAA;AACF,GAAA;AAEA,EAAA,IAAIX,WAAW,CAACS,MAAM,KAAK,CAAC,EAAE;IAC5B,OAAQG,QAAe,IAAKA,QAAQ,CAAA;AACtC,GAAA;AAEA,EAAA,OAAO,CAACA,QAAe,EAAEC,GAAW,KAAK;IACvC,IAAID,QAAQ,KAAKF,KAAK,CAACC,GAAG,IAAI,CAACE,GAAG,EAAE;AAClC,MAAA,OAAOD,QAAQ,CAAA;AACjB,KAAA;IAEA,IAAIZ,WAAW,CAACc,IAAI,CAAEE,EAAE,IAAKA,EAAE,CAACH,GAAG,CAAC,CAAC,EAAE;AACrC,MAAA,OAAOZ,KAAK,CAACa,IAAI,CAAEC,IAAI,IAAKA,IAAI,CAACF,GAAG,CAAC,CAAC,GAAGD,QAAQ,GAAGF,KAAK,CAACC,GAAG,CAAA;AAC/D,KAAA;AAEA,IAAA,OAAOC,QAAQ,CAAA;GAChB,CAAA;AACH;;;;"}
@@ -1,27 +0,0 @@
1
- {
2
- "root": true,
3
- "parser": "@typescript-eslint/parser",
4
- "parserOptions": {
5
- "project": "packages/nightingale-debug/tsconfig.json"
6
- },
7
- "plugins": ["@typescript-eslint"],
8
- "extends": ["@pob/eslint-config-typescript"],
9
- "ignorePatterns": ["*.d.ts"],
10
- "overrides": [
11
- {
12
- "files": ["**/*.test.ts", "__tests__/**/*.ts"],
13
- "extends": ["@pob/eslint-config-typescript/test"],
14
- "env": {
15
- "jest": true
16
- },
17
- "rules": {
18
- "import/no-extraneous-dependencies": [
19
- "error",
20
- {
21
- "devDependencies": true
22
- }
23
- ]
24
- }
25
- }
26
- ]
27
- }
package/src/index.test.ts DELETED
@@ -1,50 +0,0 @@
1
- import { Level } from 'nightingale-levels';
2
- import { createFindDebugLevel } from '.';
3
-
4
- describe('created with undefined', () => {
5
- const findDebugLevel = createFindDebugLevel();
6
- test('should always return level passed', () => {
7
- expect(findDebugLevel(Level.ALL, 'app')).toBe(Level.ALL);
8
- expect(findDebugLevel(Level.TRACE, 'app')).toBe(Level.TRACE);
9
- expect(findDebugLevel(Level.INFO, 'app')).toBe(Level.INFO);
10
- expect(findDebugLevel(Level.WARN, 'app')).toBe(Level.WARN);
11
- expect(findDebugLevel(Level.FATAL, 'app')).toBe(Level.FATAL);
12
- });
13
- });
14
-
15
- describe('created with *', () => {
16
- const findDebugLevel = createFindDebugLevel('*');
17
- test('should always return level ALL', () => {
18
- expect(findDebugLevel(Level.ALL, 'app')).toBe(Level.ALL);
19
- expect(findDebugLevel(Level.TRACE, 'app')).toBe(Level.ALL);
20
- expect(findDebugLevel(Level.INFO, 'app')).toBe(Level.ALL);
21
- expect(findDebugLevel(Level.WARN, 'app')).toBe(Level.ALL);
22
- expect(findDebugLevel(Level.FATAL, 'app')).toBe(Level.ALL);
23
- });
24
- });
25
-
26
- describe('created with *,-app:*', () => {
27
- const findDebugLevel = createFindDebugLevel('*,-app:*');
28
- test('app: should always return level passed', () => {
29
- expect(findDebugLevel(Level.ALL, 'app')).toBe(Level.ALL);
30
- expect(findDebugLevel(Level.INFO, 'app')).toBe(Level.INFO);
31
- });
32
-
33
- test('not app: should always return level ALL', () => {
34
- expect(findDebugLevel(Level.ALL, 'nightingale')).toBe(Level.ALL);
35
- expect(findDebugLevel(Level.INFO, 'nightingale')).toBe(Level.ALL);
36
- });
37
- });
38
-
39
- describe('created with nightingale,-nightingale:debug', () => {
40
- const findDebugLevel = createFindDebugLevel('nightingale,-nightingale:debug');
41
- test('nightingale:debug: should always return level passed', () => {
42
- expect(findDebugLevel(Level.ALL, 'nightingale:debug')).toBe(Level.ALL);
43
- expect(findDebugLevel(Level.INFO, 'nightingale:debug')).toBe(Level.INFO);
44
- });
45
-
46
- test('nightingale: should always return level ALL', () => {
47
- expect(findDebugLevel(Level.ALL, 'nightingale')).toBe(Level.ALL);
48
- expect(findDebugLevel(Level.INFO, 'nightingale')).toBe(Level.ALL);
49
- });
50
- });
package/src/index.ts DELETED
@@ -1,100 +0,0 @@
1
- /* eslint-disable complexity */
2
- import { Level } from 'nightingale-levels';
3
-
4
- const specialRegexpChars = /[$()+.?[\\\]^{|}]/;
5
-
6
- type TestFunction = (string: string) => boolean;
7
- export type DebugValueType = RegExp | string[] | string;
8
-
9
- const createTestFunctionFromRegexp =
10
- (regexp: RegExp): TestFunction =>
11
- (string: string) =>
12
- regexp.test(string);
13
-
14
- const createTestFunctionFromRegexpString = (value: string): TestFunction => {
15
- if (!value.endsWith('/')) throw new Error('Invalid RegExp DEBUG value');
16
- return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));
17
- };
18
-
19
- const createTestFunctionFromValue = (value: string): TestFunction => {
20
- if (value.endsWith(':*')) {
21
- value = value.slice(0, -2);
22
- return (string: string) => string.startsWith(value);
23
- }
24
-
25
- return (string: string) => string === value;
26
- };
27
-
28
- export type FindDebugLevel = (minLevel: Level, key: string) => Level;
29
-
30
- export function createFindDebugLevel(
31
- debugValue?: DebugValueType,
32
- ): FindDebugLevel {
33
- let isWildcard = false;
34
- const debugValues: TestFunction[] = [];
35
- const skips: TestFunction[] = [];
36
-
37
- if (!Array.isArray(debugValue)) {
38
- if (debugValue instanceof RegExp) {
39
- debugValues.push(createTestFunctionFromRegexp(debugValue));
40
- debugValue = undefined;
41
- } else if (debugValue) {
42
- debugValue = debugValue.trim();
43
-
44
- if (debugValue.startsWith('/')) {
45
- debugValues.push(createTestFunctionFromRegexpString(debugValue));
46
- debugValue = undefined;
47
- } else {
48
- debugValue = debugValue.split(/[\s,]+/);
49
- }
50
- }
51
- }
52
-
53
- if (debugValue) {
54
- (debugValue as string[]).forEach((value) => {
55
- if (specialRegexpChars.test(value)) {
56
- throw new Error(
57
- `Invalid debug value: "${value}" (contains special chars)`,
58
- );
59
- }
60
-
61
- if (!value) return;
62
-
63
- if (value === '*') {
64
- isWildcard = true;
65
- return;
66
- }
67
-
68
- if (value.startsWith('-')) {
69
- skips.push(createTestFunctionFromValue(value.slice(1)));
70
- } else if (!isWildcard) {
71
- debugValues.push(createTestFunctionFromValue(value));
72
- }
73
- });
74
- }
75
-
76
- if (isWildcard) {
77
- if (skips.length === 0) {
78
- return () => Level.ALL;
79
- } else {
80
- return (minLevel: Level, key: string) =>
81
- skips.some((skip) => skip(key)) ? minLevel : Level.ALL;
82
- }
83
- }
84
-
85
- if (debugValues.length === 0) {
86
- return (minLevel: Level) => minLevel;
87
- }
88
-
89
- return (minLevel: Level, key: string) => {
90
- if (minLevel === Level.ALL || !key) {
91
- return minLevel;
92
- }
93
-
94
- if (debugValues.some((dv) => dv(key))) {
95
- return skips.some((skip) => skip(key)) ? minLevel : Level.ALL;
96
- }
97
-
98
- return minLevel;
99
- };
100
- }