Просмотр исходного кода

chore: adds export `createColorizedDump` function

e22m4u 7 месяцев назад
Родитель
Сommit
e96d692c11
6 измененных файлов с 51 добавлено и 22 удалено
  1. 18 8
      dist/cjs/index.cjs
  2. 6 0
      src/create-colorized-dump.d.ts
  3. 23 0
      src/create-colorized-dump.js
  4. 2 14
      src/create-debugger.js
  5. 1 0
      src/index.d.ts
  6. 1 0
      src/index.js

+ 18 - 8
dist/cjs/index.cjs

@@ -20,12 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
 // src/index.js
 var index_exports = {};
 __export(index_exports, {
+  INSPECT_OPTIONS: () => INSPECT_OPTIONS,
+  createColorizedDump: () => createColorizedDump,
   createDebugger: () => createDebugger
 });
 module.exports = __toCommonJS(index_exports);
 
 // src/create-debugger.js
-var import_util = require("util");
 var import_js_format = require("@e22m4u/js-format");
 var import_js_format2 = require("@e22m4u/js-format");
 
@@ -53,6 +54,19 @@ function generateRandomHex(length = 4) {
 }
 __name(generateRandomHex, "generateRandomHex");
 
+// src/create-colorized-dump.js
+var import_util = require("util");
+var INSPECT_OPTIONS = {
+  showHidden: false,
+  depth: null,
+  colors: true,
+  compact: false
+};
+function createColorizedDump(value) {
+  return (0, import_util.inspect)(value, INSPECT_OPTIONS);
+}
+__name(createColorizedDump, "createColorizedDump");
+
 // src/create-debugger.js
 var AVAILABLE_COLORS = [
   20,
@@ -132,12 +146,6 @@ var AVAILABLE_COLORS = [
   220,
   221
 ];
-var INSPECT_OPTIONS = {
-  showHidden: false,
-  depth: null,
-  colors: true,
-  compact: false
-};
 function pickColorCode(input) {
   if (typeof input !== "string")
     throw new import_js_format.Errorf(
@@ -251,7 +259,7 @@ function createDebugger(namespaceOrOptions = void 0, ...namespaceSegments) {
       prefix ? console.log(`${prefix} ${message}`) : console.log(message);
       return;
     }
-    const multiString = (0, import_util.inspect)(messageOrData, INSPECT_OPTIONS);
+    const multiString = createColorizedDump(messageOrData);
     const rows = multiString.split("\n");
     [...args, ...rows].forEach((message) => {
       prefix ? console.log(`${prefix} ${message}`) : console.log(message);
@@ -297,5 +305,7 @@ function createDebugger(namespaceOrOptions = void 0, ...namespaceSegments) {
 __name(createDebugger, "createDebugger");
 // Annotate the CommonJS export names for ESM import in node:
 0 && (module.exports = {
+  INSPECT_OPTIONS,
+  createColorizedDump,
   createDebugger
 });

+ 6 - 0
src/create-colorized-dump.d.ts

@@ -0,0 +1,6 @@
+/**
+ * Create colorized dump.
+ *
+ * @param value
+ */
+export declare function dump(value: unknown): void;

+ 23 - 0
src/create-colorized-dump.js

@@ -0,0 +1,23 @@
+import {inspect} from 'util';
+
+/**
+ * Опции утилиты inspect для дампа объектов.
+ *
+ * @type {object}
+ */
+export const INSPECT_OPTIONS = {
+  showHidden: false,
+  depth: null,
+  colors: true,
+  compact: false,
+};
+
+/**
+ * Create colorized dump.
+ *
+ * @param {*} value
+ * @returns {string}
+ */
+export function createColorizedDump(value) {
+  return inspect(value, INSPECT_OPTIONS);
+}

+ 2 - 14
src/create-debugger.js

@@ -1,8 +1,8 @@
-import {inspect} from 'util';
 import {Errorf} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
 import {isNonArrayObject} from './utils/index.js';
 import {generateRandomHex} from './utils/index.js';
+import {createColorizedDump} from './create-colorized-dump.js';
 
 /**
  * Доступные цвета.
@@ -17,18 +17,6 @@ const AVAILABLE_COLORS = [
   205, 206, 207, 208, 209, 214, 215, 220, 221,
 ];
 
-/**
- * Опции утилиты inspect для дампа объектов.
- *
- * @type {object}
- */
-const INSPECT_OPTIONS = {
-  showHidden: false,
-  depth: null,
-  colors: true,
-  compact: false,
-};
-
 /**
  * Подбор цвета для строки.
  *
@@ -230,7 +218,7 @@ export function createDebugger(
       prefix ? console.log(`${prefix} ${message}`) : console.log(message);
       return;
     }
-    const multiString = inspect(messageOrData, INSPECT_OPTIONS);
+    const multiString = createColorizedDump(messageOrData);
     const rows = multiString.split('\n');
     [...args, ...rows].forEach(message => {
       prefix ? console.log(`${prefix} ${message}`) : console.log(message);

+ 1 - 0
src/index.d.ts

@@ -1 +1,2 @@
 export * from './create-debugger.js';
+export * from './create-colorized-dump.js';

+ 1 - 0
src/index.js

@@ -1 +1,2 @@
 export * from './create-debugger.js';
+export * from './create-colorized-dump.js';