analogger 1.1.5 → 1.3.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/.eslintrc.cjs ADDED
@@ -0,0 +1,25 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ node: true
5
+ },
6
+ parser: "@babel/eslint-parser",
7
+ parserOptions: {
8
+ "ecmaVersion": 2020
9
+ },
10
+ rules: {
11
+ "comma-dangle": 0,
12
+ "comma-style": ["error", "last"],
13
+ "no-bitwise": "off",
14
+ "no-console": "off",
15
+ "no-nested-ternary": "off",
16
+ "no-plusplus": "off",
17
+ "prefer-const": "off",
18
+ "spaced-comment": "off",
19
+ "no-debugger": "error",
20
+ "quotes": ["error", "double"],
21
+ "semi": 2,
22
+ "no-unused-vars": "error",
23
+ "max-len": ["error", {code: 200}]
24
+ }
25
+ };
@@ -0,0 +1,10 @@
1
+ name: Version
2
+ description: 'Version builds automatically'
3
+ author: 'thimpat'
4
+ runs:
5
+ using: composite
6
+ steps:
7
+ - name: Welcome
8
+ shell: powershell
9
+ run: |
10
+ echo Welcome
@@ -0,0 +1,24 @@
1
+ name: Versioning AnaLogger
2
+ env:
3
+ ANALOGGER_APP_NAME: "release/analogger"
4
+ on:
5
+ push:
6
+ branches:
7
+ - "**"
8
+ paths-ignore:
9
+ - "**.md"
10
+ - ".vscode/**"
11
+ jobs:
12
+ set-version:
13
+ runs-on: [self-hosted]
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Check out Git repository
17
+ uses: thimpat/analogger/.github/actions/checkout@ci
18
+ - name: Install dependencies
19
+ shell: powershell
20
+ run: npm install
21
+ - name: Test
22
+ shell: powershell
23
+ run: |
24
+ npm test
@@ -0,0 +1,25 @@
1
+ name: Versioning AnaLogger
2
+ env:
3
+ ANALOGGER_APP_NAME: "release/analogger"
4
+ on:
5
+ push:
6
+ branches:
7
+ - main
8
+ - ci
9
+ paths-ignore:
10
+ - "**.md"
11
+ - ".vscode/**"
12
+ jobs:
13
+ set-version:
14
+ runs-on: [self-hosted]
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Check out Git repository
18
+ uses: thimpat/analogger/.github/actions/checkout@ci
19
+ - name: Install dependencies
20
+ shell: powershell
21
+ run: npm install
22
+ - name: Upgrade version
23
+ shell: powershell
24
+ run: |
25
+ npx semantic-release
package/.releaserc ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "branches": ["test", "main", "next"],
3
+ "dryRun": false,
4
+ "ci": true,
5
+ "debug": true,
6
+ "plugins": [
7
+ ["@semantic-release/commit-analyzer",
8
+ {
9
+ "preset": "angular",
10
+ "releaseRules": [
11
+ {"type": "docs", "scope":"README", "release": "patch"},
12
+ {"type": "refactor", "release": "patch"},
13
+ {"type": "style", "release": "patch"}
14
+ ],
15
+ "parserOpts": {
16
+ "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"]
17
+ }
18
+ }],
19
+ "@semantic-release/release-notes-generator",
20
+ "@semantic-release/changelog",
21
+ "@semantic-release/npm",
22
+ ["@semantic-release/git", {
23
+ "assets": ["package.json", "CHANGELOG.md"],
24
+ "message": "AnaLogger Release: ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
25
+ }]
26
+ ]
27
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # [1.3.0](https://github.com/thimpat/analogger/compare/v1.2.0...v1.3.0) (2022-02-08)
package/README.md CHANGED
@@ -87,6 +87,12 @@ Same as above, but for errors (console.error)
87
87
 
88
88
  <br/>
89
89
 
90
+ ### removeOverride() | removeOverrideError()
91
+
92
+ Remove overridden console methods
93
+
94
+ <br/>
95
+
90
96
  ### setContexts()
91
97
 
92
98
  #### Contexts
@@ -97,18 +103,18 @@ A context allows grouping the logs by functionality by assigning them some colou
97
103
  ##### Examples
98
104
 
99
105
  ```javascript
100
- const LOG_CONTEXT = {STANDARD: null, TEST: {color: "#B18904"}, C1: null, C2: null, C3: null, DEFAULT: {}}
106
+ const LOG_CONTEXTS = {STANDARD: null, TEST: {color: "#B18904"}, C1: null, C2: null, C3: null, DEFAULT: {}}
101
107
  const LOG_TARGETS = {ALL: "ALL", DEV1: "TOM", DEV2: "TIM", USER: "USER"};
102
108
 
103
- anaLogger.setContexts(LOG_CONTEXT);
109
+ anaLogger.setContexts(LOG_CONTEXTS);
104
110
 
105
- anaLogger.log(LOG_CONTEXT.C1, `Test Log example C1`);
106
- anaLogger.log(LOG_CONTEXT.C2, `Test Log example C2`);
107
- anaLogger.log(LOG_CONTEXT.C3, `Test Log example C3`);
111
+ anaLogger.log(LOG_CONTEXTS.C1, `Test Log example C1`);
112
+ anaLogger.log(LOG_CONTEXTS.C2, `Test Log example C2`);
113
+ anaLogger.log(LOG_CONTEXTS.C3, `Test Log example C3`);
108
114
  ```
