@zelgadis87/utils-core 5.1.4 → 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;
@@ -2851,6 +2861,7 @@ export {
2851
2861
  pad,
2852
2862
  padLeft,
2853
2863
  padRight,
2864
+ parseJson,
2854
2865
  partition,
2855
2866
  pick,
2856
2867
  pipedInvoke,
@@ -2873,6 +2884,7 @@ export {
2873
2884
  sortedArray,
2874
2885
  splitWords,
2875
2886
  stringToNumber,
2887
+ stringifyJson,
2876
2888
  sum,
2877
2889
  sumArrayBy,
2878
2890
  sumBy,