Browse Source

chore: makes option names more verbose

e22m4u 2 months ago
parent
commit
90ca50ac92
5 changed files with 34 additions and 32 deletions
  1. 7 7
      README.md
  2. 7 6
      dist/cjs/index.cjs
  3. 2 2
      src/debuggable.d.ts
  4. 11 10
      src/debuggable.js
  5. 7 7
      src/debuggable.spec.js

+ 7 - 7
README.md

@@ -412,8 +412,8 @@ calculator.multiply(4, 8);
 Первый аргумент класса `Debuggable` принимает объект со следующими свойствами.
 
 - `namespace?: string` - префиксное пространство имен;
-- `noEnvNs?: boolean` - игнорировать переменную `DEBUGGER_NAMESPACE`;
-- `noInstMsg?: boolean` - не выводить сообщение о создании экземпляра;
+- `noEnvironmentNamespace?: boolean` - игнорировать переменную `DEBUGGER_NAMESPACE`;
+- `noInstantiationMessage?: boolean` - не выводить сообщение о создании экземпляра;
 
 #### DebuggableOptions.namespace
 
@@ -445,11 +445,11 @@ calculator.multiply(4, 8);
 // myApp:calculator:multiply:4d8w Result 32.
 ```
 
-#### DebuggableOptions.noEnvNs
+#### DebuggableOptions.noEnvironmentNamespace
 
-Значение `true` опции `noEnvNs` позволяет игнорировать переменную
-окружения `DEBUGGER_NAMESPACE`, устанавливающую префиксное пространство
-имен.
+Значение `true` опции `noEnvironmentNamespace` позволяет игнорировать
+переменную окружения `DEBUGGER_NAMESPACE`, устанавливающую префиксное
+пространство имен.
 
 ```js
 import {Debuggable} from '@e22m4u/js-debug';
@@ -459,7 +459,7 @@ process.env['DEBUG'] = '*';
 
 class Calculator extends Debuggable {
   constructor() {
-    super({noEnvNs: true}); // <=
+    super({noEnvironmentNamespace: true}); // <=
   }
 
   multiply(a, b) {

+ 7 - 6
dist/cjs/index.cjs

@@ -82,12 +82,12 @@ var _Debuggable = class _Debuggable {
    * @returns {Function}
    */
   getDebuggerFor(method) {
-    return this.debug.withHash().withNs(method.name);
+    const name = method.name || "anonymous";
+    return this.debug.withHash().withNs(name);
   }
   /**
    * Constructor.
    *
-   * @param {object|undefined} container
    * @param {DebuggableOptions|undefined} options
    */
   constructor(options = void 0) {
@@ -99,11 +99,12 @@ var _Debuggable = class _Debuggable {
     } else {
       this.debug = createDebugger(className);
     }
-    const noEnvNs = Boolean(options.noEnvNs);
-    if (noEnvNs) this.debug = this.debug.withoutEnvNs();
+    const noEnvironmentNamespace = Boolean(options.noEnvironmentNamespace);
+    if (noEnvironmentNamespace) this.debug = this.debug.withoutEnvNs();
     this.ctorDebug = this.debug.withNs("constructor").withHash();
-    const noInstMsg = Boolean(options.noInstMsg);
-    if (!noInstMsg) this.ctorDebug(_Debuggable.INSTANTIATION_MESSAGE);
+    const noInstantiationMessage = Boolean(options.noInstantiationMessage);
+    if (!noInstantiationMessage)
+      this.ctorDebug(_Debuggable.INSTANTIATION_MESSAGE);
   }
 };
 __name(_Debuggable, "Debuggable");

+ 2 - 2
src/debuggable.d.ts

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

+ 11 - 10
src/debuggable.js

@@ -3,9 +3,9 @@ import {createDebugger} from '@e22m4u/js-debug';
 
 /**
  * @typedef {{
- *   namespace: string,
- *   noEnvNs: boolean,
- *   noInstMsg: boolean,
+ *   namespace?: string,
+ *   noEnvironmentNamespace?: boolean,
+ *   noInstantiationMessage?: boolean,
  * }} DebuggableOptions
  */
 
@@ -42,13 +42,13 @@ export class Debuggable {
    * @returns {Function}
    */
   getDebuggerFor(method) {
-    return this.debug.withHash().withNs(method.name);
+    const name = method.name || 'anonymous';
+    return this.debug.withHash().withNs(name);
   }
 
   /**
    * Constructor.
    *
-   * @param {object|undefined} container
    * @param {DebuggableOptions|undefined} options
    */
   constructor(options = undefined) {
@@ -63,13 +63,14 @@ export class Debuggable {
     } else {
       this.debug = createDebugger(className);
     }
-    // опция "noEnvNs" отключает пространство имен
+    // опция "noEnvironmentNamespace" отключает пространство имен
     // из переменной окружения DEBUGGER_NAMESPACE
-    const noEnvNs = Boolean(options.noEnvNs);
-    if (noEnvNs) this.debug = this.debug.withoutEnvNs();
+    const noEnvironmentNamespace = Boolean(options.noEnvironmentNamespace);
+    if (noEnvironmentNamespace) this.debug = this.debug.withoutEnvNs();
 
     this.ctorDebug = this.debug.withNs('constructor').withHash();
-    const noInstMsg = Boolean(options.noInstMsg);
-    if (!noInstMsg) this.ctorDebug(Debuggable.INSTANTIATION_MESSAGE);
+    const noInstantiationMessage = Boolean(options.noInstantiationMessage);
+    if (!noInstantiationMessage)
+      this.ctorDebug(Debuggable.INSTANTIATION_MESSAGE);
   }
 }

+ 7 - 7
src/debuggable.spec.js

@@ -86,11 +86,11 @@ describe('Debuggable', function () {
       });
     });
 