109
115
 
110
- See LOG_CONTEXT.C1 in this example to categorise the functionality we want to monitor.
111
- For instance, LOG_CONTEXT.INVESTIGATING_TIMER_EFFECT could display output related to something that has to
116
+ See LOG_CONTEXTS.C1 in this example to categorise the functionality we want to monitor.
117
+ For instance, LOG_CONTEXTS.INVESTIGATING_TIMER_EFFECT could display output related to something that has to
112
118
  do with a timer.
113
119
 
114
120
  The "Testing log 2" log will not show up in the console or the terminal.
@@ -134,23 +140,19 @@ setActiveTarget() allows hiding logs from other devs or roles.
134
140
  ##### Examples
135
141
 
136
142
  ```javascript
137
- anaLogger.setActiveTarget(LOG_TARGETS.DEV1);
138
- console.log({target: LOG_CONTEXT.DEV1}, `Testing log 1`)
139
- console.log({target: LOG_CONTEXT.DEV2}, `Testing log 2`)
140
- console.log({context: LOG_CONTEXT.DEV3}, `Testing log 3`)
141
- console.log(`Testing log 4`)
142
- ```
143
+ const LOG_CONTEXTS = {STANDARD: null, TEST: {color: "#B18904", symbol: "⏰"}, C1: null, C2: null, C3: null, DEFAULT: {}}
144
+ const LOG_TARGETS = {ALL: "ALL", DEV1: "TOM", DEV2: "TIM", USER: "USER"};
143
145
 
146
+ anaLogger.setContexts(LOG_CONTEXTS);
147
+ anaLogger.setActiveTarget(LOG_TARGETS.DEV1); // <- You are DEV1
144
148
 
145
- ```javascript
146
- const LOG_CONTEXT = {STANDARD: null, TEST: {color: "#B18904", symbol: "⏰"}, C1: null, C2: null, C3: null, DEFAULT: {}}
147
- const LOG_TARGETS = {ALL: "ALL", DEV1: "TOM", DEV2: "TIM", USER: "USER"};
149
+ console.log({target: LOG_TARGETS.DEV1}, `Testing log 1`); // You will see this
150
+ console.log({target: LOG_TARGETS.DEV2}, `Testing log 2`); // You will not see this
151
+ console.log({context: LOG_CONTEXTS.STANDARD}, `Testing log 3`); // You will see this
152
+ console.log(`Testing log 4`); // You will see this. No context = LOG_CONTEXTS.ALL
148
153
 
149
- anaLogger.setContexts(LOG_CONTEXT);
150
154
 
151
- anaLogger.log(LOG_CONTEXT.C1, `Test Log example C1`);
152
- anaLogger.log(LOG_CONTEXT.C2, `Test Log example C2`);
153
- anaLogger.log(LOG_CONTEXT.C3, `Test Log example C3`);
155
+ anaLogger.log(LOG_CONTEXTS.C1, `Test Log example C1`); // You will see this
154
156
  ```
155
157
 
156
158
  <br/><br/>
@@ -162,5 +164,27 @@ It is helpful to guarantee that the code is running straight away rather than wa
162
164
 
163
165
 
164
166
  ```javascript
165
- anaLogger.asset((a, b)=> a === b, true)
167
+ anaLogger.assert(1 === 1)
168
+ anaLogger.assert(1 === 2)
169
+ anaLogger.assert(()=>true, true)
170
+ anaLogger.assert((a, b)=> a === b, true, 2, 2)
171
+ ```
172
+
173
+ <br/><br/>
174
+
175
+ ###
176
+
177
+ When an error is detected and should be seen by your app consumers explicitly (for instance, display a dialogue box
178
+ to them), you can hook your logic.
179
+
180
+ ```javascript
181
+ anaLogger.setErrorHandlerForUserTarget(function (context/*, ...args*/)
182
+ {
183
+ // Detect whether we are in a browser
184
+ if (context.environnment === anaLogger.ENVIRONMENT_TYPE.BROWSER)
185
+ {
186
+ // When an error is detected in the Browser, the Browser will see this message
187
+ anaLogger.alert(`Users explicitly see this message`)
188
+ }
189
+ })
166
190
  ```
