@zelgadis87/utils-core 5.1.3 → 5.1.5

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
@@ -739,15 +739,19 @@ function produceableToValue(t) {
739
739
  }
740
740
 
741
741
  // src/utils/errors/withTryCatch.ts
742
- function withTryCatch(fn, errMapFn) {
742
+ function withTryCatch(fn, errMapFn = identity) {
743
743
  try {
744
744
  return [fn(), void 0];
745
745
  } catch (e) {
746
- return [void 0, (errMapFn ?? identity)(asError(e))];
746
+ return [void 0, errMapFn(asError(e))];
747
747
  }
748
748
  }
749
- async function withTryCatchAsync(fn, errMapFn) {
750
- return fn().then((value) => [value, void 0], (e) => [void 0, (errMapFn ?? identity)(asError(e))]);
749
+ async function withTryCatchAsync(fn, errMapFn = identity) {
750
+ try {
751
+ return [await fn(), void 0];
752
+ } catch (e) {
753
+ return [void 0, errMapFn(asError(e))];
754
+ }
751
755
  }
752
756
 
753
757
  // src/utils/errors.ts
@@ -781,7 +785,13 @@ caused by: ${maybeCause}` : "";
781
785
 
782
786
  // src/utils/json.ts
783
787
  function tryToParseJson(jsonContent) {
784
- return withTryCatch(() => JSON.parse(jsonContent));
788
+ return withTryCatch(() => parseJson(jsonContent));
789
+ }
790
+ function parseJson(jsonContent) {
791
+ return JSON.parse(jsonContent);
792
+ }
793
+ function stringifyJson(jsonSerializable, minify = false) {
794
+ return JSON.stringify(jsonSerializable, void 0, minify ? 2 : void 0);
785
795
  }
786
796
  function jsonCloneDeep(a) {
787
797
  if (null === a || "object" !== typeof a) return a;
@@ -1128,6 +1138,15 @@ function pluralize(n, singular, plural) {
1128
1138
  function isNullOrUndefinedOrEmpty(source) {
1129
1139
  return isNullOrUndefined(source) || source.length === 0;
1130
1140
  }
1141
+ function wrapWithString(str, start, end = start) {
1142
+ if (isNullOrUndefinedOrEmpty(str))
1143
+ throw new Error(`Expected string to be non-empty, got: "${str}"`);
1144
+ if (isNullOrUndefinedOrEmpty(start))
1145
+ throw new Error(`Expected start delimiter to be non-empty, got: "${start}"`);
1146
+ if (isNullOrUndefinedOrEmpty(end))
1147
+ throw new Error(`Expected end delimiter to be non-empty, got: "${end}"`);
1148
+ return start + str + end;
1149
+ }
1131
1150
 
1132
1151
  // src/lazy/Lazy.ts
1133
1152
  var Lazy = class _Lazy {
@@ -2842,6 +2861,7 @@ export {
2842
2861
  pad,
2843
2862
  padLeft,
2844
2863
  padRight,
2864
+ parseJson,
2845
2865
  partition,
2846
2866
  pick,
2847
2867
  pipedInvoke,
@@ -2864,6 +2884,7 @@ export {
2864
2884
  sortedArray,
2865
2885
  splitWords,
2866
2886
  stringToNumber,
2887
+ stringifyJson,
2867
2888
  sum,
2868
2889
  sumArrayBy,
2869
2890
  sumBy,
@@ -2879,6 +2900,7 @@ export {
2879
2900
  upsert,
2880
2901
  withTryCatch,
2881
2902
  withTryCatchAsync,
2903
+ wrapWithString,
2882
2904
  xor
2883
2905
  };
2884
2906
  //# sourceMappingURL=index.mjs.map