@baklavabg/common-ts 1.0.2 → 1.0.4
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/tryCatchDecorator.d.ts.map +1 -1
- package/dist/utils/tryCatchDecorator.js +1 -0
- package/dist/utils/tryCatchDecorator.js.map +1 -1
- package/dist/utils/tryCatchSafeDecorator.d.ts +2 -0
- package/dist/utils/tryCatchSafeDecorator.d.ts.map +1 -0
- package/dist/utils/tryCatchSafeDecorator.js +37 -0
- package/dist/utils/tryCatchSafeDecorator.js.map +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { print } from "./utils/log.utils.js";
|
|
|
4
4
|
export { safe } from "./utils/tryCatchSafe.js";
|
|
5
5
|
export { loadFile } from "./utils/file.utils.js";
|
|
6
6
|
export { tryCatch } from "./utils/tryCatchDecorator.js";
|
|
7
|
+
export { TryCatch } from "./utils/tryCatchSafeDecorator.js";
|
|
7
8
|
export { equals, greaterThan, isEmpty, isEven, isNegative, isNotEmpty, isNull, isNullOrUndefined, isOdd, isPositive, isUndefined, isZero, lessThan, notEquals, } from "./safeExit/conditionHelpers.js";
|
|
8
9
|
export type { ConditionalResult } from "./safeExit/types.js";
|
|
9
10
|
export { createFolder } from "./utils/file.utils.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EACH,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,EACN,UAAU,EACV,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,KAAK,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,GACZ,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { print } from "./utils/log.utils.js";
|
|
|
3
3
|
export { safe } from "./utils/tryCatchSafe.js";
|
|
4
4
|
export { loadFile } from "./utils/file.utils.js";
|
|
5
5
|
export { tryCatch } from "./utils/tryCatchDecorator.js";
|
|
6
|
+
export { TryCatch } from "./utils/tryCatchSafeDecorator.js";
|
|
6
7
|
export { equals, greaterThan, isEmpty, isEven, isNegative, isNotEmpty, isNull, isNullOrUndefined, isOdd, isPositive, isUndefined, isZero, lessThan, notEquals, } from "./safeExit/conditionHelpers.js";
|
|
7
8
|
export { createFolder } from "./utils/file.utils.js";
|
|
8
9
|
export { formatDate, capitalize, randomString } from "./utils/tmp.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EACH,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,EACN,UAAU,EACV,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,KAAK,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,GACZ,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tryCatchDecorator.d.ts","sourceRoot":"","sources":["../../src/utils/tryCatchDecorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"tryCatchDecorator.d.ts","sourceRoot":"","sources":["../../src/utils/tryCatchDecorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIzD,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,IACjC,QAAQ,GAAG,EAAE,cAAc,MAAM,EAAE,YAAY,kBAAkB,wBAwCrF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tryCatchDecorator.js","sourceRoot":"","sources":["../../src/utils/tryCatchDecorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,6BAA6B;AAC7B,MAAM,UAAU,QAAQ,CAAC,UAA2B,EAAE;
|
|
1
|
+
{"version":3,"file":"tryCatchDecorator.js","sourceRoot":"","sources":["../../src/utils/tryCatchDecorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,6BAA6B;AAC7B,6BAA6B;AAC7B,MAAM,UAAU,QAAQ,CAAC,UAA2B,EAAE;IAClD,OAAO,UAAU,MAAW,EAAE,YAAoB,EAAE,UAA8B;QAC9E,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;YAC7C,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAEhD,qDAAqD;gBACrD,IAAI,MAA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C,EAAE,CAAC,IAC3F,GAAG,GAAG,EAAE,IAAI,MAAM,EAAE,YAAY,kBAAkB,wBAItE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// This file provides a decorator called TryCatch that can be used on class methods
|
|
2
|
+
// to automatically catch and handle errors. It wraps the method in a try-catch block,
|
|
3
|
+
// optionally prints errors and stack traces, and allows you to specify a custom return value
|
|
4
|
+
// if an error occurs. This helps prevent your application from crashing due to unexpected errors.
|
|
5
|
+
//
|
|
6
|
+
// Example usage:
|
|
7
|
+
// import { TryCatch } from "./tryCatchSafeDecorator";
|
|
8
|
+
//
|
|
9
|
+
// class MyClass {
|
|
10
|
+
// // This will NOT print error messages, WILL print stack trace, and returns "default value" on error
|
|
11
|
+
// @TryCatch(false, true, "default value")
|
|
12
|
+
// riskyMethod() {
|
|
13
|
+
// // code that might throw an error
|
|
14
|
+
// }
|
|
15
|
+
//
|
|
16
|
+
// // This will print error messages, NOT print stack trace, and returns undefined on error
|
|
17
|
+
// @TryCatch(true, false)
|
|
18
|
+
// anotherRiskyMethod() {
|
|
19
|
+
// // code that might throw an error
|
|
20
|
+
// }
|
|
21
|
+
// }
|
|
22
|
+
//
|
|
23
|
+
// The parameters are:
|
|
24
|
+
// printError (default: true) - whether to print error messages
|
|
25
|
+
// printStack (default: true) - whether to print the stack trace
|
|
26
|
+
// customReturn (default: undefined) - value to return if an error occurs
|
|
27
|
+
//
|
|
28
|
+
// See tryCatchSafe.ts for more details on parameter behavior.
|
|
29
|
+
// import { safe } from "./tryCatchSafe.js";
|
|
30
|
+
import { safe } from "../safeExit/safe.js";
|
|
31
|
+
export function TryCatch(printError = true, printStack = true, customReturn) {
|
|
32
|
+
return function (_, __, descriptor) {
|
|
33
|
+
descriptor.value = safe(descriptor.value, printError, printStack, customReturn);
|
|
34
|
+
return descriptor;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=tryCatchSafeDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tryCatchSafeDecorator.js","sourceRoot":"","sources":["../../src/utils/tryCatchSafeDecorator.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,sFAAsF;AACtF,6FAA6F;AAC7F,kGAAkG;AAClG,EAAE;AACF,iBAAiB;AACjB,sDAAsD;AACtD,EAAE;AACF,kBAAkB;AAClB,wGAAwG;AACxG,4CAA4C;AAC5C,oBAAoB;AACpB,wCAAwC;AACxC,MAAM;AACN,EAAE;AACF,6FAA6F;AAC7F,2BAA2B;AAC3B,2BAA2B;AAC3B,wCAAwC;AACxC,MAAM;AACN,IAAI;AACJ,EAAE;AACF,sBAAsB;AACtB,iEAAiE;AACjE,kEAAkE;AAClE,2EAA2E;AAC3E,EAAE;AACF,8DAA8D;AAC9D,4CAA4C;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,MAAM,UAAU,QAAQ,CAAgB,aAAsB,IAAI,EAAE,aAAsB,IAAI,EAAE,YAAgB;IAC5G,OAAO,UAAU,CAAM,EAAE,EAAU,EAAE,UAA8B;QAC/D,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,YAAmB,CAAC,CAAC;QACvF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baklavabg/common-ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A comprehensive TypeScript library with common utility functions and custom types",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "npm run clean && tsc",
|
|
10
10
|
"clean": "rm -rf ./dist",
|