package/ci.md ADDED
Binary file
package/package.json CHANGED
@@ -1,50 +1,61 @@
1
- {
2
- "name": "analogger",
3
- "version": "1.1.5",
4
- "description": "Js Logger",
5
- "main": "dist/index-cjs.min.cjs",
6
- "module": "dist/index-esm.min.mjs",
7
- "type": "module",
8
- "exports": {
9
- ".": {
10
- "require": "./dist/index-cjs.min.cjs",
11
- "import": "./dist/index-esm.min.mjs"
12
- }
13
- },
14
- "scripts": {
15
- "convert-cjs:esm": "toesm.cmd --input=\"src/cjs/**/*.cjs\" --output=src/esm/ --input=\"example/**/*.cjs\" --output=example/esm/ --config=\".toesm.cjs\"",
16
- "convert-cjs:browser": "toesm.cmd --input=\"src/cjs/**/*.cjs\" --input=\"example/**/*.cjs\" --output=src/esm-browser/ --output=example/esm-browser/ --config=\".toesm.cjs\" --solvedep",
17
- "bundle:prod:cjs": "rollup --config rollup-cjs.config.js",
18
- "bundle:prod:esm": "rollup --config rollup-esm.config.js",
19
- "bundle:prod": "npm run convert-cjs:esm && npm run convert-cjs:browser && npm run bundle:prod:cjs && npm run bundle:prod:esm",
20
- "demo": "npm run bundle:prod && node example/cjs/demo.cjs"
21
- },
22
- "author": "Patrice Thimothee",
23
- "license": "MIT",
24
- "homepage": "https://github.com/thimpat/analogger/blob/main/README.md",
25
- "repository": {
26
- "type": "git",
27
- "url": "https://github.com/thimpat/analogger.git"
28
- },
29
- "devDependencies": {
30
- "@babel/core": "^7.17.0",
31
- "@babel/eslint-parser": "^7.17.0",
32
- "@babel/preset-env": "^7.16.11",
33
- "@rollup/plugin-commonjs": "^21.0.1",
34
- "@rollup/plugin-node-resolve": "^13.1.3",
35
- "babel-eslint": "^10.1.0",
36
- "eslint": "^8.8.0",
37
- "rollup": "^2.67.0",
38
- "rollup-plugin-delete": "^2.0.0",
39
- "rollup-plugin-uglify": "^6.0.4",
40
- "to-esm": "^1.6.2"
41
- },
42
- "dependencies": {
43
- "chalk": "^5.0.0",
44
- "chalk-cjs": "npm:chalk@^4.1.2",
45
- "color-convert": "^2.0.1",
46
- "color-convert-cjs": "npm:color-convert@^2.0.1",
47
- "rgb-hex": "^4.0.0",
48
- "rgb-hex-cjs": "npm:rgb-hex@^3.0.0"
49
- }
50
- }
1
+ {
2
+ "name": "analogger",
3
+ "version": "1.3.0",
4
+ "description": "Js Logger",
5
+ "main": "dist/index-cjs.min.cjs",
6
+ "module": "dist/index-esm.min.mjs",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/index-cjs.min.cjs",
11
+ "import": "./dist/index-esm.min.mjs"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "convert-cjs:esm": "toesm.cmd --input=\"src/cjs/**/*.cjs\" --output=src/esm/ --input=\"example/**/*.cjs\" --output=example/esm/ --config=\".toesm.cjs\"",
16
+ "convert-cjs:browser": "toesm.cmd --input=\"src/cjs/**/*.cjs\" --input=\"example/**/*.cjs\" --output=src/esm-browser/ --output=example/esm-browser/ --config=\".toesm.cjs\" --solvedep",
17
+ "bundle:prod:cjs": "rollup --config rollup-cjs.config.js",
18
+ "bundle:prod:esm": "rollup --config rollup-esm.config.js",
19
+ "bundle:prod": "npm run convert-cjs:esm && npm run convert-cjs:browser && npm run bundle:prod:cjs && npm run bundle:prod:esm",
20
+ "test": "mocha",
21
+ "demo": "npm run bundle:prod && node example/cjs/demo.cjs"
22
+ },
23
+ "author": "Patrice Thimothee",
24
+ "license": "MIT",
25
+ "homepage": "https://github.com/thimpat/analogger/blob/main/README.md",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/thimpat/analogger.git"
29
+ },
30
+ "devDependencies": {
31
+ "@babel/core": "^7.17.0",
32
+ "@babel/eslint-parser": "^7.17.0",
33
+ "@babel/preset-env": "^7.16.11",
34
+ "@rollup/plugin-commonjs": "^21.0.1",
35
+ "@rollup/plugin-node-resolve": "^13.1.3",
36
+ "@semantic-release/changelog": "^6.0.1",
37
+ "@semantic-release/commit-analyzer": "^9.0.2",
38
+ "@semantic-release/git": "^10.0.1",
39
+ "@semantic-release/npm": "^9.0.0",
40
+ "@semantic-release/release-notes-generator": "^10.0.3",
41
+ "babel-eslint": "^10.1.0",
42
+ "capture-console": "^1.0.1",
43
+ "chai": "^4.3.6",
44
+ "chai-spies": "^1.0.0",
45
+ "eslint": "^8.8.0",
46
+ "mocha": "^9.2.0",
47
+ "rollup": "^2.67.0",
48
+ "rollup-plugin-delete": "^2.0.0",
49
+ "rollup-plugin-uglify": "^6.0.4",
50
+ "semantic-release": "^19.0.2",
51
+ "to-esm": "^1.6.2"
52
+ },
53
+ "dependencies": {
54
+ "chalk": "^5.0.0",
55
+ "chalk-cjs": "npm:chalk@^4.1.2",
56
+ "color-convert": "^2.0.1",
57
+ "color-convert-cjs": "npm:color-convert@^2.0.1",
58
+ "rgb-hex": "^4.0.0",
59
+ "rgb-hex-cjs": "npm:rgb-hex@^3.0.0"
60
+ }
61
+ }
@@ -0,0 +1,109 @@
1
+ const chai = require("chai");
2
+ var capcon = require('capture-console');
3
+ const {anaLogger} = require("../src/cjs/ana-logger.cjs");
4
+ const {LOG_CONTEXT, LOG_TARGETS} = require("../example/cjs/contexts-def.cjs");
5
+ const expect = chai.expect;
6
+
7
+ describe('In the Terminal', function ()
8
+ {
9
+ const {anaLogger} = require("../src/cjs/ana-logger.cjs");
10
+
11
+ const LOG_CONTEXT = {STANDARD: {}, TEST: {color: "#B18904", symbol: "⏰"}, C1: null, C2: null, C3: null, DEFAULT: {}}
12
+ const LOG_TARGETS = {ALL: "ALL", DEV1: "TOM", DEV2: "TIM", DEV3: "ME", USER: "USER"}
13
+
14
+ before(()=>
15
+ {
16
+ anaLogger.setContexts(LOG_CONTEXT);
17
+ anaLogger.setTargets(LOG_TARGETS);
18
+ })
19
+
20
+ beforeEach(()=>
21
+ {
22
+ anaLogger.resetLogHistory()
23
+ anaLogger.keepLogHistory()
24
+ anaLogger.setOptions({silent: false, hideError: false})
25
+ anaLogger.removeOverride()
26
+ anaLogger.removeOverrideError()
27
+ })
28
+
29
+ describe('AnaLogger', function ()
30
+ {
31
+ it('should emulate console.log', function ()
32
+ {
33
+ const captured = capcon.captureStdio(function ()
34
+ {
35
+ anaLogger.log(`Test Log example C1`);
36
+ })
37
+
38
+ expect(captured.stdout).to.contain(`Test Log example C1`)
39
+ });
40
+
41
+ it('should hide console output when the console behaviour is overridden', function ()
42
+ {
43
+ const captured = capcon.captureStdio(function ()
44
+ {
45
+ console.log(`Log Before override`);
46
+ anaLogger.setOptions({silent: true})
47
+ anaLogger.overrideConsole()
48
+ console.log(`Log After override`);
49
+ })
50
+
51
+ expect(captured.stdout).to.contain(`Log Before override`)
52
+ expect(captured.stdout).to.not.contain(`Log After override`)
53
+ });
54
+
55
+ it('should hide console output but keep console input in the log history', function ()
56
+ {
57
+ const captured1 = capcon.captureStdio(function ()
58
+ {
59
+ anaLogger.keepLogHistory();
60
+ anaLogger.setOptions({silent: true, hideError: false})
61
+ anaLogger.log(LOG_CONTEXT.C1, `Test Log example something again`);
62
+ })
63
+
64
+ const captured2 = capcon.captureStdio(function ()
65
+ {
66
+ console.log(anaLogger.getLogHistory())
67
+ })
68
+
69
+ expect(captured1.stdout).to.not.contain(`Test Log example something again`)
70
+ expect(captured2.stdout).to.contain(`Test Log example something again`)
71
+ });
72
+
73
+ it('should hide console error when the console behaviour is overridden', function ()
74
+ {
75
+ const captured = capcon.captureStdio(function ()
76
+ {
77
+ console.log(`Log Before override`);
78
+ anaLogger.setOptions({hideError: true})
79
+ anaLogger.overrideConsole()
80
+
81
+ console.error(`Error Before override`);
82
+ anaLogger.overrideError()
83
+ console.error(`Error After override`);
84
+
85
+ console.log(`Log After override`);
86
+ })
87
+
88
+ expect(captured.stdout).to.contain(`Log Before override`)
89
+ expect(captured.stdout).to.not.contain(`Error After override`)
90
+ });
91
+
92
+ it('should not show unrelated target logs', function ()
93
+ {
94
+ const captured = capcon.captureStdio(function ()
95
+ {
96
+ anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
97
+ anaLogger.log({context: LOG_CONTEXT.TEST, target: LOG_TARGETS.DEV3, lid: 100001}, `Test Log example with active target`);
98
+ anaLogger.log({context: LOG_CONTEXT.TEST, target: LOG_TARGETS.DEV1, lid: 100002}, `Test Log example with DEV1 target`);
99
+ anaLogger.log(`Test Log example with DEFAULT target`);
100
+ })
101
+
102
+ expect(captured.stdout).to.contain(`Test Log example with active target`)
103
+ expect(captured.stdout).to.contain(`Test Log example with DEFAULT target`)
104
+ expect(captured.stdout).to.not.contain(`Test Log example with DEV1 target`)
105
+ });
106
+
107
+
108
+ });
109
+ });
package/test/unit.cjs ADDED
@@ -0,0 +1,105 @@
1
+ const chai = require("chai");
2
+ const expect = chai.expect;
3
+ const spies = require('chai-spies');
4
+
5
+ chai.use(spies);
6
+ // sut
7
+ const {anaLogger} = require("../src/cjs/ana-logger.cjs");
8
+ const {LOG_CONTEXT} = require("../example/cjs/contexts-def.cjs");
9
+
10
+ describe('AnaLogger', function ()
11
+ {
12
+ const LOG_CONTEXT = {STANDARD: {}, TEST: {color: "#B18904", symbol: "⏰"}, C1: null, C2: null, C3: null, DEFAULT: {}}
13
+ const LOG_TARGETS = {ALL: "ALL", DEV1: "TOM", DEV2: "TIM", DEV3: "ME", USER: "USER"}
14
+
15
+ before(() =>
16
+ {
17
+ anaLogger.setContexts(LOG_CONTEXT);
18
+ anaLogger.setTargets(LOG_TARGETS);
19
+ anaLogger.setActiveTarget(LOG_TARGETS.DEV3)
20
+ })
21
+
22
+ beforeEach(() =>
23
+ {
24
+ anaLogger.resetLogHistory()
25
+ anaLogger.keepLogHistory()
26
+ })
27
+
28
+ describe('#log()', function ()
29
+ {
30
+ it('should emulate console.log', function ()
31
+ {
32
+ // Arrange
33
+ anaLogger.setOptions({silent: false, hideError: false})
34
+
35
+ // Act
36
+ anaLogger.log(`Test Log example C1`);
37
+ const output = anaLogger.getLogHistory()
38
+
39
+ // Assert
40
+ expect(output).to.contain(`Test Log example C1`)
41
+ });
42
+ });
43
+
44
+ describe('#assert()', function ()
45
+ {
46
+ it('should evaluate condition expressions', function ()
47
+ {
48
+ const result = anaLogger.assert(1 === 1)
49
+ expect(result).to.be.true
50
+ });
51
+
52
+ it('should detect failing condition expressions', function ()
53
+ {
54
+ const result = anaLogger.assert(1 === 2)
55
+ expect(result).to.be.false
56
+ });
57
+
58
+ it('should evaluate function expressions', function ()
59
+ {
60
+ const result = anaLogger.assert(() => true, true)
61
+ expect(result).to.be.true
62
+ });
63
+
64
+ it('should evaluate more complex function expressions', function ()
65
+ {
66
+ const result = anaLogger.assert((a, b) => a === b, true, 2, 2)
67
+ expect(result).to.be.true
68
+ });
69
+ });
70
+
71
+ describe('#alert()', function ()
72
+ {
73
+ it('should not fail on alert', function ()
74
+ {
75
+ anaLogger.alert(`Hello from alert`, {aaa: 1012})
76
+ expect(anaLogger.getLogHistory()).to.contain(`Hello from alert`)
77
+ });
78
+ });
79
+
80
+ describe('#setLogFormat()', function ()
81
+ {
82
+ /**
83
+ * We use a spy here, but things would have been straightforward with a simple "done" + async on the "it"
84
+ */
85
+ it('should replace the default formatter function with the given callback when invoking console.log', function ()
86
+ {
87
+ // Arrange
88
+ const methodToCall = {
89
+ myMethod: () => { }
90
+ }
91
+
92
+ // Spy on methodToCall.myMethod to check it has been called
93
+ chai.spy.on(methodToCall, 'myMethod');
94
+
95
+ anaLogger.setLogFormat(
96
+ methodToCall.myMethod
97
+ );
98
+
99
+ console.log(LOG_CONTEXT.C1, `Test Log example C4 with new format`);
100
+ expect(methodToCall.myMethod).to.have.been.called;
101
+ });
102
+ });
103
+
104
+
105
+ });
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var require$$0=require("chalk-cjs"),require$$1=require("color-convert-cjs"),require$$2=require("rgb-hex-cjs");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var require$$0__default=_interopDefaultLegacy(require$$0),require$$1__default=_interopDefaultLegacy(require$$1),require$$2__default=_interopDefaultLegacy(require$$2),anaLogger={},constants$1={};const constants={COLOR_TABLE:["#d2466e","#FFA07A","#FF7F50","#FF6347","#FFE4B5","#ADFF2F","#808000","#40E0D0","#1E90FF","#EE82EE","#708090","#DEB887","#FE642E","#210B61","#088A4B","#5E610B","#FA8258","#088A68","#B40431"],SYSTEM:{BROWSER:"BROWSER",NODE:"NODE"}},chalk=(constants$1.COLOR_TABLE=constants.COLOR_TABLE,constants$1.SYSTEM=constants.SYSTEM,require$$0__default.default),colorConvert=require$$1__default.default,rgbHex=require$$2__default.default,{COLOR_TABLE,SYSTEM}=constants$1;class AnaLogger{system="";logIndex=0;contexts=[];targets={};activeTarget=null;indexColor=0;format="";options={hideHookMessage:!1};static ALIGN={LEFT:"LEFT",RIGHT:"RIGHT"};static ENVIRONMENT_TYPE={BROWSER:"BROWSER",NODE:"NODE",OTHER:"OTHER"};constructor(){this.system="object"==typeof process?SYSTEM.NODE:SYSTEM.BROWSER,this.format=this.onBuildLog.bind(this),this.errorTargetHandler=this.onError.bind(this),this.errorUserTargetHandler=this.onErrorForUserTarget.bind(this),this.setOptions(this.options),this.realConsoleLog=console.log,this.realConsoleInfo=console.info,this.realConsoleWarn=console.warn,this.realConsoleError=console.error,this.ALIGN=AnaLogger.ALIGN,this.ENVIRONMENT_TYPE=AnaLogger.ENVIRONMENT_TYPE}isNode(){return this.system===SYSTEM.NODE}isBrowser(){return!this.isNode()}setOptions({contextLenMax:e=10,idLenMax:t=5,lidLenMax:o=5,symbolLenMax:r=2,messageLenMax:s=60,hideLog:n=!1,hideError:i=!1,hideHookMessage:a=!1,showPassingTests:g=!0,silent:l=!1}={}){this.options.contextLenMax=e,this.options.idLenMax=t,this.options.lidLenMax=o,this.options.messageLenMax=s,this.options.symbolLenMax=r,this.options.hideLog=!!n,this.options.hideError=!!i,this.options.hideHookMessage=!!a,this.options.showPassingTests=!!g,l&&(this.options.hideLog=!0,this.options.hideHookMessage=!0)}truncateMessage(e="",{fit:t=0,align:o=AnaLogger.ALIGN.LEFT}){try{return e=""+e,t&&e.length>=t+2&&(e=e.substring(0,t-3)+"..."),e=o===AnaLogger.ALIGN.LEFT?e.padEnd(t+1," "):e.padStart(t+1," ")}catch(e){console.error("AnaLogger:",e)}}onBuildLog({contextName:e,message:t="",lid:o="",symbol:r=""}={}){const s=new Date;var n=("0"+s.getHours()).slice(-2)+":"+("0"+s.getMinutes()).slice(-2)+":"+("0"+s.getSeconds()).slice(-2),n=this.truncateMessage(n,{fit:7});return e=this.truncateMessage(e,{fit:this.options.contextLenMax,align:AnaLogger.ALIGN.RIGHT}),o=this.truncateMessage(o,{fit:this.options.lidLenMax}),t=this.truncateMessage(t,{fit:this.options.messageLenMax}),`[${n}] ${e}: (${o}) ${r=this.truncateMessage(r,{fit:this.options.symbolLenMax})} `+t}onErrorForUserTarget(e,...t){this.errorUserTargetHandler(e,...t)}onError(e,...t){e.target===this.targets.USER&&this.onErrorForUserTarget(e,...t)}onDisplayLog(...e){this.log(...e)}onDisplayError(...e){this.error(...e)}setLogFormat(e){if("function"!=typeof e)return console.error("Invalid parameter for setFormat. It is expecting a function or method."),!1;this.format=e.bind(this)}setErrorHandler(e){this.errorTargetHandler=e.bind(this)}setErrorHandlerForUserTarget(e){this.errorUserTargetHandler=e.bind(this)}isContext(e){return"object"==typeof e&&!Array.isArray(e)&&null!==e&&(e.hasOwnProperty("contextName")&&e.hasOwnProperty("target"))}generateDefaultContext(){const e={name:"DEFAULT",contextName:"DEFAULT",target:"ALL",symbol:"⚡"};return e.id=this.logIndex++,e.color=COLOR_TABLE[1],e}generateNewContext(){const e=this.generateDefaultContext();return e.color=COLOR_TABLE[this.indexColor++%(COLOR_TABLE.length-3)+2],e.symbol="",e}generateErrorContext(){const e=this.generateDefaultContext();return e.color=COLOR_TABLE[0],e.symbol="v",e.error=!0,e}allegeProperties(e){let t=e;e=this.generateNewContext();if(t=t||{contextName:"DEFAULT"},Array.isArray(t))throw new Error(`AnaLogger: Cannot convert Array [${JSON.stringify(t)}] to context`);if(("string"==typeof t||t instanceof String)&&(t={contextName:t}),"object"!=typeof t)throw new Error(`AnaLogger: Cannot convert Unknown [${JSON.stringify(t)}] to context`);return t=Object.assign({},e,t),-1<t.color.toLowerCase().indexOf("rgb")?t.color="#"+rgbHex(t.color):-1===t.color.indexOf("#")&&colorConvert&&(t.color="#"+colorConvert.keyword.hex(t.color)),t}setContexts(o){const e=Object.keys(o);o.DEFAULT=this.contexts.DEFAULT=this.generateDefaultContext(),o.ERROR=this.contexts.ERROR=this.generateErrorContext(),e.forEach(e=>{const t=o[e]||{};t.contextName=e,t.name=e,this.contexts[e]=this.allegeProperties(t),o[e]=this.contexts[e]})}setTargets(e={}){this.targets=Object.assign({},e,{ALL:"ALL",USER:"USER"})}setActiveTarget(e){this.activeTarget=e}enableContexts(e){this.contexts.forEach(e=>{})}getActiveLogContexts(){}isTargetAllowed(e){return!e||!this.activeTarget||(e===this.targets.ALL||this.activeTarget===e)}processLog(t={}){try{if(this.options.hideLog)return;if(!this.isTargetAllowed(t.target))return;let e=Array.prototype.slice.call(arguments);e.shift();var o=e.join(" | "),r=this.format({...t,message:o});this.isBrowser()?(t.environnment=AnaLogger.ENVIRONMENT_TYPE.BROWSER,this.realConsoleLog("%c"+r,"color: "+t.color)):(t.environnment=AnaLogger.ENVIRONMENT_TYPE.NODE,this.realConsoleLog(chalk.hex(t.color)(r))),this.errorTargetHandler(t,e)}catch(e){console.error("AnaLogger:",e.message)}}isExtendedOptionsPassed(e){return"object"==typeof e&&(e.hasOwnProperty("context")||e.hasOwnProperty("target"))}log(e,...t){var o;if(!this.isExtendedOptionsPassed(e))return o=this.generateDefaultContext(),void this.processLog.apply(this,[o,e,...t]);let r=e;if("object"==typeof e.context){const s=Object.assign({},e);delete s.context,r=Object.assign({},e.context,s)}r.hasOwnProperty("context")&&(r=Object.assign({},this.generateDefaultContext(),r),delete r.context),this.processLog.apply(this,[r,...t])}error(e,...t){if(!this.options.hideError){var o=this.generateErrorContext();if(this.isExtendedOptionsPassed(e))return e=Object.assign({},o,e),this.log(e,...t);e=Array.prototype.slice.call(arguments);this.log(o,...e)}}overrideError(){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.error"),console.error=this.onDisplayError.bind(this)}overrideConsole({log:e=!0,info:t=!0,warn:o=!0,error:r=!1}={}){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.log"),e&&(console.log=this.onDisplayLog.bind(this)),t&&(console.info=this.onDisplayLog.bind(this)),o&&(console.warn=this.onDisplayLog.bind(this)),r&&this.overrideError()}info(...e){return this.log(...e)}warn(...e){return this.log(...e)}alert(...e){if(this.isNode())return this.log(...e);e=e.join(" | ");alert(e)}assert(e,t=!0){try{if("function"==typeof e)return e()!==t?void this.error("Asset failed"):void(this.options.showPassingTests&&this.log("SUCCESS: Assert passed"));if(e!==t)return void this.error("Asset failed");this.options.showPassingTests&&this.log("SUCCESS: Assert passed")}catch(e){this.error("Unexpected error in assert")}}}var anaLogger_1=anaLogger.anaLogger=new AnaLogger;exports.anaLogger=anaLogger_1,exports.default=anaLogger;
@@ -1 +0,0 @@
1
- function rgbHex(e,t,o,r){var s=(e+(r||"")).toString().includes("%");if("string"==typeof e?[e,t,o,r]=e.match(/(0?\.?\d{1,3})%?\b/g).map(e=>Number(e)):void 0!==r&&(r=Number.parseFloat(r)),"number"!=typeof e||"number"!=typeof t||"number"!=typeof o||255<e||255<t||255<o)throw new TypeError("Expected three numbers below 256");if("number"==typeof r){if(!s&&0<=r&&r<=1)r=Math.round(255*r);else{if(!(s&&0<=r&&r<=100))throw new TypeError(`Expected alpha value (${r}) as a fraction or percentage`);r=Math.round(255*r/100)}r=(256|r).toString(16).slice(1)}else r="";return(o|t<<8|e<<16|1<<24).toString(16).slice(1)+r}const constants={COLOR_TABLE:["#d2466e","#FFA07A","#FF7F50","#FF6347","#FFE4B5","#ADFF2F","#808000","#40E0D0","#1E90FF","#EE82EE","#708090","#DEB887","#FE642E","#210B61","#088A4B","#5E610B","#FA8258","#088A68","#B40431"],SYSTEM:{BROWSER:"BROWSER",NODE:"NODE"}},COLOR_TABLE=constants.COLOR_TABLE,SYSTEM=constants.SYSTEM,chalk=null;class AnaLogger{system="";logIndex=0;contexts=[];targets={};activeTarget=null;indexColor=0;format="";options={hideHookMessage:!1};static ALIGN={LEFT:"LEFT",RIGHT:"RIGHT"};static ENVIRONMENT_TYPE={BROWSER:"BROWSER",NODE:"NODE",OTHER:"OTHER"};constructor(){this.system="object"==typeof process?SYSTEM.NODE:SYSTEM.BROWSER,this.format=this.onBuildLog.bind(this),this.errorTargetHandler=this.onError.bind(this),this.errorUserTargetHandler=this.onErrorForUserTarget.bind(this),this.setOptions(this.options),this.realConsoleLog=console.log,this.realConsoleInfo=console.info,this.realConsoleWarn=console.warn,this.realConsoleError=console.error,this.ALIGN=AnaLogger.ALIGN,this.ENVIRONMENT_TYPE=AnaLogger.ENVIRONMENT_TYPE}isNode(){return this.system===SYSTEM.NODE}isBrowser(){return!this.isNode()}setOptions({contextLenMax:e=10,idLenMax:t=5,lidLenMax:o=5,symbolLenMax:r=2,messageLenMax:s=60,hideLog:n=!1,hideError:i=!1,hideHookMessage:a=!1,showPassingTests:g=!0,silent:h=!1}={}){this.options.contextLenMax=e,this.options.idLenMax=t,this.options.lidLenMax=o,this.options.messageLenMax=s,this.options.symbolLenMax=r,this.options.hideLog=!!n,this.options.hideError=!!i,this.options.hideHookMessage=!!a,this.options.showPassingTests=!!g,h&&(this.options.hideLog=!0,this.options.hideHookMessage=!0)}truncateMessage(e="",{fit:t=0,align:o=AnaLogger.ALIGN.LEFT}){try{return e=""+e,t&&e.length>=t+2&&(e=e.substring(0,t-3)+"..."),e=o===AnaLogger.ALIGN.LEFT?e.padEnd(t+1," "):e.padStart(t+1," ")}catch(e){console.error("AnaLogger:",e)}}onBuildLog({contextName:e,message:t="",lid:o="",symbol:r=""}={}){const s=new Date;var n=("0"+s.getHours()).slice(-2)+":"+("0"+s.getMinutes()).slice(-2)+":"+("0"+s.getSeconds()).slice(-2),n=this.truncateMessage(n,{fit:7});return e=this.truncateMessage(e,{fit:this.options.contextLenMax,align:AnaLogger.ALIGN.RIGHT}),o=this.truncateMessage(o,{fit:this.options.lidLenMax}),t=this.truncateMessage(t,{fit:this.options.messageLenMax}),`[${n}] ${e}: (${o}) ${r=this.truncateMessage(r,{fit:this.options.symbolLenMax})} `+t}onErrorForUserTarget(e,...t){this.errorUserTargetHandler(e,...t)}onError(e,...t){e.target===this.targets.USER&&this.onErrorForUserTarget(e,...t)}onDisplayLog(...e){this.log(...e)}onDisplayError(...e){this.error(...e)}setLogFormat(e){if("function"!=typeof e)return console.error("Invalid parameter for setFormat. It is expecting a function or method."),!1;this.format=e.bind(this)}setErrorHandler(e){this.errorTargetHandler=e.bind(this)}setErrorHandlerForUserTarget(e){this.errorUserTargetHandler=e.bind(this)}isContext(e){return"object"==typeof e&&!Array.isArray(e)&&null!==e&&(e.hasOwnProperty("contextName")&&e.hasOwnProperty("target"))}generateDefaultContext(){const e={name:"DEFAULT",contextName:"DEFAULT",target:"ALL",symbol:"⚡"};return e.id=this.logIndex++,e.color=COLOR_TABLE[1],e}generateNewContext(){const e=this.generateDefaultContext();return e.color=COLOR_TABLE[this.indexColor++%(COLOR_TABLE.length-3)+2],e.symbol="",e}generateErrorContext(){const e=this.generateDefaultContext();return e.color=COLOR_TABLE[0],e.symbol="v",e.error=!0,e}allegeProperties(e){let t=e;e=this.generateNewContext();if(t=t||{contextName:"DEFAULT"},Array.isArray(t))throw new Error(`AnaLogger: Cannot convert Array [${JSON.stringify(t)}] to context`);if(("string"==typeof t||t instanceof String)&&(t={contextName:t}),"object"!=typeof t)throw new Error(`AnaLogger: Cannot convert Unknown [${JSON.stringify(t)}] to context`);return t=Object.assign({},e,t),-1<t.color.toLowerCase().indexOf("rgb")?t.color="#"+rgbHex(t.color):t.color.indexOf("#"),t}setContexts(o){const e=Object.keys(o);o.DEFAULT=this.contexts.DEFAULT=this.generateDefaultContext(),o.ERROR=this.contexts.ERROR=this.generateErrorContext(),e.forEach(e=>{const t=o[e]||{};t.contextName=e,t.name=e,this.contexts[e]=this.allegeProperties(t),o[e]=this.contexts[e]})}setTargets(e={}){this.targets=Object.assign({},e,{ALL:"ALL",USER:"USER"})}setActiveTarget(e){this.activeTarget=e}enableContexts(e){this.contexts.forEach(e=>{})}getActiveLogContexts(){}isTargetAllowed(e){return!e||!this.activeTarget||(e===this.targets.ALL||this.activeTarget===e)}processLog(t={}){try{if(this.options.hideLog)return;if(!this.isTargetAllowed(t.target))return;let e=Array.prototype.slice.call(arguments);e.shift();var o=e.join(" | "),r=this.format({...t,message:o});this.isBrowser()?(t.environnment=AnaLogger.ENVIRONMENT_TYPE.BROWSER,this.realConsoleLog("%c"+r,"color: "+t.color)):(t.environnment=AnaLogger.ENVIRONMENT_TYPE.NODE,this.realConsoleLog(chalk.hex(t.color)(r))),this.errorTargetHandler(t,e)}catch(e){console.error("AnaLogger:",e.message)}}isExtendedOptionsPassed(e){return"object"==typeof e&&(e.hasOwnProperty("context")||e.hasOwnProperty("target"))}log(e,...t){var o;if(!this.isExtendedOptionsPassed(e))return o=this.generateDefaultContext(),void this.processLog.apply(this,[o,e,...t]);let r=e;if("object"==typeof e.context){const s=Object.assign({},e);delete s.context,r=Object.assign({},e.context,s)}r.hasOwnProperty("context")&&(r=Object.assign({},this.generateDefaultContext(),r),delete r.context),this.processLog.apply(this,[r,...t])}error(e,...t){if(!this.options.hideError){var o=this.generateErrorContext();if(this.isExtendedOptionsPassed(e))return e=Object.assign({},o,e),this.log(e,...t);var r=Array.prototype.slice.call(arguments);this.log(o,...r)}}overrideError(){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.error"),console.error=this.onDisplayError.bind(this)}overrideConsole({log:e=!0,info:t=!0,warn:o=!0,error:r=!1}={}){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.log"),e&&(console.log=this.onDisplayLog.bind(this)),t&&(console.info=this.onDisplayLog.bind(this)),o&&(console.warn=this.onDisplayLog.bind(this)),r&&this.overrideError()}info(...e){return this.log(...e)}warn(...e){return this.log(...e)}alert(...e){if(this.isNode())return this.log(...e);e=e.join(" | ");alert(e)}assert(e,t=!0){try{if("function"==typeof e)return e()!==t?void this.error("Asset failed"):void(this.options.showPassingTests&&this.log("SUCCESS: Assert passed"));if(e!==t)return void this.error("Asset failed");this.options.showPassingTests&&this.log("SUCCESS: Assert passed")}catch(e){this.error("Unexpected error in assert")}}}const anaLogger=new AnaLogger;export{anaLogger};