@zelgadis87/utils-core 5.0.1 → 5.0.2

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/esbuild/index.mjs CHANGED
@@ -479,6 +479,25 @@ function iff(firstPredicate, valueIfTrue) {
479
479
  }
480
480
  }
481
481
 
482
+ // src/utils/functions/predicateBuilder.ts
483
+ var PredicateBuilder = class {
484
+ _currentPredicate = constantTrue;
485
+ and(predicate) {
486
+ const curPredicate = this._currentPredicate.bind(void 0);
487
+ const newPredicate = (t) => curPredicate(t) && predicate(t);
488
+ this._currentPredicate = newPredicate;
489
+ return this;
490
+ }
491
+ or(predicate) {
492
+ const newPredicate = (t) => this._currentPredicate(t) || predicate(t);
493
+ this._currentPredicate = newPredicate;
494
+ return this;
495
+ }
496
+ toPredicate() {
497
+ return this._currentPredicate;
498
+ }
499
+ };
500
+
482
501
  // src/utils/functions.ts
483
502
  function isFunction(t) {
484
503
  return typeof t === "function";
@@ -729,6 +748,19 @@ function asError(e) {
729
748
  function isError(e) {
730
749
  return e instanceof Error;
731
750
  }
751
+ function printErrorMessage(error) {
752
+ const maybeCause = error.cause ? printErrorMessage(asError(error.cause)) : null;
753
+ const cause = maybeCause ? `
754
+ caused by: ${maybeCause}` : "";
755
+ return `${error.name}: ${error.message}${cause}`;
756
+ }
757
+ function printErrorStack(error) {
758
+ const maybeCause = error.cause ? printErrorStack(asError(error.cause)) : null;
759
+ const cause = maybeCause ? `
760
+ caused by: ${maybeCause}` : "";
761
+ const stack = error.stack && error.stack.includes(error.message) ? error.stack : error.message + " " + (error.stack ?? "");
762
+ return `${error.name}: ${stack}${cause}`;
763
+ }
732
764
 
733
765
  // src/utils/json.ts
734
766
  function tryToParseJson(jsonContent) {
@@ -2614,6 +2646,7 @@ export {
2614
2646
  Logger,
2615
2647
  NEVER,
2616
2648
  Optional,
2649
+ PredicateBuilder,
2617
2650
  RandomTimeDuration,
2618
2651
  RateThrottler,
2619
2652
  Semaphore,
@@ -2727,6 +2760,8 @@ export {
2727
2760
  pipedInvoke,
2728
2761
  pipedInvokeFromArray,
2729
2762
  pluralize,
2763
+ printErrorMessage,
2764
+ printErrorStack,
2730
2765
  promiseSequence,
2731
2766
  randomId,
2732
2767
  randomNumberInInterval,