corexxx 1.0.117 → 1.0.118

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.
@@ -0,0 +1,21 @@
1
+ export declare namespace dfunction {
2
+ type FuncWithFallback<T> = {
3
+ (defaultValue: T): T;
4
+ };
5
+ /************************* Function will encapsulte exception ----
6
+ *
7
+ * // Example usage
8
+ function divide(a: number, b: number): number {
9
+ if (b === 0) {
10
+ throw new Error("Division by zero");
11
+ }
12
+ return a / b;
13
+ }
14
+
15
+ const safeDivide = withTryCatch(() => divide(10, 0), -1);
16
+ const result = safeDivide(42);
17
+
18
+ */
19
+ export function withTryCatch<T>(func: () => T, defaultValue: T): FuncWithFallback<T>;
20
+ export {};
21
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dfunction = void 0;
4
+ var dfunction;
5
+ (function (dfunction) {
6
+ /************************* Function will encapsulte exception ----
7
+ *
8
+ * // Example usage
9
+ function divide(a: number, b: number): number {
10
+ if (b === 0) {
11
+ throw new Error("Division by zero");
12
+ }
13
+ return a / b;
14
+ }
15
+
16
+ const safeDivide = withTryCatch(() => divide(10, 0), -1);
17
+ const result = safeDivide(42);
18
+
19
+ */
20
+ function withTryCatch(func, defaultValue) {
21
+ return (fallbackValue) => {
22
+ try {
23
+ return func();
24
+ }
25
+ catch (error) {
26
+ console.error("An error occurred:", error);
27
+ return fallbackValue;
28
+ }
29
+ };
30
+ }
31
+ dfunction.withTryCatch = withTryCatch;
32
+ })(dfunction = exports.dfunction || (exports.dfunction = {}));
33
+ //# sourceMappingURL=dfunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dfunction.js","sourceRoot":"","sources":["../src/dfunction.ts"],"names":[],"mappings":";;;AAAA,IAAiB,SAAS,CA+BzB;AA/BD,WAAiB,SAAS;IAMtB;;;;;;;;;;;;;OAaG;IACH,SAAgB,YAAY,CAAI,IAAa,EAAE,YAAe;QAC1D,OAAO,CAAC,aAAgB,EAAE,EAAE;YACxB,IAAI;gBACA,OAAO,IAAI,EAAE,CAAC;aACjB;YAAC,OAAO,KAAK,EAAE;gBACZ,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;gBAC3C,OAAO,aAAa,CAAC;aACxB;QACL,CAAC,CAAC;IACN,CAAC;IATe,sBAAY,eAS3B,CAAA;AAEL,CAAC,EA/BgB,SAAS,GAAT,iBAAS,KAAT,iBAAS,QA+BzB"}
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./dcookie";
6
6
  export * from "./dcrypto";
7
7
  export * from "./ddebug";
8
8
  export * from "./dformat";
9
+ export * from "./dfunction";
9
10
  export * from "./dlog";
10
11
  export * from "./dmarge";
11
12
  export * from "./dnetwork";
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ __exportStar(require("./dcookie"), exports);
19
19
  __exportStar(require("./dcrypto"), exports);
20
20
  __exportStar(require("./ddebug"), exports);
21
21
  __exportStar(require("./dformat"), exports);
22
+ __exportStar(require("./dfunction"), exports);
22
23
  __exportStar(require("./dlog"), exports);
23
24
  __exportStar(require("./dmarge"), exports);
24
25
  __exportStar(require("./dnetwork"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA8C;AAC9C,4CAA0B;AAC1B,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B;AAC1B,4CAA0B;AAC1B,2CAAyB;AACzB,4CAA0B;AAC1B,yCAAuB;AACvB,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,4CAA0B;AAC1B,0CAAwB;AACxB,2CAAyB;AACzB,2CAAyB;AACzB,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B;AAE3B,oBAAoB;AACpB,uCAAuC;AACvC,uCAAuC;AACvC,yBAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA8C;AAC9C,4CAA0B;AAC1B,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B;AAC1B,4CAA0B;AAC1B,2CAAyB;AACzB,4CAA0B;AAC1B,8CAA4B;AAC5B,yCAAuB;AACvB,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,4CAA0B;AAC1B,0CAAwB;AACxB,2CAAyB;AACzB,2CAAyB;AACzB,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B;AAE3B,oBAAoB;AACpB,uCAAuC;AACvC,uCAAuC;AACvC,yBAAyB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corexxx",
3
- "version": "1.0.117",
3
+ "version": "1.0.118",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,32 @@
1
+ export namespace dfunction {
2
+
3
+ type FuncWithFallback<T> = {
4
+ (defaultValue: T): T;
5
+ };
6
+
7
+ /************************* Function will encapsulte exception ----
8
+ *
9
+ * // Example usage
10
+ function divide(a: number, b: number): number {
11
+ if (b === 0) {
12
+ throw new Error("Division by zero");
13
+ }
14
+ return a / b;
15
+ }
16
+
17
+ const safeDivide = withTryCatch(() => divide(10, 0), -1);
18
+ const result = safeDivide(42);
19
+
20
+ */
21
+ export function withTryCatch<T>(func: () => T, defaultValue: T): FuncWithFallback<T> {
22
+ return (fallbackValue: T) => {
23
+ try {
24
+ return func();
25
+ } catch (error) {
26
+ console.error("An error occurred:", error);
27
+ return fallbackValue;
28
+ }
29
+ };
30
+ }
31
+
32
+ }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./dcookie";
7
7
  export * from "./dcrypto";
8
8
  export * from "./ddebug";
9
9
  export * from "./dformat";
10
+ export * from "./dfunction";
10
11
  export * from "./dlog";
11
12
  export * from "./dmarge";
12
13
  export * from "./dnetwork";