@naturalcycles/nodejs-lib 13.1.4 → 13.2.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/dist/index.d.ts CHANGED
@@ -58,7 +58,7 @@ export * from './stream/writable/writableVoid';
58
58
  export * from './csv/csvWriter';
59
59
  export * from './csv/csvReader';
60
60
  export * from './csv/transformToCSV';
61
- export * from './string/inspectAny';
61
+ export * from './string/inspect';
62
62
  export * from './util/env.util';
63
63
  export * from './util/lruMemoCache';
64
64
  export * from './util/zip.util';
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ tslib_1.__exportStar(require("./stream/writable/writableVoid"), exports);
62
62
  tslib_1.__exportStar(require("./csv/csvWriter"), exports);
63
63
  tslib_1.__exportStar(require("./csv/csvReader"), exports);
64
64
  tslib_1.__exportStar(require("./csv/transformToCSV"), exports);
65
- tslib_1.__exportStar(require("./string/inspectAny"), exports);
65
+ tslib_1.__exportStar(require("./string/inspect"), exports);
66
66
  tslib_1.__exportStar(require("./util/env.util"), exports);
67
67
  tslib_1.__exportStar(require("./util/lruMemoCache"), exports);
68
68
  tslib_1.__exportStar(require("./util/zip.util"), exports);
@@ -7,5 +7,5 @@ const index_1 = require("../index");
7
7
  * CommonLogger that logs to process.stdout directly (bypassing console.log).
8
8
  */
9
9
  exports.stdoutLogger = (0, js_lib_1.commonLoggerCreate)((_level, args) => {
10
- process.stdout.write(args.map(a => (0, index_1.inspectAny)(a)).join(' ') + '\n');
10
+ process.stdout.write(args.map(a => (0, index_1._inspect)(a)).join(' ') + '\n');
11
11
  });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runScript = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const inspectAny_1 = require("../string/inspectAny");
5
+ const inspect_1 = require("../string/inspect");
6
6
  const { DEBUG_RUN_SCRIPT } = process.env;
7
7
  /**
8
8
  * Use it in your top-level scripts like this:
@@ -23,7 +23,7 @@ const { DEBUG_RUN_SCRIPT } = process.env;
23
23
  * Set env DEBUG_RUN_SCRIPT for extra debugging.
24
24
  */
