@zelgadis87/utils-core 5.1.4 → 5.2.0
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/Logger.d.ts +2 -1
- package/dist/Optional.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/errors/withTryCatch.d.ts +1 -1
- package/dist/utils/errors.d.ts +2 -0
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/strings.d.ts +2 -0
- package/esbuild/index.cjs +58 -15
- package/esbuild/index.cjs.map +2 -2
- package/esbuild/index.mjs +52 -15
- package/esbuild/index.mjs.map +2 -2
- package/package.json +1 -1
- package/src/Logger.ts +2 -1
- package/src/Optional.ts +6 -0
- package/src/utils/errors/withTryCatch.ts +8 -4
- package/src/utils/errors.ts +15 -6
- package/src/utils/json.ts +9 -1
- package/src/utils/strings.ts +10 -2
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
|
|
@@ -766,22 +770,34 @@ function isError(e) {
|
|
|
766
770
|
return e instanceof Error;
|
|
767
771
|
}
|
|
768
772
|
function getMessageFromError(error) {
|
|
769
|
-
|
|
770
|
-
const cause = maybeCause ? `
|
|
771
|
-
caused by: ${maybeCause}` : "";
|
|
772
|
-
return `${error.name}: ${error.message}${cause}`;
|
|
773
|
+
return `${error.name}: ${error.message}${getCauseMessageFromError(error.cause)}`;
|
|
773
774
|
}
|
|
774
775
|
function getStackFromError(error) {
|
|
775
|
-
const maybeCause = error.cause ? getStackFromError(asError(error.cause)) : null;
|
|
776
|
-
const cause = maybeCause ? `
|
|
777
|
-
caused by: ${maybeCause}` : "";
|
|
778
776
|
const stack = error.stack && error.stack.includes(error.message) ? error.stack : error.message + " " + (error.stack ?? "");
|
|
779
|
-
return `${error.name}: ${stack}${cause}`;
|
|
777
|
+
return `${error.name}: ${stack}${getCauseStackFromError(error.cause)}`;
|
|
778
|
+
}
|
|
779
|
+
function getCauseMessageFromError(cause) {
|
|
780
|
+
if (isNullOrUndefined(cause))
|
|
781
|
+
return "";
|
|
782
|
+
return `
|
|
783
|
+
caused by: ${getMessageFromError(asError(cause))}`;
|
|
784
|
+
}
|
|
785
|
+
function getCauseStackFromError(cause) {
|
|
786
|
+
if (isNullOrUndefined(cause))
|
|
787
|
+
return "";
|
|
788
|
+
return `
|
|
789
|
+
caused by: ${getStackFromError(asError(cause))}`;
|
|
780
790
|
}
|
|
781
791
|
|
|
782
792
|
// src/utils/json.ts
|
|
783
793
|
function tryToParseJson(jsonContent) {
|
|
784
|
-
return withTryCatch(() =>
|
|
794
|
+
return withTryCatch(() => parseJson(jsonContent));
|
|
795
|
+
}
|
|
796
|
+
function parseJson(jsonContent) {
|
|
797
|
+
return JSON.parse(jsonContent);
|
|
798
|
+
}
|
|
799
|
+
function stringifyJson(jsonSerializable, minify = false) {
|
|
800
|
+
return JSON.stringify(jsonSerializable, void 0, minify ? void 0 : 2);
|
|
785
801
|
}
|
|
786
802
|
function jsonCloneDeep(a) {
|
|
787
803
|
if (null === a || "object" !== typeof a) return a;
|
|
@@ -1125,8 +1141,14 @@ function pluralize(n, singular, plural) {
|
|
|
1125
1141
|
}
|
|
1126
1142
|
return plural;
|
|
1127
1143
|
}
|
|
1144
|
+
function isString(source) {
|
|
1145
|
+
return isDefined(source) && typeof source === "string";
|
|
1146
|
+
}
|
|
1147
|
+
function isEmpty(source) {
|
|
1148
|
+
return source.trim().length === 0;
|
|
1149
|
+
}
|
|
1128
1150
|
function isNullOrUndefinedOrEmpty(source) {
|
|
1129
|
-
return isNullOrUndefined(source) || source
|
|
1151
|
+
return isNullOrUndefined(source) || isEmpty(source);
|
|
1130
1152
|
}
|
|
1131
1153
|
function wrapWithString(str, start, end = start) {
|
|
1132
1154
|
if (isNullOrUndefinedOrEmpty(str))
|
|
@@ -2068,7 +2090,7 @@ function isTimeInstant(x) {
|
|
|
2068
2090
|
var TimeInstant_default = TimeInstant;
|
|
2069
2091
|
|
|
2070
2092
|
// src/Logger.ts
|
|
2071
|
-
var LEVELS = ["log", "debug", "info", "warn", "error"];
|
|
2093
|
+
var LEVELS = ["trace", "log", "debug", "info", "warn", "error"];
|
|
2072
2094
|
var timestamp = () => TimeInstant_default.now().format("HH:mm:ss");
|
|
2073
2095
|
var Logger = class {
|
|
2074
2096
|
constructor(name, args) {
|
|
@@ -2080,6 +2102,9 @@ var Logger = class {
|
|
|
2080
2102
|
enabled = true;
|
|
2081
2103
|
console;
|
|
2082
2104
|
minLevel;
|
|
2105
|
+
get trace() {
|
|
2106
|
+
return this.logWrap("trace");
|
|
2107
|
+
}
|
|
2083
2108
|
get log() {
|
|
2084
2109
|
return this.logWrap("log");
|
|
2085
2110
|
}
|
|
@@ -2152,6 +2177,12 @@ var Optional = class _Optional {
|
|
|
2152
2177
|
if (this.isPresent())
|
|
2153
2178
|
callback(this.get());
|
|
2154
2179
|
}
|
|
2180
|
+
ifPresentThenClear(callback) {
|
|
2181
|
+
if (this.isPresent()) {
|
|
2182
|
+
callback(this.get());
|
|
2183
|
+
this.clear();
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2155
2186
|
apply(callbackIfPresent, callbackIfEmpty) {
|
|
2156
2187
|
if (this.isEmpty()) {
|
|
2157
2188
|
callbackIfEmpty();
|
|
@@ -2792,6 +2823,8 @@ export {
|
|
|
2792
2823
|
filterWithTypePredicate,
|
|
2793
2824
|
first,
|
|
2794
2825
|
flatMapTruthys,
|
|
2826
|
+
getCauseMessageFromError,
|
|
2827
|
+
getCauseStackFromError,
|
|
2795
2828
|
getMessageFromError,
|
|
2796
2829
|
getStackFromError,
|
|
2797
2830
|
groupByBoolean,
|
|
@@ -2820,6 +2853,7 @@ export {
|
|
|
2820
2853
|
isAllowedTimeDuration,
|
|
2821
2854
|
isArray,
|
|
2822
2855
|
isDefined,
|
|
2856
|
+
isEmpty,
|
|
2823
2857
|
isError,
|
|
2824
2858
|
isFalse,
|
|
2825
2859
|
isFunction,
|
|
@@ -2828,6 +2862,7 @@ export {
|
|
|
2828
2862
|
isNullOrUndefinedOrEmpty,
|
|
2829
2863
|
isNumber,
|
|
2830
2864
|
isPositiveNumber,
|
|
2865
|
+
isString,
|
|
2831
2866
|
isTimeInstant,
|
|
2832
2867
|
isTrue,
|
|
2833
2868
|
isUpgradable,
|
|
@@ -2851,6 +2886,7 @@ export {
|
|
|
2851
2886
|
pad,
|
|
2852
2887
|
padLeft,
|
|
2853
2888
|
padRight,
|
|
2889
|
+
parseJson,
|
|
2854
2890
|
partition,
|
|
2855
2891
|
pick,
|
|
2856
2892
|
pipedInvoke,
|
|
@@ -2873,6 +2909,7 @@ export {
|
|
|
2873
2909
|
sortedArray,
|
|
2874
2910
|
splitWords,
|
|
2875
2911
|
stringToNumber,
|
|
2912
|
+
stringifyJson,
|
|
2876
2913
|
sum,
|
|
2877
2914
|
sumArrayBy,
|
|
2878
2915
|
sumBy,
|