-    describe('"noEnvNs" option', function () {
-      it('should use DEBUGGER_NAMESPACE when the option "noEnvNs" is false', function () {
+    describe('"noEnvironmentNamespace" option', function () {
+      it('should use DEBUGGER_NAMESPACE when the option "noEnvironmentNamespace" is false', function () {
         process.env.DEBUGGER_NAMESPACE = 'myApp';
         process.env.DEBUG = '*';
-        new Debuggable({noEnvNs: false});
+        new Debuggable({noEnvironmentNamespace: false});
         expect(consoleLogSpy.callCount).to.equal(1);
         const msg = escapeRegexp(Debuggable.INSTANTIATION_MESSAGE);
         expect(stripAnsi(consoleLogSpy.getCall(0).args[0])).to.match(
@@ -98,10 +98,10 @@ describe('Debuggable', function () {
         );
       });
 
-      it('should skip DEBUGGER_NAMESPACE when the option "noEnvNs" is true', function () {
+      it('should skip DEBUGGER_NAMESPACE when the option "noEnvironmentNamespace" is true', function () {
         process.env.DEBUGGER_NAMESPACE = 'myApp';
         process.env.DEBUG = '*';
-        new Debuggable({noEnvNs: true});
+        new Debuggable({noEnvironmentNamespace: true});
         expect(consoleLogSpy.callCount).to.equal(1);
         const msg = escapeRegexp(Debuggable.INSTANTIATION_MESSAGE);
         expect(stripAnsi(consoleLogSpy.getCall(0).args[0])).to.match(
@@ -110,10 +110,10 @@ describe('Debuggable', function () {
       });
     });
 
-    describe('"noInstMsg" option', function () {
+    describe('"noInstantiationMessage" option', function () {
       it('should hide instantiation message', function () {
         process.env.DEBUG = '*';
-        new Debuggable({noInstMsg: true});
+        new Debuggable({noInstantiationMessage: true});
         expect(consoleLogSpy.callCount).to.equal(0);
       });
     });