@naturalcycles/js-lib 14.190.0 → 14.191.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.
@@ -27,7 +27,7 @@ function _LogMethod(opt = {}) {
27
27
  let { logResultFn } = opt;
28
28
  if (!logResultFn) {
29
29
  if (logResult) {
30
- logResultFn = r => ['result:', (0, __1._stringifyAny)(r)];
30
+ logResultFn = r => ['result:', (0, __1._stringify)(r)];
31
31
  }
32
32
  else if (logResultLength) {
33
33
  logResultFn = r => (Array.isArray(r) ? [`result: ${r.length} items`] : []);
@@ -36,7 +36,7 @@ exports._assert = _assert;
36
36
  function _assertEquals(actual, expected, message, errorData) {
37
37
  if (actual !== expected) {
38
38
  const msg = message ||
39
- ['not equal', `expected: ${(0, __1._stringifyAny)(expected)}`, `got : ${(0, __1._stringifyAny)(actual)}`]
39
+ ['not equal', `expected: ${(0, __1._stringify)(expected)}`, `got : ${(0, __1._stringify)(actual)}`]
40
40
  .filter(Boolean)
41
41
  .join('\n');
42
42
  throw new __1.AssertionError(msg, {
@@ -55,11 +55,7 @@ exports._assertEquals = _assertEquals;
55
55
  function _assertDeepEquals(actual, expected, message, errorData) {
56
56
  if (!(0, __1._deepEquals)(actual, expected)) {
57
57
  const msg = message ||
58
- [
59
- `not deeply equal`,
60
- `expected: ${(0, __1._stringifyAny)(expected)}`,
61
- `got : ${(0, __1._stringifyAny)(actual)}`,
62
- ]
58
+ [`not deeply equal`, `expected: ${(0, __1._stringify)(expected)}`, `got : ${(0, __1._stringify)(actual)}`]
63
59
  .filter(Boolean)
64
60
  .join('\n');
65
61
  throw new __1.AssertionError(msg, {
@@ -12,7 +12,7 @@ export declare function _anyToError<ERROR_TYPE extends Error = Error>(o: any, er
12
12
  * Converts "anything" to ErrorObject.
13
13
  * Detects if it's HttpErrorResponse, HttpErrorObject, ErrorObject, Error, etc..
14
14
  * If object is Error - Error.message will be used.
15
- * Objects (not Errors) get converted to prettified JSON string (via `_stringifyAny`).
15
+ * Objects (not Errors) get converted to prettified JSON string (via `_stringify`).
16
16
  */
17
17
  export declare function _anyToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(o: any, errorData?: Partial<DATA_TYPE>): ErrorObject<DATA_TYPE>;
18
18
  export declare function _errorLikeToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(e: AppError<DATA_TYPE> | Error | ErrorLike): ErrorObject<DATA_TYPE>;
@@ -34,7 +34,7 @@ exports._anyToError = _anyToError;
34
34
  * Converts "anything" to ErrorObject.
35
35
  * Detects if it's HttpErrorResponse, HttpErrorObject, ErrorObject, Error, etc..
36
36
  * If object is Error - Error.message will be used.
37
- * Objects (not Errors) get converted to prettified JSON string (via `_stringifyAny`).
37
+ * Objects (not Errors) get converted to prettified JSON string (via `_stringify`).
38
38
  */
39
39
  function _anyToErrorObject(o, errorData) {
40
40
  let eo;
@@ -57,7 +57,7 @@ function _anyToErrorObject(o, errorData) {
57
57
  // so, fair to return `data: {}` in the end
58
58
  // Also we're sure it includes no "error name", e.g no `Error: ...`,
59
59
  // so, fair to include `name: 'Error'`
60
- const message = (0, __1._stringifyAny)(o);
60
+ const message = (0, __1._stringify)(o);
61
61
  eo = {
62
62
  name: 'Error',
63
63
  message,
package/dist/error/try.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports._expectedErrorString = exports.pExpectedErrorString = exports.pExpectedError = exports._expectedError = exports.pTry = exports._try = void 0;
4
- const stringifyAny_1 = require("../string/stringifyAny");
4
+ const stringify_1 = require("../string/stringify");
5
5
  const assert_1 = require("./assert");
6
6
  const error_util_1 = require("./error.util");
7
7
  /**
@@ -101,7 +101,7 @@ exports.pExpectedError = pExpectedError;
101
101
  */
102
102
  async function pExpectedErrorString(promise, errorClass) {
103
103
  const err = await pExpectedError(promise, errorClass);
104
- return (0, stringifyAny_1._stringifyAny)(err);
104
+ return (0, stringify_1._stringify)(err);
105
105
  }
106
106
  exports.pExpectedErrorString = pExpectedErrorString;
107
107
  /**
@@ -109,6 +109,6 @@ exports.pExpectedErrorString = pExpectedErrorString;
109
109
  */
110
110
  function _expectedErrorString(fn, errorClass) {
111
111
  const err = _expectedError(fn, errorClass);
112
- return (0, stringifyAny_1._stringifyAny)(err);
112
+ return (0, stringify_1._stringify)(err);
113
113
  }
114
114
  exports._expectedErrorString = _expectedErrorString;
@@ -12,7 +12,7 @@ const object_util_1 = require("../object/object.util");
12
12
  const pDelay_1 = require("../promise/pDelay");
13
13
  const pTimeout_1 = require("../promise/pTimeout");
14
14
  const json_util_1 = require("../string/json.util");
15
- const stringifyAny_1 = require("../string/stringifyAny");
15
+ const stringify_1 = require("../string/stringify");
16
16
  const time_util_1 = require("../time/time.util");
17
17
  const http_model_1 = require("./http.model");
18
18
  const acceptByResponseType = {
@@ -392,7 +392,7 @@ class Fetcher {
392
392
  .filter(Boolean)
393
393
  .join(' ') + '\n',
394
394
  // We're stringifying the error here, otherwise Sentry shows it as [object Object]
395
- (0, stringifyAny_1._stringifyAny)(res.err.cause || res.err));
395
+ (0, stringify_1._stringify)(res.err.cause || res.err));
396
396
  }
397
397
  if (retryStatus.retryStopped)
398
398
  return;
package/dist/index.d.ts CHANGED
@@ -50,7 +50,7 @@ export * from './string/string.util';
50
50
  export * from './string/readingTime';
51
51
  export * from './string/escape';
52
52
  export * from './string/pupa';
53
- export * from './string/stringifyAny';
53
+ export * from './string/stringify';
54
54
  export * from './time/time.util';
55
55
  export * from './is.util';
56
56
  export * from './typeFest';
package/dist/index.js CHANGED
@@ -54,7 +54,7 @@ tslib_1.__exportStar(require("./string/string.util"), exports);
54
54
  tslib_1.__exportStar(require("./string/readingTime"), exports);
55
55
  tslib_1.__exportStar(require("./string/escape"), exports);
56
56
  tslib_1.__exportStar(require("./string/pupa"), exports);
57
- tslib_1.__exportStar(require("./string/stringifyAny"), exports);
57
+ tslib_1.__exportStar(require("./string/stringify"), exports);
58
58
  tslib_1.__exportStar(require("./time/time.util"), exports);
59
59
  tslib_1.__exportStar(require("./is.util"), exports);
60
60
  tslib_1.__exportStar(require("./typeFest"), exports);
@@ -3,7 +3,7 @@ import type { Reviver } from '../types';
3
3
  * Allows to set Global "stringifyFunction" that will be used to "pretty-print" objects
4
4
  * in various cases.
5
5
  *
6
- * Used, for example, by _stringifyAny() to pretty-print objects/arrays.
6
+ * Used, for example, by _stringify() to pretty-print objects/arrays.
7
7
  *
8
8
  * Defaults to _safeJsonStringify.
9
9
  *
@@ -14,7 +14,7 @@ import type { Reviver } from '../types';
14
14
  */
15
15
  export declare function setGlobalStringifyFunction(fn: JsonStringifyFunction): void;
16
16
  export type JsonStringifyFunction = (obj: any, reviver?: Reviver, space?: number) => string;
17
- export interface StringifyAnyOptions {
17
+ export interface StringifyOptions {
18
18
  /**
19
19
  * @default 10_000
20
20
  * Default limit is less than in Node, cause it's likely to be used e.g in Browser alert()
@@ -47,13 +47,13 @@ export interface StringifyAnyOptions {
47
47
  stringifyFn?: JsonStringifyFunction;
48
48
  }
49
49
  /**
50
- * Inspired by inspectAny from nodejs-lib, which is based on util.inpect that is not available in the Browser.
50
+ * Inspired by `_inspect` from nodejs-lib, which is based on util.inpect that is not available in the Browser.
51
51
  * Potentially can do this (with extra 2Kb gz size): https://github.com/deecewan/browser-util-inspect
52
52
  *
53
53
  * Transforms ANY to human-readable string (via JSON.stringify pretty).
54
54
  * Safe (no error throwing).
55
55
  *
56
- * Correclty prints Errors, AppErrors, ErrorObjects: error.message + \n + stringifyAny(error.data)
56
+ * Correctly prints Errors, AppErrors, ErrorObjects: error.message + \n + _stringify(error.data)
57
57
  *
58
58
  * Enforces max length (default to 1000, pass 0 to skip it).
59
59
  *
@@ -64,4 +64,8 @@ export interface StringifyAnyOptions {
64
64
  * Returns 'empty_string' if empty string is passed.
65
65
  * Returns 'undefined' if undefined is passed (default util.inspect behavior).
66
66
  */
67
- export declare function _stringifyAny(obj: any, opt?: StringifyAnyOptions): string;
67
+ export declare function _stringify(obj: any, opt?: StringifyOptions): string;
68
+ /**
69
+ * @deprecated renamed to _stringify
70
+ */
71
+ export declare const _stringifyAny: typeof _stringify;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._stringifyAny = exports.setGlobalStringifyFunction = void 0;
3
+ exports._stringifyAny = exports._stringify = exports.setGlobalStringifyFunction = void 0;
4
4
  const error_util_1 = require("../error/error.util");
5
5
  const json_util_1 = require("./json.util");
6
6
  const safeJsonStringify_1 = require("./safeJsonStringify");
@@ -10,7 +10,7 @@ let globalStringifyFunction = safeJsonStringify_1._safeJsonStringify;
10
10
  * Allows to set Global "stringifyFunction" that will be used to "pretty-print" objects
11
11
  * in various cases.
12
12
  *
13
- * Used, for example, by _stringifyAny() to pretty-print objects/arrays.
13
+ * Used, for example, by _stringify() to pretty-print objects/arrays.
14
14
  *
15
15
  * Defaults to _safeJsonStringify.
16
16
  *
@@ -24,13 +24,13 @@ function setGlobalStringifyFunction(fn) {
24
24
  }
25
25
  exports.setGlobalStringifyFunction = setGlobalStringifyFunction;
26
26
  /**
27
- * Inspired by inspectAny from nodejs-lib, which is based on util.inpect that is not available in the Browser.
27
+ * Inspired by `_inspect` from nodejs-lib, which is based on util.inpect that is not available in the Browser.
28
28
  * Potentially can do this (with extra 2Kb gz size): https://github.com/deecewan/browser-util-inspect
29
29
  *
30
30
  * Transforms ANY to human-readable string (via JSON.stringify pretty).
31
31
  * Safe (no error throwing).
32
32
  *
33
- * Correclty prints Errors, AppErrors, ErrorObjects: error.message + \n + stringifyAny(error.data)
33
+ * Correctly prints Errors, AppErrors, ErrorObjects: error.message + \n + _stringify(error.data)
34
34
  *
35
35
  * Enforces max length (default to 1000, pass 0 to skip it).
36
36
  *
@@ -41,7 +41,7 @@ exports.setGlobalStringifyFunction = setGlobalStringifyFunction;
41
41
  * Returns 'empty_string' if empty string is passed.
42
42
  * Returns 'undefined' if undefined is passed (default util.inspect behavior).
43
43
  */
44
- function _stringifyAny(obj, opt = {}) {
44
+ function _stringify(obj, opt = {}) {
45
45
  if (obj === undefined)
46
46
  return 'undefined';
47
47
  if (obj === null)
@@ -57,7 +57,7 @@ function _stringifyAny(obj, opt = {}) {
57
57
  // HttpErrorResponse
58
58
  //
59
59
  if ((0, error_util_1._isBackendErrorResponseObject)(obj)) {
60
- return _stringifyAny(obj.error, opt);
60
+ return _stringify(obj.error, opt);
61
61
  }
62
62
  if (obj instanceof Error || (0, error_util_1._isErrorLike)(obj)) {
63
63
  const { includeErrorCause = true } = opt;
@@ -79,7 +79,7 @@ function _stringifyAny(obj, opt = {}) {
79
79
  s += `\ncode: ${obj.code}`;
80
80
  }
81
81
  if (opt.includeErrorData && (0, error_util_1._isErrorObject)(obj) && Object.keys(obj.data).length) {
82
- s += '\n' + _stringifyAny(obj.data, opt);
82
+ s += '\n' + _stringify(obj.data, opt);
83
83
  }
84
84
  if (opt.includeErrorStack && obj.stack) {
85
85
  // Here we're using the previously-generated "title line" (e.g "Error: some_message"),
@@ -94,11 +94,11 @@ function _stringifyAny(obj, opt = {}) {
94
94
  s = [
95
95
  s,
96
96
  `${obj.errors.length} error(s):`,
97
- ...obj.errors.map((err, i) => `${i + 1}. ${_stringifyAny(err, opt)}`),
97
+ ...obj.errors.map((err, i) => `${i + 1}. ${_stringify(err, opt)}`),
98
98
  ].join('\n');
99
99
  }
100
100
  if (obj.cause && includeErrorCause) {
101
- s = s + '\nCaused by: ' + _stringifyAny(obj.cause, opt);
101
+ s = s + '\nCaused by: ' + _stringify(obj.cause, opt);
102
102
  }
103
103
  }
104
104
  else if (typeof obj === 'string') {
@@ -129,4 +129,8 @@ function _stringifyAny(obj, opt = {}) {
129
129
  }
130
130
  return s;
131
131
  }
132
- exports._stringifyAny = _stringifyAny;
132
+ exports._stringify = _stringify;
133
+ /**
134
+ * @deprecated renamed to _stringify
135
+ */
136
+ exports._stringifyAny = _stringify;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZodValidationError = exports.zSafeValidate = exports.zValidate = exports.zIsValid = void 0;
4
4
  const zod_1 = require("zod");
5
- const stringifyAny_1 = require("../string/stringifyAny");
5
+ const stringify_1 = require("../string/stringify");
6
6
  function zIsValid(value, schema) {
7
7
  const { success } = schema.safeParse(value);
8
8
  return success;
@@ -48,7 +48,7 @@ class ZodValidationError extends zod_1.ZodError {
48
48
  `Invalid ${objectTitle}`,
49
49
  '',
50
50
  'Input:',
51
- (0, stringifyAny_1._stringifyAny)(this.value),
51
+ (0, stringify_1._stringify)(this.value),
52
52
  this.issues.length > 1 ? `\n${this.issues.length} issues:` : '',
53
53
  ...this.issues.slice(0, 100).map(i => {
54
54
  return [i.path.join('.'), i.message].filter(Boolean).join(': ');
@@ -1,4 +1,4 @@
1
- import { SimpleMovingAverage, _stringifyAny, _assert } from '..';
1
+ import { SimpleMovingAverage, _stringify, _assert } from '..';
2
2
  import { _ms } from '../time/time.util';
3
3
  import { _getArgsSignature, _getMethodSignature } from './decorator.util';
4
4
  /**
@@ -24,7 +24,7 @@ export function _LogMethod(opt = {}) {
24
24
  let { logResultFn } = opt;
25
25
  if (!logResultFn) {
26
26
  if (logResult) {
27
- logResultFn = r => ['result:', _stringifyAny(r)];
27
+ logResultFn = r => ['result:', _stringify(r)];
28
28
  }
29
29
  else if (logResultLength) {
30
30
  logResultFn = r => (Array.isArray(r) ? [`result: ${r.length} items`] : []);
@@ -1,4 +1,4 @@
1
- import { _deepEquals, _isErrorObject, _stringifyAny, AssertionError } from '..';
1
+ import { _deepEquals, _isErrorObject, _stringify, AssertionError } from '..';
2
2
  /**
3
3
  * Evaluates the `condition` (casts it to Boolean).
4
4
  * Expects it to be truthy, otherwise throws AppError.
@@ -29,7 +29,7 @@ message, errorData) {
29
29
  export function _assertEquals(actual, expected, message, errorData) {
30
30
  if (actual !== expected) {
31
31
  const msg = message ||
32
- ['not equal', `expected: ${_stringifyAny(expected)}`, `got : ${_stringifyAny(actual)}`]
32
+ ['not equal', `expected: ${_stringify(expected)}`, `got : ${_stringify(actual)}`]
33
33
  .filter(Boolean)
34
34
  .join('\n');
35
35
  throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
@@ -44,11 +44,7 @@ export function _assertEquals(actual, expected, message, errorData) {
44
44
  export function _assertDeepEquals(actual, expected, message, errorData) {
45
45
  if (!_deepEquals(actual, expected)) {
46
46
  const msg = message ||
47
- [
48
- `not deeply equal`,
49
- `expected: ${_stringifyAny(expected)}`,
50
- `got : ${_stringifyAny(actual)}`,
51
- ]
47
+ [`not deeply equal`, `expected: ${_stringify(expected)}`, `got : ${_stringify(actual)}`]
52
48
  .filter(Boolean)
53
49
  .join('\n');
54
50
  throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
@@ -1,4 +1,4 @@
1
- import { _jsonParseIfPossible, _stringifyAny, _truncate, _truncateMiddle, isServerSide } from '..';
1
+ import { _jsonParseIfPossible, _stringify, _truncate, _truncateMiddle, isServerSide } from '..';
2
2
  /**
3
3
  * Useful to ensure that error in `catch (err) { ... }`
4
4
  * is indeed an Error (and not e.g `string` or `undefined`).
@@ -27,7 +27,7 @@ export function _anyToError(o, errorClass = Error, errorData) {
27
27
  * Converts "anything" to ErrorObject.
28
28
  * Detects if it's HttpErrorResponse, HttpErrorObject, ErrorObject, Error, etc..
29
29
  * If object is Error - Error.message will be used.
30
- * Objects (not Errors) get converted to prettified JSON string (via `_stringifyAny`).
30
+ * Objects (not Errors) get converted to prettified JSON string (via `_stringify`).
31
31
  */
32
32
  export function _anyToErrorObject(o, errorData) {
33
33
  let eo;
@@ -50,7 +50,7 @@ export function _anyToErrorObject(o, errorData) {
50
50
  // so, fair to return `data: {}` in the end
51
51
  // Also we're sure it includes no "error name", e.g no `Error: ...`,
52
52
  // so, fair to include `name: 'Error'`
53
- const message = _stringifyAny(o);
53
+ const message = _stringify(o);
54
54
  eo = {
55
55
  name: 'Error',
56
56
  message,
@@ -1,4 +1,4 @@
1
- import { _stringifyAny } from '../string/stringifyAny';
1
+ import { _stringify } from '../string/stringify';
2
2
  import { _assertErrorClassOrRethrow } from './assert';
3
3
  import { UnexpectedPassError } from './error.util';
4
4
  /**
@@ -94,12 +94,12 @@ export async function pExpectedError(promise, errorClass) {
94
94
  */
95
95
  export async function pExpectedErrorString(promise, errorClass) {
96
96
  const err = await pExpectedError(promise, errorClass);
97
- return _stringifyAny(err);
97
+ return _stringify(err);
98
98
  }
99
99
  /**
100
100
  * Shortcut function to simplify error snapshot-matching in tests.
101
101
  */
102
102
  export function _expectedErrorString(fn, errorClass) {
103
103
  const err = _expectedError(fn, errorClass);
104
- return _stringifyAny(err);
104
+ return _stringify(err);
105
105
  }
@@ -10,7 +10,7 @@ import { _filterNullishValues, _filterUndefinedValues, _mapKeys, _merge, _omit,
10
10
  import { pDelay } from '../promise/pDelay';
11
11
  import { pTimeout } from '../promise/pTimeout';
12
12
  import { _jsonParse, _jsonParseIfPossible } from '../string/json.util';
13
- import { _stringifyAny } from '../string/stringifyAny';
13
+ import { _stringify } from '../string/stringify';
14
14
  import { _ms, _since } from '../time/time.util';
15
15
  import { HTTP_METHODS } from './http.model';
16
16
  const acceptByResponseType = {
@@ -372,7 +372,7 @@ export class Fetcher {
372
372
  .filter(Boolean)
373
373
  .join(' ') + '\n',
374
374
  // We're stringifying the error here, otherwise Sentry shows it as [object Object]
375
- _stringifyAny(res.err.cause || res.err));
375
+ _stringify(res.err.cause || res.err));
376
376
  }
377
377
  if (retryStatus.retryStopped)
378
378
  return;
package/dist-esm/index.js CHANGED
@@ -50,7 +50,7 @@ export * from './string/string.util';
50
50
  export * from './string/readingTime';
51
51
  export * from './string/escape';
52
52
  export * from './string/pupa';
53
- export * from './string/stringifyAny';
53
+ export * from './string/stringify';
54
54
  export * from './time/time.util';
55
55
  export * from './is.util';
56
56
  export * from './typeFest';
@@ -7,7 +7,7 @@ let globalStringifyFunction = _safeJsonStringify;
7
7
  * Allows to set Global "stringifyFunction" that will be used to "pretty-print" objects
8
8
  * in various cases.
9
9
  *
10
- * Used, for example, by _stringifyAny() to pretty-print objects/arrays.
10
+ * Used, for example, by _stringify() to pretty-print objects/arrays.
11
11
  *
12
12
  * Defaults to _safeJsonStringify.
13
13
  *
@@ -20,13 +20,13 @@ export function setGlobalStringifyFunction(fn) {
20
20
  globalStringifyFunction = fn;
21
21
  }
22
22
  /**
23
- * Inspired by inspectAny from nodejs-lib, which is based on util.inpect that is not available in the Browser.
23
+ * Inspired by `_inspect` from nodejs-lib, which is based on util.inpect that is not available in the Browser.
24
24
  * Potentially can do this (with extra 2Kb gz size): https://github.com/deecewan/browser-util-inspect
25
25
  *
26
26
  * Transforms ANY to human-readable string (via JSON.stringify pretty).
27
27
  * Safe (no error throwing).
28
28
  *
29
- * Correclty prints Errors, AppErrors, ErrorObjects: error.message + \n + stringifyAny(error.data)
29
+ * Correctly prints Errors, AppErrors, ErrorObjects: error.message + \n + _stringify(error.data)
30
30
  *
31
31
  * Enforces max length (default to 1000, pass 0 to skip it).
32
32
  *
@@ -37,7 +37,7 @@ export function setGlobalStringifyFunction(fn) {
37
37
  * Returns 'empty_string' if empty string is passed.
38
38
  * Returns 'undefined' if undefined is passed (default util.inspect behavior).
39
39
  */
40
- export function _stringifyAny(obj, opt = {}) {
40
+ export function _stringify(obj, opt = {}) {
41
41
  if (obj === undefined)
42
42
  return 'undefined';
43
43
  if (obj === null)
@@ -53,7 +53,7 @@ export function _stringifyAny(obj, opt = {}) {
53
53
  // HttpErrorResponse
54
54
  //
55
55
  if (_isBackendErrorResponseObject(obj)) {
56
- return _stringifyAny(obj.error, opt);
56
+ return _stringify(obj.error, opt);
57
57
  }
58
58
  if (obj instanceof Error || _isErrorLike(obj)) {
59
59
  const { includeErrorCause = true } = opt;
@@ -75,7 +75,7 @@ export function _stringifyAny(obj, opt = {}) {
75
75
  s += `\ncode: ${obj.code}`;
76
76
  }
77
77
  if (opt.includeErrorData && _isErrorObject(obj) && Object.keys(obj.data).length) {
78
- s += '\n' + _stringifyAny(obj.data, opt);
78
+ s += '\n' + _stringify(obj.data, opt);
79
79
  }
80
80
  if (opt.includeErrorStack && obj.stack) {
81
81
  // Here we're using the previously-generated "title line" (e.g "Error: some_message"),
@@ -90,11 +90,11 @@ export function _stringifyAny(obj, opt = {}) {
90
90
  s = [
91
91
  s,
92
92
  `${obj.errors.length} error(s):`,
93
- ...obj.errors.map((err, i) => `${i + 1}. ${_stringifyAny(err, opt)}`),
93
+ ...obj.errors.map((err, i) => `${i + 1}. ${_stringify(err, opt)}`),
94
94
  ].join('\n');
95
95
  }
96
96
  if (obj.cause && includeErrorCause) {
97
- s = s + '\nCaused by: ' + _stringifyAny(obj.cause, opt);
97
+ s = s + '\nCaused by: ' + _stringify(obj.cause, opt);
98
98
  }
99
99
  }
100
100
  else if (typeof obj === 'string') {
@@ -125,3 +125,7 @@ export function _stringifyAny(obj, opt = {}) {
125
125
  }
126
126
  return s;
127
127
  }
128
+ /**
129
+ * @deprecated renamed to _stringify
130
+ */
131
+ export const _stringifyAny = _stringify;
@@ -1,5 +1,5 @@
1
1
  import { ZodError } from 'zod';
2
- import { _stringifyAny } from '../string/stringifyAny';
2
+ import { _stringify } from '../string/stringify';
3
3
  export function zIsValid(value, schema) {
4
4
  const { success } = schema.safeParse(value);
5
5
  return success;
@@ -43,7 +43,7 @@ export class ZodValidationError extends ZodError {
43
43
  `Invalid ${objectTitle}`,
44
44
  '',
45
45
  'Input:',
46
- _stringifyAny(this.value),
46
+ _stringify(this.value),
47
47
  this.issues.length > 1 ? `\n${this.issues.length} issues:` : '',
48
48
  ...this.issues.slice(0, 100).map(i => {
49
49
  return [i.path.join('.'), i.message].filter(Boolean).join(': ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.190.0",
3
+ "version": "14.191.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -1,5 +1,5 @@
1
1
  import type { CommonLogger } from '..'
2
- import { SimpleMovingAverage, _stringifyAny, _assert } from '..'
2
+ import { SimpleMovingAverage, _stringify, _assert } from '..'
3
3
  import { _ms } from '../time/time.util'
4
4
  import { _getArgsSignature, _getMethodSignature } from './decorator.util'
5
5
 
@@ -88,7 +88,7 @@ export function _LogMethod(opt: LogMethodOptions = {}): MethodDecorator {
88
88
  let { logResultFn } = opt
89
89
  if (!logResultFn) {
90
90
  if (logResult) {
91
- logResultFn = r => ['result:', _stringifyAny(r)]
91
+ logResultFn = r => ['result:', _stringify(r)]
92
92
  } else if (logResultLength) {
93
93
  logResultFn = r => (Array.isArray(r) ? [`result: ${r.length} items`] : [])
94
94
  }
@@ -1,5 +1,5 @@
1
1
  import type { ErrorData, ErrorObject } from '..'
2
- import { _deepEquals, _isErrorObject, _stringifyAny, AssertionError, Class } from '..'
2
+ import { _deepEquals, _isErrorObject, _stringify, AssertionError, Class } from '..'
3
3
 
4
4
  /**
5
5
  * Evaluates the `condition` (casts it to Boolean).
@@ -44,7 +44,7 @@ export function _assertEquals<T>(
44
44
  if (actual !== expected) {
45
45
  const msg =
46
46
  message ||
47
- ['not equal', `expected: ${_stringifyAny(expected)}`, `got : ${_stringifyAny(actual)}`]
47
+ ['not equal', `expected: ${_stringify(expected)}`, `got : ${_stringify(actual)}`]
48
48
  .filter(Boolean)
49
49
  .join('\n')
50
50
 
@@ -70,11 +70,7 @@ export function _assertDeepEquals<T>(
70
70
  if (!_deepEquals(actual, expected)) {
71
71
  const msg =
72
72
  message ||
73
- [
74
- `not deeply equal`,
75
- `expected: ${_stringifyAny(expected)}`,
76
- `got : ${_stringifyAny(actual)}`,
77
- ]
73
+ [`not deeply equal`, `expected: ${_stringify(expected)}`, `got : ${_stringify(actual)}`]
78
74
  .filter(Boolean)
79
75
  .join('\n')
80
76
 
@@ -6,7 +6,7 @@ import type {
6
6
  HttpRequestErrorData,
7
7
  ErrorLike,
8
8
  } from '..'
9
- import { _jsonParseIfPossible, _stringifyAny, _truncate, _truncateMiddle, isServerSide } from '..'
9
+ import { _jsonParseIfPossible, _stringify, _truncate, _truncateMiddle, isServerSide } from '..'
10
10
 
11
11
  /**
12
12
  * Useful to ensure that error in `catch (err) { ... }`
@@ -46,7 +46,7 @@ export function _anyToError<ERROR_TYPE extends Error = Error>(
46
46
  * Converts "anything" to ErrorObject.
47
47
  * Detects if it's HttpErrorResponse, HttpErrorObject, ErrorObject, Error, etc..
48
48
  * If object is Error - Error.message will be used.
49
- * Objects (not Errors) get converted to prettified JSON string (via `_stringifyAny`).
49
+ * Objects (not Errors) get converted to prettified JSON string (via `_stringify`).
50
50
  */
51
51
  export function _anyToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(
52
52
  o: any,
@@ -70,7 +70,7 @@ export function _anyToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(
70
70
  // so, fair to return `data: {}` in the end
71
71
  // Also we're sure it includes no "error name", e.g no `Error: ...`,
72
72
  // so, fair to include `name: 'Error'`
73
- const message = _stringifyAny(o)
73
+ const message = _stringify(o)
74
74
 
75
75
  eo = {
76
76
  name: 'Error',
package/src/error/try.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _stringifyAny } from '../string/stringifyAny'
1
+ import { _stringify } from '../string/stringify'
2
2
  import type { Class } from '../typeFest'
3
3
  import type { AnyFunction, ErrorDataTuple } from '../types'
4
4
  import { _assertErrorClassOrRethrow } from './assert'
@@ -116,7 +116,7 @@ export async function pExpectedErrorString<ERR = Error>(
116
116
  errorClass?: Class<ERR>,
117
117
  ): Promise<string> {
118
118
  const err = await pExpectedError<ERR>(promise, errorClass)
119
- return _stringifyAny(err)
119
+ return _stringify(err)
120
120
  }
121
121
 
122
122
  /**
@@ -127,5 +127,5 @@ export function _expectedErrorString<ERR = Error>(
127
127
  errorClass?: Class<ERR>,
128
128
  ): string {
129
129
  const err = _expectedError<ERR>(fn, errorClass)
130
- return _stringifyAny(err)
130
+ return _stringify(err)
131
131
  }
@@ -25,7 +25,7 @@ import {
25
25
  import { pDelay } from '../promise/pDelay'
26
26
  import { pTimeout } from '../promise/pTimeout'
27
27
  import { _jsonParse, _jsonParseIfPossible } from '../string/json.util'
28
- import { _stringifyAny } from '../string/stringifyAny'
28
+ import { _stringify } from '../string/stringify'
29
29
  import { _ms, _since } from '../time/time.util'
30
30
  import { ErrorDataTuple, NumberOfMilliseconds } from '../types'
31
31
  import type {
@@ -504,7 +504,7 @@ export class Fetcher {
504
504
  .filter(Boolean)
505
505
  .join(' ') + '\n',
506
506
  // We're stringifying the error here, otherwise Sentry shows it as [object Object]
507
- _stringifyAny(res.err.cause || res.err),
507
+ _stringify(res.err.cause || res.err),
508
508
  )
509
509
  }
510
510
 
package/src/index.ts CHANGED
@@ -50,7 +50,7 @@ export * from './string/string.util'
50
50
  export * from './string/readingTime'
51
51
  export * from './string/escape'
52
52
  export * from './string/pupa'
53
- export * from './string/stringifyAny'
53
+ export * from './string/stringify'
54
54
  export * from './time/time.util'
55
55
  export * from './is.util'
56
56
  export * from './typeFest'
@@ -11,7 +11,7 @@ let globalStringifyFunction: JsonStringifyFunction = _safeJsonStringify
11
11
  * Allows to set Global "stringifyFunction" that will be used to "pretty-print" objects
12
12
  * in various cases.
13
13
  *
14
- * Used, for example, by _stringifyAny() to pretty-print objects/arrays.
14
+ * Used, for example, by _stringify() to pretty-print objects/arrays.
15
15
  *
16
16
  * Defaults to _safeJsonStringify.
17
17
  *
@@ -26,7 +26,7 @@ export function setGlobalStringifyFunction(fn: JsonStringifyFunction): void {
26
26
 
27
27
  export type JsonStringifyFunction = (obj: any, reviver?: Reviver, space?: number) => string
28
28
 
29
- export interface StringifyAnyOptions {
29
+ export interface StringifyOptions {
30
30
  /**
31
31
  * @default 10_000
32
32
  * Default limit is less than in Node, cause it's likely to be used e.g in Browser alert()
@@ -64,13 +64,13 @@ export interface StringifyAnyOptions {
64
64
  }
65
65
 
66
66
  /**
67
- * Inspired by inspectAny from nodejs-lib, which is based on util.inpect that is not available in the Browser.
67
+ * Inspired by `_inspect` from nodejs-lib, which is based on util.inpect that is not available in the Browser.
68
68
  * Potentially can do this (with extra 2Kb gz size): https://github.com/deecewan/browser-util-inspect
69
69
  *
70
70
  * Transforms ANY to human-readable string (via JSON.stringify pretty).
71
71
  * Safe (no error throwing).
72
72
  *
73
- * Correclty prints Errors, AppErrors, ErrorObjects: error.message + \n + stringifyAny(error.data)
73
+ * Correctly prints Errors, AppErrors, ErrorObjects: error.message + \n + _stringify(error.data)
74
74
  *
75
75
  * Enforces max length (default to 1000, pass 0 to skip it).
76
76
  *
@@ -81,7 +81,7 @@ export interface StringifyAnyOptions {
81
81
  * Returns 'empty_string' if empty string is passed.
82
82
  * Returns 'undefined' if undefined is passed (default util.inspect behavior).
83
83
  */
84
- export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
84
+ export function _stringify(obj: any, opt: StringifyOptions = {}): string {
85
85
  if (obj === undefined) return 'undefined'
86
86
  if (obj === null) return 'null'
87
87
  if (typeof obj === 'function') return 'function'
@@ -96,7 +96,7 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
96
96
  // HttpErrorResponse
97
97
  //
98
98
  if (_isBackendErrorResponseObject(obj)) {
99
- return _stringifyAny(obj.error, opt)
99
+ return _stringify(obj.error, opt)
100
100
  }
101
101
 
102
102
  if (obj instanceof Error || _isErrorLike(obj)) {
@@ -123,7 +123,7 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
123
123
  }
124
124
 
125
125
  if (opt.includeErrorData && _isErrorObject(obj) && Object.keys(obj.data).length) {
126
- s += '\n' + _stringifyAny(obj.data, opt)
126
+ s += '\n' + _stringify(obj.data, opt)
127
127
  }
128
128
 
129
129
  if (opt.includeErrorStack && obj.stack) {
@@ -141,12 +141,12 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
141
141
  s = [
142
142
  s,
143
143
  `${obj.errors.length} error(s):`,
144
- ...obj.errors.map((err, i) => `${i + 1}. ${_stringifyAny(err, opt)}`),
144
+ ...obj.errors.map((err, i) => `${i + 1}. ${_stringify(err, opt)}`),
145
145
  ].join('\n')
146
146
  }
147
147
 
148
148
  if (obj.cause && includeErrorCause) {
149
- s = s + '\nCaused by: ' + _stringifyAny(obj.cause, opt)
149
+ s = s + '\nCaused by: ' + _stringify(obj.cause, opt)
150
150
  }
151
151
  } else if (typeof obj === 'string') {
152
152
  //
@@ -178,3 +178,8 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
178
178
 
179
179
  return s
180
180
  }
181
+
182
+ /**
183
+ * @deprecated renamed to _stringify
184
+ */
185
+ export const _stringifyAny = _stringify
@@ -1,5 +1,5 @@
1
1
  import { ZodError, ZodSchema, ZodIssue } from 'zod'
2
- import { _stringifyAny } from '../string/stringifyAny'
2
+ import { _stringify } from '../string/stringify'
3
3
 
4
4
  export interface ZodErrorResult<T> {
5
5
  success: false
@@ -71,7 +71,7 @@ export class ZodValidationError<T> extends ZodError<T> {
71
71
  `Invalid ${objectTitle}`,
72
72
  '',
73
73
  'Input:',
74
- _stringifyAny(this.value),
74
+ _stringify(this.value),
75
75
  this.issues.length > 1 ? `\n${this.issues.length} issues:` : '',
76
76
  ...this.issues.slice(0, 100).map(i => {
77
77
  return [i.path.join('.'), i.message].filter(Boolean).join(': ')