Browse Source

feat: adds "noInstMsg" option

e22m4u 2 months ago
parent
commit
1f097b41f5
4 changed files with 14 additions and 2 deletions
  1. 2 1
      dist/cjs/index.cjs
  2. 1 0
      src/debuggable.d.ts
  3. 3 1
      src/debuggable.js
  4. 8 0
      src/debuggable.spec.js

+ 2 - 1
dist/cjs/index.cjs

@@ -102,7 +102,8 @@ var _Debuggable = class _Debuggable {
     const noEnvNs = Boolean(options.noEnvNs);
     if (noEnvNs) this.debug = this.debug.withoutEnvNs();
     this.ctorDebug = this.debug.withNs("constructor").withHash();
-    this.ctorDebug(_Debuggable.INSTANTIATION_MESSAGE);
+    const noInstMsg = Boolean(options.noInstMsg);
+    if (!noInstMsg) this.ctorDebug(_Debuggable.INSTANTIATION_MESSAGE);
   }
 };
 __name(_Debuggable, "Debuggable");

+ 1 - 0
src/debuggable.d.ts

@@ -7,6 +7,7 @@ import {Debugger} from './create-debugger.js';
 export type DebuggableOptions = {
   namespace: string,
   noEnvNs: boolean,
+  noInstMsg: boolean,
 }
 
 /**

+ 3 - 1
src/debuggable.js

@@ -5,6 +5,7 @@ import {createDebugger} from '@e22m4u/js-debug';
  * @typedef {{
  *   namespace: string,
  *   noEnvNs: boolean,
+ *   noInstMsg: boolean,
  * }} DebuggableOptions
  */
 
@@ -68,6 +69,7 @@ export class Debuggable {
     if (noEnvNs) this.debug = this.debug.withoutEnvNs();
 
     this.ctorDebug = this.debug.withNs('constructor').withHash();
-    this.ctorDebug(Debuggable.INSTANTIATION_MESSAGE);
+    const noInstMsg = Boolean(options.noInstMsg);
+    if (!noInstMsg) this.ctorDebug(Debuggable.INSTANTIATION_MESSAGE);
   }
 }

+ 8 - 0
src/debuggable.spec.js

@@ -109,6 +109,14 @@ describe('Debuggable', function () {
         );
       });
     });
+
+    describe('"noInstMsg" option', function () {
+      it('should hide instantiation message', function () {
+        process.env.DEBUG = '*';
+        new Debuggable({noInstMsg: true});
+        expect(consoleLogSpy.callCount).to.equal(0);
+      });
+    });
   });
 
   describe('getDebuggerFor', function () {