@zelgadis87/utils-core 5.0.0 → 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) {
@@ -1214,6 +1246,31 @@ var LazyAsync = class _LazyAsync {
1214
1246
  }
1215
1247
  };
1216
1248
 
1249
+ // src/lazy/LazyDictionary.ts
1250
+ var LazyDictionary = class _LazyDictionary {
1251
+ constructor(_generator) {
1252
+ this._generator = _generator;
1253
+ }
1254
+ _dictionary = {};
1255
+ static of(generator) {
1256
+ return new _LazyDictionary(generator);
1257
+ }
1258
+ getOrCreate(key) {
1259
+ if (key in this._dictionary) {
1260
+ return this._dictionary[key];
1261
+ }
1262
+ const value = this._generator(key);
1263
+ this._dictionary[key] = value;
1264
+ return value;
1265
+ }
1266
+ getOrThrow(key, errorMessage) {
1267
+ if (key in this._dictionary) {
1268
+ return this._dictionary[key];
1269
+ }
1270
+ throw new Error(errorMessage);
1271
+ }
1272
+ };
1273
+
1217
1274
  // src/time/TimeInstant.ts
1218
1275
  var import_small_date = __toESM(require_lib());
1219
1276
 
@@ -2585,9 +2642,11 @@ export {
2585
2642
  ErrorSetEmptyOptional,
2586
2643
  Lazy,
2587
2644
  LazyAsync,
2645
+ LazyDictionary,
2588
2646
  Logger,
2589
2647
  NEVER,
2590
2648
  Optional,
2649
+ PredicateBuilder,
2591
2650
  RandomTimeDuration,
2592
2651
  RateThrottler,
2593
2652
  Semaphore,
@@ -2701,6 +2760,8 @@ export {
2701
2760
  pipedInvoke,
2702
2761
  pipedInvokeFromArray,
2703
2762
  pluralize,
2763
+ printErrorMessage,
2764
+ printErrorStack,
2704
2765
  promiseSequence,
2705
2766
  randomId,
2706
2767
  randomNumberInInterval,