nightingale-browser-console 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,36 @@
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
+ Version bump for dependency: nightingale
17
+
18
+
19
+ ## [15.0.0](https://github.com/christophehurpeau/nightingale/compare/v14.2.1...v15.0.0) (2023-12-25)
20
+
21
+
22
+ ### ⚠ BREAKING CHANGES
23
+
24
+ * update babel and drop browser modern version
25
+
26
+ ### Features
27
+
28
+ * update babel and drop browser modern version ([5c76abc](https://github.com/christophehurpeau/nightingale/commit/5c76abc8bfb595a617fc4c8b795dae7e674ea664))
29
+
30
+ Version bump for dependency: nightingale-browser-console-formatter
31
+ Version bump for dependency: nightingale-console-output
32
+ Version bump for dependency: nightingale-debug
33
+ Version bump for dependency: nightingale-types
34
+
35
+
6
36
  ## [14.2.1](https://github.com/christophehurpeau/nightingale/compare/v14.2.0...v14.2.1) (2023-11-05)
7
37
 
8
38
  Note: no notable changes
package/README.md CHANGED
@@ -1,82 +1,28 @@
1
- <h3 align="center">
1
+ <h1 align="center">
2
2
  nightingale-browser-console
3
- </h3>
3
+ </h1>
4
4
 
5
5
  <p align="center">
6
- Browser console handler for nightingale
6
+ Deprecated: use BrowserConsoleHandler from nightingale
7
7
  </p>
8
8
 
9
9
  <p align="center">
10
- <a href="https://npmjs.org/package/nightingale-browser-console"><img src="https://img.shields.io/npm/v/nightingale-browser-console.svg?style=flat-square"></a>
11
- <a href="https://npmjs.org/package/nightingale-browser-console"><img src="https://img.shields.io/npm/dw/nightingale-browser-console.svg?style=flat-square"></a>
12
- <a href="https://npmjs.org/package/nightingale-browser-console"><img src="https://img.shields.io/node/v/nightingale-browser-console.svg?style=flat-square"></a>
13
- <a href="https://npmjs.org/package/nightingale-browser-console"><img src="https://img.shields.io/npm/types/nightingale-browser-console.svg?style=flat-square"></a>
10
+ <a href="https://npmjs.org/package/nightingale-browser-console"><img src="https://img.shields.io/npm/v/nightingale-browser-console.svg?style=flat-square" alt="npm version"></a>
11
+ <a href="https://npmjs.org/package/nightingale-browser-console"><img src="https://img.shields.io/npm/dw/nightingale-browser-console.svg?style=flat-square" alt="npm downloads"></a>
12
+ <a href="https://npmjs.org/package/nightingale-browser-console"><img src="https://img.shields.io/node/v/nightingale-browser-console.svg?style=flat-square" alt="node version"></a>
13
+ <a href="https://npmjs.org/package/nightingale-browser-console"><img src="https://img.shields.io/npm/types/nightingale-browser-console.svg?style=flat-square" alt="types"></a>
14
14
  </p>
15
15
 
16
16
  ## Install
17
17
 
18
18
  ```sh
19
- npm install --save nightingale-browser-console
19
+ npm install --save nightingale
20
20
  ```
21
21
 
22
22
  ## Usage
23
23
 
24
24
  ```js
25
- import { configure, levels } from 'nightingale';
26
- import { ConsoleHandler } from 'nightingale-browser-console';
25
+ import { configure, levels, BrowserConsoleHandler } from "nightingale";
27
26
 
28
- configure([{ handlers: [new ConsoleHandler(Level.INFO)] }]);
27
+ configure([{ handlers: [new BrowserConsoleHandler(Level.INFO)] }]);
29
28
  ```
30
-
31
- ## Theme
32
-
33
- If you have a dark console theme, you can set this config in your localStorage :
34
-
35
- ```js
36
- localStorage.NIGHTINGALE_THEME = 'dark';
37
- ```
38
-
39
- You can also force this option:
40
-
41
- ```js
42
- import { ConsoleHandler } from 'nightingale-browser-console';
43
-
44
- configure([{ handlers: [new ConsoleHandler(Level.INFO, { theme: 'dark' })] }]);
45
- ```
46
-
47
- ## Debug
48
-
49
- ### with localStorage
50
-
51
- ```js
52
- localStorage.debug = '*'; // debug everything
53
- localStorage.debug = 'app'; // debug for logger with key 'app'
54
- localStorage.debug = 'app,nightingale'; // debug for logger with key 'app' and 'nightingale'
55
- localStorage.debug = '/^app/'; //debug for logger with key starting with 'app'
56
- localStorage.debug = '/^(app|nightingale$)/'; // debug for logger with key starting with 'app' and key 'nightingale'
57
- localStorage.debug = '*,-app'; // debug everything except app
58
- localStorage.debug = '*,-app:*'; // debug everything except app and all its children
59
- ```
60
-
61
- ### with query, in the url
62
-
63
- ```js
64
- ?DEBUG='*'; // debug everything
65
- ?DEBUG=app // debug for logger with key 'app'
66
- ?DEBUG=app,nightingale // debug for logger with key 'app' and 'nightingale'
67
- ?DEBUG=/^app/ // debug for logger with key starting with 'app'
68
- ?DEBUG=/^(app|nightingale$)/ // debug for logger with key starting with 'app' and key 'nightingale'
69
- ?DEBUG=*,-app // debug everything except app
70
- ?DEBUG=*,-app:* // debug everything except app and all its children
71
- ```
72
-
73
- ## Use source maps to display error stack trace
74
-
75
- In production:
76
-
77
- Send your log to an external tool like [sentry](https://sentry.io/). Sentry allows you to send the source maps after building (if you use webpack, you can use `hidden-source-map` to generate `.map` files, send them to sentry, and remove them so they are not accessible).
78
-
79
- In development:
80
-
81
- - Configure your build tool to generate sourcemaps. For webpack: use proper [`devtool` configuration](https://webpack.js.org/configuration/devtool/). For best stack trace, use `source-map` but it's the slowest option.
82
- - Make sure your project uses [source-map-support](https://www.npmjs.com/package/source-map-support) or similar tool. If not, you can install and simply import `source-map-support/register`.
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ export { BrowserConsoleHandler } from "nightingale";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nightingale-browser-console",
3
- "version": "14.2.1",
4
- "description": "Browser console handler for nightingale",
3
+ "version": "16.0.0",
4
+ "description": "Deprecated: use BrowserConsoleHandler from nightingale",
5
5
  "keywords": [
6
6
  "nightingale",
7
7
  "nightingale-handler"
@@ -16,71 +16,30 @@
16
16
  "homepage": "https://github.com/christophehurpeau/nightingale",
17
17
  "type": "module",
18
18
  "engines": {
19
- "node": ">=18.12.0"
19
+ "node": ">=20.9.0"
20
20
  },
21
- "browserslist": {
22
- "production": [
23
- "defaults",
24
- "> 0.2%",
25
- "not ie < 12",
26
- "not safari < 10",
27
- "not ios_saf < 10"
28
- ]
29
- },
30
- "types": "./dist/definitions/index.d.ts",
31
- "module": "./dist/index-browser.es.js",
32
- "browser": "./dist/index-browser.es.js",
21
+ "sideEffects": false,
22
+ "main": "./lib/index.js",
23
+ "types": "./lib/index.d.ts",
33
24
  "exports": {
34
- "./package.json": "./package.json",
35
25
  ".": {
36
- "types": "./dist/definitions/index.d.ts",
37
- "browser": {
38
- "browser:modern": {
39
- "import": "./dist/index-browsermodern.es.js"
40
- },
41
- "import": "./dist/index-browser.es.js"
42
- }
43
- }
26
+ "types": "./lib/index.d.ts",
27
+ "default": "./lib/index.js"
28
+ },
29
+ "./package.json": "./package.json"
44
30
  },
45
- "sideEffects": false,
46
31
  "files": [
47
- "src",
48
- "dist"
32
+ "lib"
49
33
  ],
50
34
  "scripts": {
51
- "build": "yarn clean:build && rollup --config rollup.config.mjs && yarn run build:definitions",
52
- "build:definitions": "tsc -p tsconfig.json",
53
35
  "clean": "yarn clean:build",
54
- "clean:build": "pob-babel-clean-out dist",
55
36
  "lint": "yarn run lint:eslint",
56
- "lint:eslint": "yarn ../.. run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/nightingale-browser-console",
37
+ "lint:eslint": "yarn ../.. run eslint --quiet packages/nightingale-browser-console",
57
38
  "watch": "yarn clean:build && rollup --config rollup.config.mjs --watch"
58
39
  },
40
+ "pob": {},
59
41
  "prettier": "@pob/root/prettier-config",
60
- "pob": {
61
- "babelEnvs": [
62
- {
63
- "target": "browser",
64
- "version": "modern"
65
- },
66
- {
67
- "target": "browser"
68
- }
69
- ],
70
- "entries": [
71
- "index"
72
- ]
73
- },
74
42
  "dependencies": {
75
- "nightingale-browser-console-formatter": "14.2.1",
76
- "nightingale-console-output": "14.2.1",
77
- "nightingale-debug": "14.2.1",
78
- "nightingale-types": "14.2.1"
79
- },
80
- "devDependencies": {
81
- "@babel/core": "7.23.2",
82
- "@babel/preset-env": "7.23.2",
83
- "pob-babel": "36.6.1",
84
- "typescript": "5.2.2"
43
+ "nightingale": "16.0.0"
85
44
  }
86
45
  }
@@ -1,2 +0,0 @@
1
- export declare function getDebugString(): string;
2
- //# sourceMappingURL=debug.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,IAAI,MAAM,CAsBvC"}
@@ -1,13 +0,0 @@
1
- import type { Level, Handle, IsHandling, Handler } from 'nightingale-types';
2
- type Theme = 'dark' | 'light';
3
- export interface BrowserConsoleHandlerOptions {
4
- theme?: Theme;
5
- }
6
- export declare class BrowserConsoleHandler implements Handler {
7
- minLevel: Level;
8
- handle: Handle;
9
- isHandling: IsHandling;
10
- constructor(minLevel: Level, options?: BrowserConsoleHandlerOptions);
11
- }
12
- export {};
13
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,KAAK,EACL,MAAM,EACN,UAAU,EAGV,OAAO,EACR,MAAM,mBAAmB,CAAC;AAO3B,KAAK,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AAmB9B,MAAM,WAAW,4BAA4B;IAC3C,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,qBAAa,qBAAsB,YAAW,OAAO;IACnD,QAAQ,EAAE,KAAK,CAAK;IAEpB,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,UAAU,CAAC;gBAEX,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAE,4BAAiC;CAMxE"}
@@ -1,55 +0,0 @@
1
- import { createBrowserConsoleFormatter } from 'nightingale-browser-console-formatter';
2
- import consoleOutput from 'nightingale-console-output';
3
- import { createFindDebugLevel } from 'nightingale-debug';
4
-
5
- function getDebugString() {
6
- var _document$location;
7
- var querystring = (_document$location = document.location) == null ? void 0 : _document$location.search;
8
- var debugFromLocalStorage = window.localStorage && localStorage.getItem('debug') || '';
9
- if (!querystring) {
10
- return debugFromLocalStorage;
11
- }
12
-
13
- // https://developer.mozilla.org/en-US/docs/Web/API/URLUtils/search#Get_the_value_of_a_single_search_param
14
- var debugFromQueryString = decodeURI(querystring.replace(
15
- // eslint-disable-next-line prefer-regex-literals
16
- new RegExp('^(?:.*[&\\?]DEBUG(?:\\=([^&]*))?)?.*$', 'i'), '$1'));
17
- return (debugFromLocalStorage ? debugFromLocalStorage + "," : '') + debugFromQueryString;
18
- }
19
-
20
- // debug string can change any time (localStorage), so we need a new object each time.
21
- var findDebugLevel = function findDebugLevel(minLevel, key) {
22
- return createFindDebugLevel(getDebugString())(minLevel, key);
23
- };
24
- var getDefaultTheme = function getDefaultTheme() {
25
- var configInLocalStorage;
26
- try {
27
- configInLocalStorage = localStorage.getItem('NIGHTINGALE_THEME');
28
- if (configInLocalStorage && configInLocalStorage === 'dark') {
29
- return configInLocalStorage;
30
- }
31
- } catch (_unused) {}
32
- return 'light';
33
- };
34
- var createHandler = function createHandler(theme) {
35
- if (theme === void 0) {
36
- theme = getDefaultTheme();
37
- }
38
- var browserConsoleFormatter = createBrowserConsoleFormatter(theme);
39
- return function (record) {
40
- consoleOutput(browserConsoleFormatter(record), record);
41
- };
42
- };
43
- var BrowserConsoleHandler = function BrowserConsoleHandler(minLevel, options) {
44
- if (options === void 0) {
45
- options = {};
46
- }
47
- this.minLevel = 0;
48
- this.isHandling = function (level, key) {
49
- return level >= findDebugLevel(minLevel, key);
50
- };
51
- this.handle = createHandler(options.theme);
52
- };
53
-
54
- export { BrowserConsoleHandler };
55
- //# sourceMappingURL=index-browser.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-browser.es.js","sources":["../src/debug.ts","../src/index.ts"],"sourcesContent":["export function getDebugString(): string {\n const querystring = document.location?.search;\n const debugFromLocalStorage =\n (window.localStorage && localStorage.getItem('debug')) || '';\n\n if (!querystring) {\n return debugFromLocalStorage;\n }\n\n // https://developer.mozilla.org/en-US/docs/Web/API/URLUtils/search#Get_the_value_of_a_single_search_param\n const debugFromQueryString = decodeURI(\n querystring.replace(\n // eslint-disable-next-line prefer-regex-literals\n new RegExp('^(?:.*[&\\\\?]DEBUG(?:\\\\=([^&]*))?)?.*$', 'i'),\n '$1',\n ),\n );\n\n return (\n (debugFromLocalStorage ? `${debugFromLocalStorage},` : '') +\n debugFromQueryString\n );\n}\n","import { createBrowserConsoleFormatter } from 'nightingale-browser-console-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport { createFindDebugLevel } from 'nightingale-debug';\nimport type {\n Level,\n Handle,\n IsHandling,\n LogRecord,\n Metadata,\n Handler,\n} from 'nightingale-types';\nimport { getDebugString } from './debug';\n\n// debug string can change any time (localStorage), so we need a new object each time.\nconst findDebugLevel = (minLevel: Level, key: string): Level =>\n createFindDebugLevel(getDebugString())(minLevel, key);\n\ntype Theme = 'dark' | 'light';\n\nconst getDefaultTheme = (): Theme => {\n try {\n const configInLocalStorage = localStorage.getItem('NIGHTINGALE_THEME');\n if (configInLocalStorage && configInLocalStorage === 'dark') {\n return configInLocalStorage;\n }\n } catch {}\n return 'light';\n};\n\nconst createHandler = (theme: Theme = getDefaultTheme()): Handle => {\n const browserConsoleFormatter = createBrowserConsoleFormatter(theme);\n return <T extends Metadata>(record: LogRecord<T>) => {\n consoleOutput(browserConsoleFormatter(record), record);\n };\n};\n\nexport interface BrowserConsoleHandlerOptions {\n theme?: Theme;\n}\n\nexport class BrowserConsoleHandler implements Handler {\n minLevel: Level = 0;\n\n handle: Handle;\n\n isHandling: IsHandling;\n\n constructor(minLevel: Level, options: BrowserConsoleHandlerOptions = {}) {\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n\n this.handle = createHandler(options.theme);\n }\n}\n"],"names":["getDebugString","_document$location","querystring","document","location","search","debugFromLocalStorage","window","localStorage","getItem","debugFromQueryString","decodeURI","replace","RegExp","findDebugLevel","minLevel","key","createFindDebugLevel","getDefaultTheme","configInLocalStorage","_unused","createHandler","theme","browserConsoleFormatter","createBrowserConsoleFormatter","record","consoleOutput","BrowserConsoleHandler","options","isHandling","level","handle"],"mappings":";;;;AAAO,SAASA,cAAcA,GAAW;AAAA,EAAA,IAAAC,kBAAA,CAAA;EACvC,IAAMC,WAAW,GAAAD,CAAAA,kBAAA,GAAGE,QAAQ,CAACC,QAAQ,KAAA,IAAA,GAAA,KAAA,CAAA,GAAjBH,kBAAA,CAAmBI,MAAM,CAAA;AAC7C,EAAA,IAAMC,qBAAqB,GACxBC,MAAM,CAACC,YAAY,IAAIA,YAAY,CAACC,OAAO,CAAC,OAAO,CAAC,IAAK,EAAE,CAAA;EAE9D,IAAI,CAACP,WAAW,EAAE;AAChB,IAAA,OAAOI,qBAAqB,CAAA;AAC9B,GAAA;;AAEA;AACA,EAAA,IAAMI,oBAAoB,GAAGC,SAAS,CACpCT,WAAW,CAACU,OAAO;AACjB;EACA,IAAIC,MAAM,CAAC,uCAAuC,EAAE,GAAG,CAAC,EACxD,IACF,CACF,CAAC,CAAA;AAED,EAAA,OACE,CAACP,qBAAqB,GAAMA,qBAAqB,GAAM,GAAA,GAAA,EAAE,IACzDI,oBAAoB,CAAA;AAExB;;ACTA;AACA,IAAMI,cAAc,GAAG,SAAjBA,cAAcA,CAAIC,QAAe,EAAEC,GAAW,EAAA;EAAA,OAClDC,oBAAoB,CAACjB,cAAc,EAAE,CAAC,CAACe,QAAQ,EAAEC,GAAG,CAAC,CAAA;AAAA,CAAA,CAAA;AAIvD,IAAME,eAAe,GAAG,SAAlBA,eAAeA,GAAgB;AAAA,EAAA,IAE3BC,oBAAgE,CAAA;EADxE,IAAI;AACIA,IAAAA,oBAAoB,GAAGX,YAAY,CAACC,OAAO,CAAC,mBAAmB,CAAC,CAAA;AACtE,IAAA,IAAIU,oBAAoB,IAAIA,oBAAoB,KAAK,MAAM,EAAE;AAC3D,MAAA,OAAOA,oBAAoB,CAAA;AAC7B,KAAA;AACF,GAAC,CAAC,OAAAC,OAAA,EAAM,EAAC;AACT,EAAA,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,IAAMC,aAAa,GAAG,SAAhBA,aAAaA,CAAIC,KAAY,EAAiC;AAAA,EAAA,IAA7CA,KAAY,KAAA,KAAA,CAAA,EAAA;IAAZA,KAAY,GAAGJ,eAAe,EAAE,CAAA;AAAA,GAAA;AACrD,EAAA,IAAMK,uBAAuB,GAAGC,6BAA6B,CAACF,KAAK,CAAC,CAAA;EACpE,OAAO,UAAqBG,MAAoB,EAAK;AACnDC,IAAAA,aAAa,CAACH,uBAAuB,CAACE,MAAM,CAAC,EAAEA,MAAM,CAAC,CAAA;GACvD,CAAA;AACH,CAAC,CAAA;AAMD,IAAaE,qBAAqB,GAOhC,SAAAA,sBAAYZ,QAAe,EAAEa,OAAqC,EAAO;AAAA,EAAA,IAA5CA,OAAqC,KAAA,KAAA,CAAA,EAAA;IAArCA,OAAqC,GAAG,EAAE,CAAA;AAAA,GAAA;EAAA,IANvEb,CAAAA,QAAQ,GAAU,CAAC,CAAA;AAOjB,EAAA,IAAI,CAACc,UAAU,GAAG,UAACC,KAAY,EAAEd,GAAW,EAAA;AAAA,IAAA,OAC1Cc,KAAK,IAAIhB,cAAc,CAACC,QAAQ,EAAEC,GAAG,CAAC,CAAA;AAAA,GAAA,CAAA;EAExC,IAAI,CAACe,MAAM,GAAGV,aAAa,CAACO,OAAO,CAACN,KAAK,CAAC,CAAA;AAC5C;;;;"}
@@ -1,45 +0,0 @@
1
- import { createBrowserConsoleFormatter } from 'nightingale-browser-console-formatter';
2
- import consoleOutput from 'nightingale-console-output';
3
- import { createFindDebugLevel } from 'nightingale-debug';
4
-
5
- function getDebugString() {
6
- const querystring = document.location?.search;
7
- const debugFromLocalStorage = window.localStorage && localStorage.getItem('debug') || '';
8
- if (!querystring) {
9
- return debugFromLocalStorage;
10
- }
11
-
12
- // https://developer.mozilla.org/en-US/docs/Web/API/URLUtils/search#Get_the_value_of_a_single_search_param
13
- const debugFromQueryString = decodeURI(querystring.replace(
14
- // eslint-disable-next-line prefer-regex-literals
15
- new RegExp('^(?:.*[&\\?]DEBUG(?:\\=([^&]*))?)?.*$', 'i'), '$1'));
16
- return (debugFromLocalStorage ? `${debugFromLocalStorage},` : '') + debugFromQueryString;
17
- }
18
-
19
- // debug string can change any time (localStorage), so we need a new object each time.
20
- const findDebugLevel = (minLevel, key) => createFindDebugLevel(getDebugString())(minLevel, key);
21
- const getDefaultTheme = () => {
22
- try {
23
- const configInLocalStorage = localStorage.getItem('NIGHTINGALE_THEME');
24
- if (configInLocalStorage && configInLocalStorage === 'dark') {
25
- return configInLocalStorage;
26
- }
27
- } catch {}
28
- return 'light';
29
- };
30
- const createHandler = (theme = getDefaultTheme()) => {
31
- const browserConsoleFormatter = createBrowserConsoleFormatter(theme);
32
- return record => {
33
- consoleOutput(browserConsoleFormatter(record), record);
34
- };
35
- };
36
- class BrowserConsoleHandler {
37
- minLevel = 0;
38
- constructor(minLevel, options = {}) {
39
- this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key);
40
- this.handle = createHandler(options.theme);
41
- }
42
- }
43
-
44
- export { BrowserConsoleHandler };
45
- //# sourceMappingURL=index-browsermodern.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-browsermodern.es.js","sources":["../src/debug.ts","../src/index.ts"],"sourcesContent":["export function getDebugString(): string {\n const querystring = document.location?.search;\n const debugFromLocalStorage =\n (window.localStorage && localStorage.getItem('debug')) || '';\n\n if (!querystring) {\n return debugFromLocalStorage;\n }\n\n // https://developer.mozilla.org/en-US/docs/Web/API/URLUtils/search#Get_the_value_of_a_single_search_param\n const debugFromQueryString = decodeURI(\n querystring.replace(\n // eslint-disable-next-line prefer-regex-literals\n new RegExp('^(?:.*[&\\\\?]DEBUG(?:\\\\=([^&]*))?)?.*$', 'i'),\n '$1',\n ),\n );\n\n return (\n (debugFromLocalStorage ? `${debugFromLocalStorage},` : '') +\n debugFromQueryString\n );\n}\n","import { createBrowserConsoleFormatter } from 'nightingale-browser-console-formatter';\nimport consoleOutput from 'nightingale-console-output';\nimport { createFindDebugLevel } from 'nightingale-debug';\nimport type {\n Level,\n Handle,\n IsHandling,\n LogRecord,\n Metadata,\n Handler,\n} from 'nightingale-types';\nimport { getDebugString } from './debug';\n\n// debug string can change any time (localStorage), so we need a new object each time.\nconst findDebugLevel = (minLevel: Level, key: string): Level =>\n createFindDebugLevel(getDebugString())(minLevel, key);\n\ntype Theme = 'dark' | 'light';\n\nconst getDefaultTheme = (): Theme => {\n try {\n const configInLocalStorage = localStorage.getItem('NIGHTINGALE_THEME');\n if (configInLocalStorage && configInLocalStorage === 'dark') {\n return configInLocalStorage;\n }\n } catch {}\n return 'light';\n};\n\nconst createHandler = (theme: Theme = getDefaultTheme()): Handle => {\n const browserConsoleFormatter = createBrowserConsoleFormatter(theme);\n return <T extends Metadata>(record: LogRecord<T>) => {\n consoleOutput(browserConsoleFormatter(record), record);\n };\n};\n\nexport interface BrowserConsoleHandlerOptions {\n theme?: Theme;\n}\n\nexport class BrowserConsoleHandler implements Handler {\n minLevel: Level = 0;\n\n handle: Handle;\n\n isHandling: IsHandling;\n\n constructor(minLevel: Level, options: BrowserConsoleHandlerOptions = {}) {\n this.isHandling = (level: Level, key: string) =>\n level >= findDebugLevel(minLevel, key);\n\n this.handle = createHandler(options.theme);\n }\n}\n"],"names":["getDebugString","querystring","document","location","search","debugFromLocalStorage","window","localStorage","getItem","debugFromQueryString","decodeURI","replace","RegExp","findDebugLevel","minLevel","key","createFindDebugLevel","getDefaultTheme","configInLocalStorage","createHandler","theme","browserConsoleFormatter","createBrowserConsoleFormatter","record","consoleOutput","BrowserConsoleHandler","constructor","options","isHandling","level","handle"],"mappings":";;;;AAAO,SAASA,cAAcA,GAAW;AACvC,EAAA,MAAMC,WAAW,GAAGC,QAAQ,CAACC,QAAQ,EAAEC,MAAM,CAAA;AAC7C,EAAA,MAAMC,qBAAqB,GACxBC,MAAM,CAACC,YAAY,IAAIA,YAAY,CAACC,OAAO,CAAC,OAAO,CAAC,IAAK,EAAE,CAAA;EAE9D,IAAI,CAACP,WAAW,EAAE;AAChB,IAAA,OAAOI,qBAAqB,CAAA;AAC9B,GAAA;;AAEA;AACA,EAAA,MAAMI,oBAAoB,GAAGC,SAAS,CACpCT,WAAW,CAACU,OAAO;AACjB;EACA,IAAIC,MAAM,CAAC,uCAAuC,EAAE,GAAG,CAAC,EACxD,IACF,CACF,CAAC,CAAA;EAED,OACE,CAACP,qBAAqB,GAAI,CAAA,EAAEA,qBAAsB,CAAE,CAAA,CAAA,GAAG,EAAE,IACzDI,oBAAoB,CAAA;AAExB;;ACTA;AACA,MAAMI,cAAc,GAAGA,CAACC,QAAe,EAAEC,GAAW,KAClDC,oBAAoB,CAAChB,cAAc,EAAE,CAAC,CAACc,QAAQ,EAAEC,GAAG,CAAC,CAAA;AAIvD,MAAME,eAAe,GAAGA,MAAa;EACnC,IAAI;AACF,IAAA,MAAMC,oBAAoB,GAAGX,YAAY,CAACC,OAAO,CAAC,mBAAmB,CAAC,CAAA;AACtE,IAAA,IAAIU,oBAAoB,IAAIA,oBAAoB,KAAK,MAAM,EAAE;AAC3D,MAAA,OAAOA,oBAAoB,CAAA;AAC7B,KAAA;GACD,CAAC,MAAM,EAAC;AACT,EAAA,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAMC,aAAa,GAAGA,CAACC,KAAY,GAAGH,eAAe,EAAE,KAAa;AAClE,EAAA,MAAMI,uBAAuB,GAAGC,6BAA6B,CAACF,KAAK,CAAC,CAAA;AACpE,EAAA,OAA4BG,MAAoB,IAAK;AACnDC,IAAAA,aAAa,CAACH,uBAAuB,CAACE,MAAM,CAAC,EAAEA,MAAM,CAAC,CAAA;GACvD,CAAA;AACH,CAAC,CAAA;AAMM,MAAME,qBAAqB,CAAoB;AACpDX,EAAAA,QAAQ,GAAU,CAAC,CAAA;AAMnBY,EAAAA,WAAWA,CAACZ,QAAe,EAAEa,OAAqC,GAAG,EAAE,EAAE;AACvE,IAAA,IAAI,CAACC,UAAU,GAAG,CAACC,KAAY,EAAEd,GAAW,KAC1Cc,KAAK,IAAIhB,cAAc,CAACC,QAAQ,EAAEC,GAAG,CAAC,CAAA;IAExC,IAAI,CAACe,MAAM,GAAGX,aAAa,CAACQ,OAAO,CAACP,KAAK,CAAC,CAAA;AAC5C,GAAA;AACF;;;;"}
@@ -1,27 +0,0 @@
1
- {
2
- "root": true,
3
- "parser": "@typescript-eslint/parser",
4
- "parserOptions": {
5
- "project": "packages/nightingale-browser-console/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/debug.ts DELETED
@@ -1,23 +0,0 @@
1
- export function getDebugString(): string {
2
- const querystring = document.location?.search;
3
- const debugFromLocalStorage =
4
- (window.localStorage && localStorage.getItem('debug')) || '';
5
-
6
- if (!querystring) {
7
- return debugFromLocalStorage;
8
- }
9
-
10
- // https://developer.mozilla.org/en-US/docs/Web/API/URLUtils/search#Get_the_value_of_a_single_search_param
11
- const debugFromQueryString = decodeURI(
12
- querystring.replace(
13
- // eslint-disable-next-line prefer-regex-literals
14
- new RegExp('^(?:.*[&\\?]DEBUG(?:\\=([^&]*))?)?.*$', 'i'),
15
- '$1',
16
- ),
17
- );
18
-
19
- return (
20
- (debugFromLocalStorage ? `${debugFromLocalStorage},` : '') +
21
- debugFromQueryString
22
- );
23
- }
package/src/index.ts DELETED
@@ -1,54 +0,0 @@
1
- import { createBrowserConsoleFormatter } from 'nightingale-browser-console-formatter';
2
- import consoleOutput from 'nightingale-console-output';
3
- import { createFindDebugLevel } from 'nightingale-debug';
4
- import type {
5
- Level,
6
- Handle,
7
- IsHandling,
8
- LogRecord,
9
- Metadata,
10
- Handler,
11
- } from 'nightingale-types';
12
- import { getDebugString } from './debug';
13
-
14
- // debug string can change any time (localStorage), so we need a new object each time.
15
- const findDebugLevel = (minLevel: Level, key: string): Level =>
16
- createFindDebugLevel(getDebugString())(minLevel, key);
17
-
18
- type Theme = 'dark' | 'light';
19
-
20
- const getDefaultTheme = (): Theme => {
21
- try {
22
- const configInLocalStorage = localStorage.getItem('NIGHTINGALE_THEME');
23
- if (configInLocalStorage && configInLocalStorage === 'dark') {
24
- return configInLocalStorage;
25
- }
26
- } catch {}
27
- return 'light';
28
- };
29
-
30
- const createHandler = (theme: Theme = getDefaultTheme()): Handle => {
31
- const browserConsoleFormatter = createBrowserConsoleFormatter(theme);
32
- return <T extends Metadata>(record: LogRecord<T>) => {
33
- consoleOutput(browserConsoleFormatter(record), record);
34
- };
35
- };
36
-
37
- export interface BrowserConsoleHandlerOptions {
38
- theme?: Theme;
39
- }
40
-
41
- export class BrowserConsoleHandler implements Handler {
42
- minLevel: Level = 0;
43
-
44
- handle: Handle;
45
-
46
- isHandling: IsHandling;
47
-
48
- constructor(minLevel: Level, options: BrowserConsoleHandlerOptions = {}) {
49
- this.isHandling = (level: Level, key: string) =>
50
- level >= findDebugLevel(minLevel, key);
51
-
52
- this.handle = createHandler(options.theme);
53
- }
54
- }