@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/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/errors/withTryCatch.d.ts +1 -1
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/strings.d.ts +2 -2
- package/esbuild/index.cjs +30 -5
- package/esbuild/index.cjs.map +2 -2
- package/esbuild/index.mjs +27 -5
- package/esbuild/index.mjs.map +2 -2
- package/package.json +1 -1
- package/src/utils/errors/withTryCatch.ts +8 -4
- package/src/utils/json.ts +9 -1
- package/src/utils/strings.ts +3 -3
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,
|
|
746
|
+
return [void 0, errMapFn(asError(e))];
|
|
747
747
|
}
|
|
748
748
|
}
|
|
749
|
-
async function withTryCatchAsync(fn, errMapFn) {
|
|
750
|
-
|
|
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(() =>
|
|
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
|