25
25
  function runScript(fn, opt = {}) {
26
- (0, js_lib_1.setGlobalStringifyFunction)(inspectAny_1.inspectAnyStringifyFn);
26
+ (0, js_lib_1.setGlobalStringifyFunction)(inspect_1.inspectStringifyFn);
27
27
  const { logger = console, noExit } = opt;
28
28
  process.on('uncaughtException', err => {
29
29
  logger.error('uncaughtException:', err);
@@ -69,10 +69,10 @@ class SlackService {
69
69
  let text;
70
70
  // Array has a special treatment here
71
71
  if (Array.isArray(msg.items)) {
72
- text = msg.items.map(t => (0, __1.inspectAny)(t, inspectOptions)).join('\n');
72
+ text = msg.items.map(t => (0, __1._inspect)(t, inspectOptions)).join('\n');
73
73
  }
74
74
  else {
75
- text = (0, __1.inspectAny)(msg.items, inspectOptions);
75
+ text = (0, __1._inspect)(msg.items, inspectOptions);
76
76
  }
77
77
  // Wrap in markdown-text-block if it's anything but plain String
78
78
  if (typeof msg.items !== 'string') {
@@ -1,12 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import { InspectOptions } from 'node:util';
3
- import { StringifyAnyOptions, JsonStringifyFunction } from '@naturalcycles/js-lib';
4
- export interface InspectAnyOptions extends StringifyAnyOptions, InspectOptions {
3
+ import { StringifyOptions, JsonStringifyFunction } from '@naturalcycles/js-lib';
4
+ export interface InspectAnyOptions extends StringifyOptions, InspectOptions {
5
5
  }
6
6
  /**
7
7
  * Just a convenience export of a const that fulfills the JsonStringifyFunction interface.
8
8
  */
9
- export declare const inspectAnyStringifyFn: JsonStringifyFunction;
9
+ export declare const inspectStringifyFn: JsonStringifyFunction;
10
10
  /**
11
11
  * Transforms ANY to human-readable string (via util.inspect mainly).
12
12
  * Safe (no error throwing).
@@ -22,6 +22,10 @@ export declare const inspectAnyStringifyFn: JsonStringifyFunction;
22
22
  * Returns 'empty_string' if empty string is passed.
23
23
  * Returns 'undefined' if undefined is passed (default util.inspect behavior).
24
24
  *
25
- * Based on `_stringifyAny` from `js-lib`, just replaced `JSON.stringify` with `util.inspect`.
25
+ * Based on `_stringify` from `js-lib`, just replaced `JSON.stringify` with `util.inspect`.
26
26
  */
27
- export declare function inspectAny(obj: any, opt?: InspectAnyOptions): string;
27
+ export declare function _inspect(obj: any, opt?: InspectAnyOptions): string;
28
+ /**
29
+ * @deprecated renamed to _inspect
30
+ */
31
+ export declare const inspectAny: typeof _inspect;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inspectAny = exports.inspectAnyStringifyFn = void 0;
3
+ exports.inspectAny = exports._inspect = exports.inspectStringifyFn = void 0;
4
4
  const node_util_1 = require("node:util");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const INSPECT_OPT = {
@@ -10,8 +10,8 @@ const INSPECT_OPT = {
10
10
  /**
11
11
  * Just a convenience export of a const that fulfills the JsonStringifyFunction interface.
12
12
  */
13
- const inspectAnyStringifyFn = obj => (0, node_util_1.inspect)(obj, INSPECT_OPT);
14
- exports.inspectAnyStringifyFn = inspectAnyStringifyFn;
13
+ const inspectStringifyFn = obj => (0, node_util_1.inspect)(obj, INSPECT_OPT);
14
+ exports.inspectStringifyFn = inspectStringifyFn;
15
15
  /**
16
16
  * Transforms ANY to human-readable string (via util.inspect mainly).
17
17
  * Safe (no error throwing).
@@ -27,9 +27,9 @@ exports.inspectAnyStringifyFn = inspectAnyStringifyFn;
27
27
  * Returns 'empty_string' if empty string is passed.
28
28
  * Returns 'undefined' if undefined is passed (default util.inspect behavior).
29
29
  *
30
- * Based on `_stringifyAny` from `js-lib`, just replaced `JSON.stringify` with `util.inspect`.
30
+ * Based on `_stringify` from `js-lib`, just replaced `JSON.stringify` with `util.inspect`.
31
31
  */
32
- function inspectAny(obj, opt = {}) {
32
+ function _inspect(obj, opt = {}) {
33
33
  // Inspect handles functions better
34
34
  if (typeof obj === 'function') {
35
35
  return (0, node_util_1.inspect)(obj, {
@@ -37,7 +37,7 @@ function inspectAny(obj, opt = {}) {
37
37
  ...opt,
38
38
  });
39
39
  }
40
- return (0, js_lib_1._stringifyAny)(obj, {
40
+ return (0, js_lib_1._stringify)(obj, {
41
41
  ...opt,
42
42
  stringifyFn: obj => (0, node_util_1.inspect)(obj, {
43
43
  ...INSPECT_OPT,
@@ -45,4 +45,8 @@ function inspectAny(obj, opt = {}) {
45
45
  }),
46
46
  });
47
47
  }
48
- exports.inspectAny = inspectAny;
48
+ exports._inspect = _inspect;
49
+ /**
50
+ * @deprecated renamed to _inspect
51
+ */
52
+ exports.inspectAny = _inspect;
@@ -86,7 +86,7 @@ class AjvSchema {
86
86
  dataVar: name,
87
87
  separator,
88
88
  });
89
- const strValue = (0, index_1.inspectAny)(obj, { maxLen: 1000 });
89
+ const strValue = (0, index_1._inspect)(obj, { maxLen: 1000 });
90
90
  message = [message, 'Input: ' + strValue].join(separator);
91
91
  if (logErrors) {
92
92
  this.cfg.logger.error(errors);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.1.4",
3
+ "version": "13.2.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
package/src/index.ts CHANGED
@@ -68,7 +68,7 @@ export * from './stream/writable/writableVoid'
68
68
  export * from './csv/csvWriter'
69
69
  export * from './csv/csvReader'
70
70
  export * from './csv/transformToCSV'
71
- export * from './string/inspectAny'
71
+ export * from './string/inspect'
72
72
  export * from './util/env.util'
73
73
  export * from './util/lruMemoCache'
74
74
  export * from './util/zip.util'
@@ -1,9 +1,9 @@
1
1
  import { commonLoggerCreate } from '@naturalcycles/js-lib'
2
- import { inspectAny } from '../index'
2
+ import { _inspect } from '../index'
3
3
 
4
4
  /**
5
5
  * CommonLogger that logs to process.stdout directly (bypassing console.log).
6
6
  */
7
7
  export const stdoutLogger = commonLoggerCreate((_level, args) => {
8
- process.stdout.write(args.map(a => inspectAny(a)).join(' ') + '\n')
8
+ process.stdout.write(args.map(a => _inspect(a)).join(' ') + '\n')
9
9
  })
@@ -1,6 +1,6 @@
1
1
  import { setGlobalStringifyFunction } from '@naturalcycles/js-lib'
2
2
  import type { CommonLogger } from '@naturalcycles/js-lib'
3
- import { inspectAnyStringifyFn } from '../string/inspectAny'
3
+ import { inspectStringifyFn } from '../string/inspect'
4
4
 
5
5
  export interface RunScriptOptions {
6
6
  /**
@@ -37,7 +37,7 @@ const { DEBUG_RUN_SCRIPT } = process.env
37
37
  * Set env DEBUG_RUN_SCRIPT for extra debugging.
38
38
  */
39
39
  export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {}): void {
40
- setGlobalStringifyFunction(inspectAnyStringifyFn)
40
+ setGlobalStringifyFunction(inspectStringifyFn)
41
41
 
42
42
  const { logger = console, noExit } = opt
43
43
 
@@ -9,7 +9,7 @@ import {
9
9
  localTimeNow,
10
10
  PQueue,
11
11
  } from '@naturalcycles/js-lib'
12
- import { inspectAny, InspectAnyOptions } from '..'
12
+ import { _inspect, InspectAnyOptions } from '..'
13
13
  import {
14
14
  SlackApiBody,
15
15
  SlackAttachmentField,
@@ -99,9 +99,9 @@ export class SlackService<CTX = any> {
99
99
 
100
100
  // Array has a special treatment here
101
101
  if (Array.isArray(msg.items)) {
102
- text = msg.items.map(t => inspectAny(t, inspectOptions)).join('\n')
102
+ text = msg.items.map(t => _inspect(t, inspectOptions)).join('\n')
103
103
  } else {
104
- text = inspectAny(msg.items, inspectOptions)
104
+ text = _inspect(msg.items, inspectOptions)
105
105
  }
106
106
 
107
107
  // Wrap in markdown-text-block if it's anything but plain String
@@ -1,7 +1,7 @@
1
1
  import { inspect, InspectOptions } from 'node:util'
2
- import { StringifyAnyOptions, _stringifyAny, JsonStringifyFunction } from '@naturalcycles/js-lib'
2
+ import { StringifyOptions, _stringify, JsonStringifyFunction } from '@naturalcycles/js-lib'
3
3
 
4
- export interface InspectAnyOptions extends StringifyAnyOptions, InspectOptions {}
4
+ export interface InspectAnyOptions extends StringifyOptions, InspectOptions {}
5
5
 
6
6
  const INSPECT_OPT: InspectOptions = {
7
7
  breakLength: 80, // default: ??
@@ -11,7 +11,7 @@ const INSPECT_OPT: InspectOptions = {
11
11
  /**
12
12
  * Just a convenience export of a const that fulfills the JsonStringifyFunction interface.
13
13
  */
14
- export const inspectAnyStringifyFn: JsonStringifyFunction = obj => inspect(obj, INSPECT_OPT)
14
+ export const inspectStringifyFn: JsonStringifyFunction = obj => inspect(obj, INSPECT_OPT)
15
15
 
16
16
  /**
17
17
  * Transforms ANY to human-readable string (via util.inspect mainly).
@@ -28,9 +28,9 @@ export const inspectAnyStringifyFn: JsonStringifyFunction = obj => inspect(obj,
28
28
  * Returns 'empty_string' if empty string is passed.
29
29
  * Returns 'undefined' if undefined is passed (default util.inspect behavior).
30
30
  *
31
- * Based on `_stringifyAny` from `js-lib`, just replaced `JSON.stringify` with `util.inspect`.
31
+ * Based on `_stringify` from `js-lib`, just replaced `JSON.stringify` with `util.inspect`.
32
32
  */
33
- export function inspectAny(obj: any, opt: InspectAnyOptions = {}): string {
33
+ export function _inspect(obj: any, opt: InspectAnyOptions = {}): string {
34
34
  // Inspect handles functions better
35
35
  if (typeof obj === 'function') {
36
36
  return inspect(obj, {
@@ -39,7 +39,7 @@ export function inspectAny(obj: any, opt: InspectAnyOptions = {}): string {
39
39
  })
40
40
  }
41
41
 
42
- return _stringifyAny(obj, {
42
+ return _stringify(obj, {
43
43
  ...opt,
44
44
  stringifyFn: obj =>
45
45
  inspect(obj, {
@@ -48,3 +48,8 @@ export function inspectAny(obj: any, opt: InspectAnyOptions = {}): string {
48
48
  }),
49
49
  })
50
50
  }
51
+
52
+ /**
53
+ * @deprecated renamed to _inspect
54
+ */
55
+ export const inspectAny = _inspect
@@ -8,7 +8,7 @@ import {
8
8
  CommonLogger,
9
9
  } from '@naturalcycles/js-lib'
10
10
  import Ajv, { ValidateFunction } from 'ajv'
11
- import { _readJsonSync, inspectAny, requireFileToExist } from '../../index'
11
+ import { _readJsonSync, _inspect, requireFileToExist } from '../../index'
12
12
  import { AjvValidationError } from './ajvValidationError'
13
13
  import { getAjv } from './getAjv'
14
14
 
@@ -173,7 +173,7 @@ export class AjvSchema<T = unknown> {
173
173
  separator,
174
174
  })
175
175
 
176
- const strValue = inspectAny(obj, { maxLen: 1000 })
176
+ const strValue = _inspect(obj, { maxLen: 1000 })
177
177
  message = [message, 'Input: ' + strValue].join(separator)
178
178
 
179
179
  if (logErrors) {