@baklavabg/common-ts 1.0.2

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.
Files changed (58) hide show
  1. package/README.md +41 -0
  2. package/dist/index.d.ts +11 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +9 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/safeExit/conditionHelpers.d.ts +15 -0
  7. package/dist/safeExit/conditionHelpers.d.ts.map +1 -0
  8. package/dist/safeExit/conditionHelpers.js +16 -0
  9. package/dist/safeExit/conditionHelpers.js.map +1 -0
  10. package/dist/safeExit/reurnIf.d.ts +32 -0
  11. package/dist/safeExit/reurnIf.d.ts.map +1 -0
  12. package/dist/safeExit/reurnIf.js +56 -0
  13. package/dist/safeExit/reurnIf.js.map +1 -0
  14. package/dist/safeExit/safe.d.ts +11 -0
  15. package/dist/safeExit/safe.d.ts.map +1 -0
  16. package/dist/safeExit/safe.js +71 -0
  17. package/dist/safeExit/safe.js.map +1 -0
  18. package/dist/safeExit/types.d.ts +9 -0
  19. package/dist/safeExit/types.d.ts.map +1 -0
  20. package/dist/safeExit/types.js +10 -0
  21. package/dist/safeExit/types.js.map +1 -0
  22. package/dist/types/index.d.ts +21 -0
  23. package/dist/types/index.d.ts.map +1 -0
  24. package/dist/types/index.js +3 -0
  25. package/dist/types/index.js.map +1 -0
  26. package/dist/utils/file.utils.d.ts +5 -0
  27. package/dist/utils/file.utils.d.ts.map +1 -0
  28. package/dist/utils/file.utils.js +35 -0
  29. package/dist/utils/file.utils.js.map +1 -0
  30. package/dist/utils/log.utils.d.ts +12 -0
  31. package/dist/utils/log.utils.d.ts.map +1 -0
  32. package/dist/utils/log.utils.js +19 -0
  33. package/dist/utils/log.utils.js.map +1 -0
  34. package/dist/utils/searchAndFilter.d.ts +9 -0
  35. package/dist/utils/searchAndFilter.d.ts.map +1 -0
  36. package/dist/utils/searchAndFilter.js +20 -0
  37. package/dist/utils/searchAndFilter.js.map +1 -0
  38. package/dist/utils/tmp.d.ts +19 -0
  39. package/dist/utils/tmp.d.ts.map +1 -0
  40. package/dist/utils/tmp.js +36 -0
  41. package/dist/utils/tmp.js.map +1 -0
  42. package/dist/utils/tryCatchDecorator.d.ts +27 -0
  43. package/dist/utils/tryCatchDecorator.d.ts.map +1 -0
  44. package/dist/utils/tryCatchDecorator.js +63 -0
  45. package/dist/utils/tryCatchDecorator.js.map +1 -0
  46. package/dist/utils/tryCatchSafe.d.ts +12 -0
  47. package/dist/utils/tryCatchSafe.d.ts.map +1 -0
  48. package/dist/utils/tryCatchSafe.js +49 -0
  49. package/dist/utils/tryCatchSafe.js.map +1 -0
  50. package/dist/utils/typeChecks.d.ts +8 -0
  51. package/dist/utils/typeChecks.d.ts.map +1 -0
  52. package/dist/utils/typeChecks.js +43 -0
  53. package/dist/utils/typeChecks.js.map +1 -0
  54. package/dist/utils/user.utils.d.ts +3 -0
  55. package/dist/utils/user.utils.d.ts.map +1 -0
  56. package/dist/utils/user.utils.js +11 -0
  57. package/dist/utils/user.utils.js.map +1 -0
  58. package/package.json +59 -0
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # TypeScript Library With Example Javascript and Typescript Consumer Projects
2
+
3
+ There are three separate projects in this repo.
4
+ `common-ts` is a common library with typescript functions and types.
5
+ `project-js` and `project-ts` are examples how to use the library in a Javascript and Typescript project.
6
+ All three projects contain tests using `vitest`.
7
+
8
+ # Usage
9
+
10
+ ## 1. Setup the Library
11
+ `cd common-ts`
12
+ `npm install`
13
+ `npm run build`
14
+ `npm link`
15
+
16
+ -or-
17
+ `npm run relink`
18
+ `npm start`
19
+
20
+
21
+ ## 2. Run JavaScript Consumer
22
+ `cd project-js`
23
+ `npm link @baklavabg/common-ts`
24
+ `npm start`
25
+
26
+ -or-
27
+ `npm run relink`
28
+ `npm start`
29
+
30
+ ## 3. Run TypeScript Consumer
31
+ `cd project-ts`
32
+ `npm install`
33
+ `npm link @baklavabg/common-ts`
34
+ `npm start`
35
+
36
+ -or-
37
+ `npm run relink`
38
+ `npm start`
39
+
40
+ ## 4. Testing
41
+ Testing is implemented using vitest. For all three projects: `npm test`
@@ -0,0 +1,11 @@
1
+ export type { User1, User2 } from "./types/index.js";
2
+ export { formatUserName } from "./utils/user.utils.js";
3
+ export { print } from "./utils/log.utils.js";
4
+ export { safe } from "./utils/tryCatchSafe.js";
5
+ export { loadFile } from "./utils/file.utils.js";
6
+ export { tryCatch } from "./utils/tryCatchDecorator.js";
7
+ export { equals, greaterThan, isEmpty, isEven, isNegative, isNotEmpty, isNull, isNullOrUndefined, isOdd, isPositive, isUndefined, isZero, lessThan, notEquals, } from "./safeExit/conditionHelpers.js";
8
+ export type { ConditionalResult } from "./safeExit/types.js";
9
+ export { createFolder } from "./utils/file.utils.js";
10
+ export { formatDate, capitalize, randomString } from "./utils/tmp.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAExD,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 ADDED
@@ -0,0 +1,9 @@
1
+ export { formatUserName } from "./utils/user.utils.js";
2
+ export { print } from "./utils/log.utils.js";
3
+ export { safe } from "./utils/tryCatchSafe.js";
4
+ export { loadFile } from "./utils/file.utils.js";
5
+ export { tryCatch } from "./utils/tryCatchDecorator.js";
6
+ export { equals, greaterThan, isEmpty, isEven, isNegative, isNotEmpty, isNull, isNullOrUndefined, isOdd, isPositive, isUndefined, isZero, lessThan, notEquals, } from "./safeExit/conditionHelpers.js";
7
+ export { createFolder } from "./utils/file.utils.js";
8
+ export { formatDate, capitalize, randomString } from "./utils/tmp.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;AAExD,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"}
@@ -0,0 +1,15 @@
1
+ export declare const isNull: <T>(value: T | null) => value is null;
2
+ export declare const isUndefined: <T>(value: T | undefined) => value is undefined;
3
+ export declare const isNullOrUndefined: <T>(value: T | null | undefined) => value is null | undefined;
4
+ export declare const isEmpty: (value: string | any[]) => boolean;
5
+ export declare const isNotEmpty: (value: string | any[]) => boolean;
6
+ export declare const isEven: (value: number) => boolean;
7
+ export declare const isOdd: (value: number) => boolean;
8
+ export declare const isPositive: (value: number) => boolean;
9
+ export declare const isNegative: (value: number) => boolean;
10
+ export declare const isZero: (value: number) => boolean;
11
+ export declare const greaterThan: (threshold: number) => (value: number) => boolean;
12
+ export declare const lessThan: (threshold: number) => (value: number) => boolean;
13
+ export declare const equals: <T>(expected: T) => (value: T) => boolean;
14
+ export declare const notEquals: <T>(expected: T) => (value: T) => boolean;
15
+ //# sourceMappingURL=conditionHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditionHelpers.d.ts","sourceRoot":"","sources":["../../src/safeExit/conditionHelpers.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,KAAG,KAAK,IAAI,IAAsB,CAAA;AAC3E,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,SAAS,KAAG,KAAK,IAAI,SAAgC,CAAA;AAC/F,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,KAAG,KAAK,IAAI,IAAI,GAAG,SAAkD,CAAA;AACrI,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,GAAG,GAAG,EAAE,KAAG,OAA6B,CAAA;AAC7E,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,GAAG,GAAG,EAAE,KAAG,OAA2B,CAAA;AAC9E,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,KAAG,OAA0B,CAAA;AACjE,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,KAAG,OAA0B,CAAA;AAChE,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,OAAoB,CAAA;AAC/D,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,OAAoB,CAAA;AAC/D,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,KAAG,OAAsB,CAAA;AAC7D,eAAO,MAAM,WAAW,GACnB,WAAW,MAAM,MACjB,OAAO,MAAM,KAAG,OACI,CAAA;AACzB,eAAO,MAAM,QAAQ,GAChB,WAAW,MAAM,MACjB,OAAO,MAAM,KAAG,OACI,CAAA;AACzB,eAAO,MAAM,MAAM,GACd,CAAC,EAAE,UAAU,CAAC,MACd,OAAO,CAAC,KAAG,OACU,CAAA;AAC1B,eAAO,MAAM,SAAS,GACjB,CAAC,EAAE,UAAU,CAAC,MACd,OAAO,CAAC,KAAG,OACU,CAAA"}
@@ -0,0 +1,16 @@
1
+ // Helper condition functions
2
+ export const isNull = (value) => value === null;
3
+ export const isUndefined = (value) => value === undefined;
4
+ export const isNullOrUndefined = (value) => value === null || value === undefined;
5
+ export const isEmpty = (value) => value.length === 0;
6
+ export const isNotEmpty = (value) => value.length > 0;
7
+ export const isEven = (value) => value % 2 === 0;
8
+ export const isOdd = (value) => value % 2 !== 0;
9
+ export const isPositive = (value) => value > 0;
10
+ export const isNegative = (value) => value < 0;
11
+ export const isZero = (value) => value === 0;
12
+ export const greaterThan = (threshold) => (value) => value > threshold;
13
+ export const lessThan = (threshold) => (value) => value < threshold;
14
+ export const equals = (expected) => (value) => value === expected;
15
+ export const notEquals = (expected) => (value) => value !== expected;
16
+ //# sourceMappingURL=conditionHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditionHelpers.js","sourceRoot":"","sources":["../../src/safeExit/conditionHelpers.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,MAAM,CAAC,MAAM,MAAM,GAAG,CAAI,KAAe,EAAiB,EAAE,CAAC,KAAK,KAAK,IAAI,CAAA;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAI,KAAoB,EAAs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MAAM,SAAS,GAClB,CAAI,QAAW,EAAE,EAAE,CACnB,CAAC,KAAQ,EAAW,EAAE,CAClB,KAAK,KAAK,QAAQ,CAAA"}
@@ -0,0 +1,32 @@
1
+ import { type ConditionalResult } from "./types.js";
2
+ /**
3
+ * Returns early from a function if the condition passes
4
+ * @param condition Function that tests the value
5
+ * @param value Value to test
6
+ * @param logMessage Optional message to log if condition passes
7
+ * @param returnValue Value to return if condition passes (default: null)
8
+ */
9
+ export declare function returnIf<T, R = null>(condition: (value: T) => boolean, value: T, logMessage?: string, returnValue?: R): void;
10
+ /**
11
+ * Returns early from a function if the condition expression is true
12
+ * @param condition Boolean expression to evaluate
13
+ * @param logMessage Optional message to log if condition is true
14
+ * @param returnValue Value to return if condition is true (default: null)
15
+ */
16
+ export declare function returnIf<R = null>(condition: boolean, logMessage?: string, returnValue?: R): void;
17
+ /**
18
+ * Returns a result object if the condition passes
19
+ * @param condition Function that tests the value
20
+ * @param value Value to test
21
+ * @param returnValue Value to include in result if condition passes
22
+ * @param logMessage Optional message to log and include in result if condition passes
23
+ */
24
+ export declare function returnResultIf<T, R = any>(condition: (value: T) => boolean, value: T, returnValue?: R, logMessage?: string): ConditionalResult<R>;
25
+ /**
26
+ * Returns a result object if the condition expression is true
27
+ * @param condition Boolean expression to evaluate
28
+ * @param returnValue Value to include in result if condition is true
29
+ * @param logMessage Optional message to log and include in result if condition is true
30
+ */
31
+ export declare function returnResultIf<R = any>(condition: boolean, returnValue?: R, logMessage?: string): ConditionalResult<R>;
32
+ //# sourceMappingURL=reurnIf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reurnIf.d.ts","sourceRoot":"","sources":["../../src/safeExit/reurnIf.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAErE;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;AAC7H;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,GAAG,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;AA0BlG;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAA;AAClJ;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,56 @@
1
+ import { print } from "../utils/log.utils.js";
2
+ import { EarlyReturnError } from "./types.js";
3
+ export function returnIf(conditionOrValue, valueOrLogMessage, logMessageOrReturnValue, returnValue) {
4
+ let shouldReturn;
5
+ let actualReturnValue;
6
+ let actualLogMessage;
7
+ if (typeof conditionOrValue === "boolean") {
8
+ // Simple boolean condition overload
9
+ shouldReturn = conditionOrValue;
10
+ actualLogMessage = valueOrLogMessage;
11
+ actualReturnValue = logMessageOrReturnValue ?? null;
12
+ }
13
+ else {
14
+ // Function condition overload
15
+ shouldReturn = conditionOrValue(valueOrLogMessage);
16
+ actualLogMessage = logMessageOrReturnValue;
17
+ actualReturnValue = returnValue ?? null;
18
+ }
19
+ if (shouldReturn) {
20
+ if (actualLogMessage) {
21
+ print.yellow(actualLogMessage);
22
+ }
23
+ throw new EarlyReturnError(actualReturnValue, actualLogMessage);
24
+ }
25
+ }
26
+ export function returnResultIf(conditionOrValue, valueOrReturnValue, returnValueOrLogMessage, logMessage) {
27
+ let shouldReturn;
28
+ let actualReturnValue;
29
+ let actualLogMessage;
30
+ if (typeof conditionOrValue === "boolean") {
31
+ // Simple boolean condition overload
32
+ shouldReturn = conditionOrValue;
33
+ actualReturnValue = valueOrReturnValue;
34
+ actualLogMessage = returnValueOrLogMessage;
35
+ }
36
+ else {
37
+ // Function condition overload
38
+ shouldReturn = conditionOrValue(valueOrReturnValue);
39
+ actualReturnValue = returnValueOrLogMessage;
40
+ actualLogMessage = logMessage;
41
+ }
42
+ if (shouldReturn) {
43
+ if (actualLogMessage) {
44
+ print.yellow(actualLogMessage);
45
+ }
46
+ return {
47
+ value: actualReturnValue ?? null,
48
+ message: actualLogMessage ?? null,
49
+ };
50
+ }
51
+ return {
52
+ value: null,
53
+ message: null,
54
+ };
55
+ }
56
+ //# sourceMappingURL=reurnIf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reurnIf.js","sourceRoot":"","sources":["../../src/safeExit/reurnIf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAA0B,MAAM,YAAY,CAAA;AAiBrE,MAAM,UAAU,QAAQ,CAAc,gBAAmD,EAAE,iBAA8B,EAAE,uBAAoC,EAAE,WAAe;IAC5K,IAAI,YAAqB,CAAA;IACzB,IAAI,iBAA2B,CAAA;IAC/B,IAAI,gBAAoC,CAAA;IAExC,IAAI,OAAO,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACxC,oCAAoC;QACpC,YAAY,GAAG,gBAAgB,CAAA;QAC/B,gBAAgB,GAAG,iBAA2B,CAAA;QAC9C,iBAAiB,GAAI,uBAA6B,IAAI,IAAI,CAAA;IAC9D,CAAC;SAAM,CAAC;QACJ,8BAA8B;QAC9B,Y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param fn - The function to wrap
4
+ * @param printError - Whether to print regular errors (default: true)
5
+ * @param printStack - Whether to print stack trace for regular errors (default: true)
6
+ * @param defaultReturnValue - Default return value for regular errors (default: undefined)
7
+ * @param defaultErrorMsg - Default message for regular errors
8
+ * @param cbk - Optional callback for regular errors
9
+ */
10
+ export declare function safe<T extends (...args: any[]) => any>(fn: T, printError?: boolean, printStack?: boolean, defaultReturnValue?: any, defaultErrorMsg?: string, cbk?: (error: unknown) => void): (...args: Parameters<T>) => ReturnType<T> | typeof defaultReturnValue;
11
+ //# sourceMappingURL=safe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe.d.ts","sourceRoot":"","sources":["../../src/safeExit/safe.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrD,EAAE,EAAE,CAAC,EACL,UAAU,GAAE,OAAc,EAC1B,UAAU,GAAE,OAAc,EAC1B,kBAAkB,CAAC,EAAE,GAAG,EACxB,eAAe,CAAC,EAAE,MAAM,EACxB,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAC5B,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,kBAAkB,CA+DvE"}
@@ -0,0 +1,71 @@
1
+ import { print } from "../utils/log.utils.js";
2
+ import { EarlyReturnError } from "./types.js";
3
+ // @mii use this instead of the other function `safe`
4
+ /**
5
+ * Enhanced safe function that handles both regular errors and early returns
6
+ * @param fn - The function to wrap
7
+ * @param printError - Whether to print regular errors (default: true)
8
+ * @param printStack - Whether to print stack trace for regular errors (default: true)
9
+ * @param defaultReturnValue - Default return value for regular errors (default: undefined)
10
+ * @param defaultErrorMsg - Default message for regular errors
11
+ * @param cbk - Optional callback for regular errors
12
+ */
13
+ export function safe(fn, printError = true, printStack = true, defaultReturnValue, defaultErrorMsg, cbk) {
14
+ const getFileInfoFromStack = (stackTrace, functionName) => {
15
+ const lines = stackTrace.split("\n").map((line) => line.trim());
16
+ const fnLine = lines.find((line) => line.startsWith(`at ${functionName}`)) ||
17
+ lines.find((line) => /at .*:\d+:\d+/.test(line)) ||
18
+ lines[1] ||
19
+ "";
20
+ const regex = /at (?:\S+ \()?(.+):(\d+):(\d+)\)?$/;
21
+ const match = fnLine.match(regex);
22
+ if (match) {
23
+ const [, path, line, col] = match;
24
+ return `${path}:${line}:${col}`;
25
+ }
26
+ return "";
27
+ };
28
+ const handleRegularError = (e) => {
29
+ if (printError) {
30
+ let fileInfo = "";
31
+ if (e instanceof Error && e.stack) {
32
+ fileInfo = getFileInfoFromStack(e.stack, fn.name);
33
+ }
34
+ const errorMsg = defaultErrorMsg || `Exception in ${fn.name}()${fileInfo ? ` at ${fileInfo}` : ""}:`;
35
+ if (printStack && e instanceof Error) {
36
+ print.red(`${errorMsg}\n${e.stack}`);
37
+ }
38
+ else {
39
+ print.red(`${errorMsg} ${e}`);
40
+ }
41
+ }
42
+ if (cbk) {
43
+ cbk(e);
44
+ }
45
+ return defaultReturnValue;
46
+ };
47
+ const handleEarlyReturn = (e) => {
48
+ return e.returnValue;
49
+ };
50
+ return (...args) => {
51
+ try {
52
+ const result = fn(...args);
53
+ if (result && typeof result === "object" && "then" in result && typeof result.then === "function") {
54
+ return result.catch((e) => {
55
+ if (e instanceof EarlyReturnError) {
56
+ return handleEarlyReturn(e);
57
+ }
58
+ return handleRegularError(e);
59
+ });
60
+ }
61
+ return result;
62
+ }
63
+ catch (e) {
64
+ if (e instanceof EarlyReturnError) {
65
+ return handleEarlyReturn(e);
66
+ }
67
+ return handleRegularError(e);
68
+ }
69
+ };
70
+ }
71
+ //# sourceMappingURL=safe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe.js","sourceRoot":"","sources":["../../src/safeExit/safe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KA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,CAAC;YAED,OAAO,MAAM,CAAA;QACd,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACrB,IAAI,CAAC,YAAY,gBAAgB,EAAE,CAAC;gBACnC,OAAO,iBAAiB,CAAC,CAAC,CAAkB,CAAA;YAC7C,CAAC;YACD,OAAO,kBAAkB,CAAC,CAAC,CAAkB,CAAA;QAC9C,CAAC;IACF,CAAC,CAAA;AACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ export interface ConditionalResult<T = any> {
2
+ value: T | null;
3
+ message: string | null;
4
+ }
5
+ export declare class EarlyReturnError extends Error {
6
+ returnValue: any;
7
+ constructor(returnValue: any, message?: string);
8
+ }
9
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/safeExit/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,GAAG;IACtC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB;AAGD,qBAAa,gBAAiB,SAAQ,KAAK;IACpB,WAAW,EAAE,GAAG;gBAAhB,WAAW,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM;CAIxD"}
@@ -0,0 +1,10 @@
1
+ // Custom error class for early returns
2
+ export class EarlyReturnError extends Error {
3
+ returnValue;
4
+ constructor(returnValue, message) {
5
+ super(message || "Early return");
6
+ this.returnValue = returnValue;
7
+ this.name = "EarlyReturnError";
8
+ }
9
+ }
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/safeExit/types.ts"],"names":[],"mappings":"AAKA,uCAAuC;AACvC,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACpB;IAAnB,YAAmB,WAAgB,EAAE,OAAgB;QACjD,KAAK,CAAC,OAAO,IAAI,cAAc,CAAC,CAAA;QADjB,gBAAW,GAAX,WAAW,CAAK;QAE/B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAClC,CAAC;CACJ"}
@@ -0,0 +1,21 @@
1
+ export interface User1 {
2
+ id: number;
3
+ name: string;
4
+ email: string;
5
+ age?: number;
6
+ }
7
+ export interface User2 {
8
+ id: number;
9
+ name: string;
10
+ email: string;
11
+ age?: number;
12
+ additionalInfo: string;
13
+ }
14
+ export interface TryCatchOptions {
15
+ returnVal?: any;
16
+ logError?: boolean;
17
+ logStack?: boolean;
18
+ cbk?: (error?: Error) => any;
19
+ rethrow?: boolean;
20
+ }
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,KAAK;IAClB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,KAAK;IAClB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;CACzB;AAGD,MAAM,WAAW,eAAe;IAC5B,SAAS,CAAC,EAAE,GAAG,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,GAAG,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB"}
@@ -0,0 +1,3 @@
1
+ // Simple custom types for the POC
2
+ export {};
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,kCAAkC"}
@@ -0,0 +1,5 @@
1
+ export declare function loadFile(fullPath: string): string | null;
2
+ export declare function loadJson(fullPath: string): any;
3
+ export declare function saveJson(fullPath: string, json: object): string | null;
4
+ export declare function createFolder(fullPath: string): string;
5
+ //# sourceMappingURL=file.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.utils.d.ts","sourceRoot":"","sources":["../../src/utils/file.utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,iBAOxC;AACD,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAO9C;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKtE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMrD"}
@@ -0,0 +1,35 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ export function loadFile(fullPath) {
4
+ try {
5
+ const buffer = fs.readFileSync(fullPath);
6
+ return buffer.toString();
7
+ }
8
+ catch (error) {
9
+ return null;
10
+ }
11
+ }
12
+ export function loadJson(fullPath) {
13
+ try {
14
+ const buffer = fs.readFileSync(fullPath);
15
+ return JSON.parse(buffer.toString());
16
+ }
17
+ catch (error) {
18
+ return undefined;
19
+ }
20
+ }
21
+ export function saveJson(fullPath, json) {
22
+ if (!json)
23
+ return null;
24
+ const jsonStr = JSON.stringify(json, null, 4);
25
+ fs.writeFileSync(fullPath, jsonStr);
26
+ return fullPath;
27
+ }
28
+ export function createFolder(fullPath) {
29
+ const dir = path.dirname(fullPath);
30
+ if (!fs.existsSync(dir)) {
31
+ fs.mkdirSync(dir, { recursive: true });
32
+ }
33
+ return fullPath;
34
+ }
35
+ //# sourceMappingURL=file.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.utils.js","sourceRoot":"","sources":["../../src/utils/file.utils.ts"],"names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12 @@
1
+ export declare function printJson(json: object): void;
2
+ export declare function dumpJson(json: object): string | null;
3
+ export declare const print: {
4
+ red: (msg: string) => void;
5
+ green: (msg: string) => void;
6
+ yellow: (msg: string) => void;
7
+ blue: (msg: string) => void;
8
+ magenta: (msg: string) => void;
9
+ cyan: (msg: string) => void;
10
+ white: (msg: string) => void;
11
+ };
12
+ //# sourceMappingURL=log.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.utils.d.ts","sourceRoot":"","sources":["../../src/utils/log.utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,QAErC;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,iBAGpC;AAED,eAAO,MAAM,KAAK;eACN,MAAM;iBACJ,MAAM;kBACL,MAAM;gBACR,MAAM;mBACH,MAAM;gBACT,MAAM;iBACL,MAAM;CACnB,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { blue, cyan, green, magenta, red, white, yellow } from "console-log-colors";
2
+ export function printJson(json) {
3
+ console.log(JSON.stringify(json, null, 2));
4
+ }
5
+ export function dumpJson(json) {
6
+ if (!json)
7
+ return null;
8
+ return JSON.stringify(json, null, 2);
9
+ }
10
+ export const print = {
11
+ red: (msg) => console.log(red(msg)),
12
+ green: (msg) => console.log(green(msg)),
13
+ yellow: (msg) => console.log(yellow(msg)),
14
+ blue: (msg) => console.log(blue(msg)),
15
+ magenta: (msg) => console.log(magenta(msg)),
16
+ cyan: (msg) => console.log(cyan(msg)),
17
+ white: (msg) => console.log(white(msg)),
18
+ };
19
+ //# sourceMappingURL=log.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.utils.js","sourceRoot":"","sources":["../../src/utils/log.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEnF,MAAM,UAAU,SAAS,CAAC,IAAY;IACrC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY;IACpC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAA;IACtB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AACrC,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG;IACpB,GAAG,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3C,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjD,IAAI,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7C,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CAC/C,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Filters an array of strings based on the presence of a substring.
3
+ * @param {string[]} arr - The array of strings to filter.
4
+ * @param {string} substring - The substring to search for.
5
+ * @param {boolean} [isCaseSensitive=true] - Determines if the search is case-sensitive. Default is true.
6
+ * @returns {string[]} - An array of strings that contain the substring. */
7
+ export declare function searchArray(arr: string[], substring: string, isCaseSensitive?: boolean): any;
8
+ export declare function filterArray(arr: any[]): any;
9
+ //# sourceMappingURL=searchAndFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchAndFilter.d.ts","sourceRoot":"","sources":["../../src/utils/searchAndFilter.ts"],"names":[],"mappings":"AAAA;;;;;2EAK2E;AAC3E,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,UAAO,GAAG,GAAG,CAMzF;AAGD,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAI3C"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Filters an array of strings based on the presence of a substring.
3
+ * @param {string[]} arr - The array of strings to filter.
4
+ * @param {string} substring - The substring to search for.
5
+ * @param {boolean} [isCaseSensitive=true] - Determines if the search is case-sensitive. Default is true.
6
+ * @returns {string[]} - An array of strings that contain the substring. */
7
+ export function searchArray(arr, substring, isCaseSensitive = true) {
8
+ return arr.filter((element) => {
9
+ if (isCaseSensitive)
10
+ return element.includes(substring);
11
+ return element.toLowerCase().includes(substring.toLowerCase());
12
+ });
13
+ }
14
+ /* Filters an array by removing null, undefined, and empty arrays. */
15
+ export function filterArray(arr) {
16
+ return arr.filter((item) => {
17
+ return item !== null && item !== undefined && Array.isArray(item) ? item.length > 0 : true;
18
+ });
19
+ }
20
+ //# sourceMappingURL=searchAndFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchAndFilter.js","sourceRoot":"","sources":["../../src/utils/searchAndFilter.ts"],"names":[],"mappings":"AAAA;;;;;2EAK2E;AAC3E,MAAM,UAAU,WAAW,CAAC,GAAa,EAAE,SAAiB,EAAE,eAAe,GAAG,IAAI;IACnF,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,eAAe;YAAE,OAAO,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAEvD,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,CAAA;IAC/D,CAAC,CAAC,CAAA;AACH,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,WAAW,CAAC,GAAU;IACrC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC3F,CAAC,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Formats a date to YYYY-MM-DD format
3
+ */
4
+ export declare function formatDate(date: Date): string;
5
+ /**
6
+ * Capitalizes the first letter of a string
7
+ */
8
+ export declare function capitalize(text: string): string;
9
+ /**
10
+ * Generates a random string of specified length
11
+ */
12
+ export declare function randomString(length?: number): string;
13
+ declare const _default: {
14
+ formatDate: typeof formatDate;
15
+ capitalize: typeof capitalize;
16
+ randomString: typeof randomString;
17
+ };
18
+ export default _default;
19
+ //# sourceMappingURL=tmp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tmp.d.ts","sourceRoot":"","sources":["../../src/utils/tmp.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAK7C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,MAAU,GAAG,MAAM,CAOvD;;;;;;AAGD,wBAIE"}
@@ -0,0 +1,36 @@
1
+ // src/index.ts
2
+ /**
3
+ * Formats a date to YYYY-MM-DD format
4
+ */
5
+ export function formatDate(date) {
6
+ const year = date.getFullYear();
7
+ const month = String(date.getMonth() + 1).padStart(2, "0");
8
+ const day = String(date.getDate()).padStart(2, "0");
9
+ return `${year}-${month}-${day}`;
10
+ }
11
+ /**
12
+ * Capitalizes the first letter of a string
13
+ */
14
+ export function capitalize(text) {
15
+ if (!text)
16
+ return text;
17
+ return text.charAt(0).toUpperCase() + text.slice(1);
18
+ }
19
+ /**
20
+ * Generates a random string of specified length
21
+ */
22
+ export function randomString(length = 8) {
23
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
24
+ let result = "";
25
+ for (let i = 0; i < length; i++) {
26
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
27
+ }
28
+ return result;
29
+ }
30
+ // Export everything as a namespace as well
31
+ export default {
32
+ formatDate,
33
+ capitalize,
34
+ randomString,
35
+ };
36
+ //# sourceMappingURL=tmp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tmp.js","sourceRoot":"","sources":["../../src/utils/tmp.ts"],"names":[],"mappings":"AAAA,eAAe;AAEf;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAU;IACjC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACpD,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACnC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB,CAAC;IAC3C,MAAM,KAAK,GAAG,gEAAgE,CAAC;IAC/E,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,2CAA2C;AAC3C,eAAe;IACX,UAAU;IACV,UAAU;IACV,YAAY;CACf,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * This try/catch decorator automatically wraps your methods in try-catch blocks so you don't have to!
3
+ * Works with both sync and async functions automatically!
4
+ * Works only on methods, not on class constructors, static methods or standalone functions.
5
+ *
6
+ * Basic Usage (just catch errors and return null):
7
+ * @tryCatch()
8
+ * getUserData(id: string) { ... }
9
+ *
10
+ * Return something else when errors happen:
11
+ * @tryCatch({ returnVal: [] })
12
+ *
13
+ * Custom error handling:
14
+ * @tryCatch({ cbk: (error) => ({ success: false, error: error.message }) })
15
+ *
16
+ * Async function with async custom handler
17
+ @tryCatch({
18
+ cbk: async (_) => {
19
+ await new Promise((resolve) => setTimeout(resolve, 50))
20
+ return []
21
+ },
22
+ })
23
+ async getAllUsersAsync() { }
24
+ */
25
+ import type { TryCatchOptions } from "../types/index.js";
26
+ export declare function tryCatch(options?: TryCatchOptions): (target: any, propertyName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
27
+ //# sourceMappingURL=tryCatchDecorator.d.ts.map
@@ -0,0 +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,CAAA;AAGxD,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,IACpC,QAAQ,GAAG,EAAE,cAAc,MAAM,EAAE,YAAY,kBAAkB,wBAwClF"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * This try/catch decorator automatically wraps your methods in try-catch blocks so you don't have to!
3
+ * Works with both sync and async functions automatically!
4
+ * Works only on methods, not on class constructors, static methods or standalone functions.
5
+ *
6
+ * Basic Usage (just catch errors and return null):
7
+ * @tryCatch()
8
+ * getUserData(id: string) { ... }
9
+ *
10
+ * Return something else when errors happen:
11
+ * @tryCatch({ returnVal: [] })
12
+ *
13
+ * Custom error handling:
14
+ * @tryCatch({ cbk: (error) => ({ success: false, error: error.message }) })
15
+ *
16
+ * Async function with async custom handler
17
+ @tryCatch({
18
+ cbk: async (_) => {
19
+ await new Promise((resolve) => setTimeout(resolve, 50))
20
+ return []
21
+ },
22
+ })
23
+ async getAllUsersAsync() { }
24
+ */
25
+ // The main decorator factory
26
+ export function tryCatch(options = {}) {
27
+ return function (target, propertyName, descriptor) {
28
+ const originalMethod = descriptor.value;
29
+ descriptor.value = async function (...args) {
30
+ try {
31
+ const result = originalMethod.apply(this, args);
32
+ // Handle both synchronous and asynchronous functions
33
+ if (result instanceof Promise) {
34
+ return await result;
35
+ }
36
+ return result;
37
+ }
38
+ catch (error) {
39
+ // Log the error unless explicitly disabled
40
+ if (options.logError !== false) {
41
+ console.error(`❌ Error in ${target.constructor.name}.${propertyName}:`, error.message);
42
+ if (options.logStack === true && error.stack) {
43
+ console.error(error.stack);
44
+ }
45
+ }
46
+ // Use custom handler if provided
47
+ if (options.cbk) {
48
+ const handlerResult = options.cbk(error);
49
+ // Handle async custom handlers too
50
+ return handlerResult instanceof Promise ? await handlerResult : handlerResult;
51
+ }
52
+ // Rethrow after logging (useful for debugging while still propagating errors)
53
+ if (options.rethrow) {
54
+ throw error;
55
+ }
56
+ // Return fallback value or null
57
+ return options.returnVal ?? null;
58
+ }
59
+ };
60
+ return descriptor;
61
+ };
62
+ }
63
+ //# sourceMappingURL=tryCatchDecorator.js.map
@@ -0,0 +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;IACrD,OAAO,UAAU,MAAW,EAAE,YAAoB,EAAE,UAA8B;QACjF,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAA;QAEvC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;YAChD,IAAI,CAAC;gBACJ,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;gBAE/C,qDAAqD;gBACrD,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;oBAC/B,OAAO,MAAM,MAAM,CAAA;gBACpB,CAAC;gBACD,OAAO,MAAM,CAAA;YACd,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACrB,2CAA2C;gBAC3C,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;oBAChC,OAAO,CAAC,KAAK,CAAC,cAAc,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,YAAY,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;oBACtF,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;wBAC9C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;oBAC3B,CAAC;gBACF,CAAC;gBAED,iCAAiC;gBACjC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;oBACjB,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;oBACxC,mCAAmC;oBACnC,OAAO,aAAa,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,aAAa,CAAC,CAAC,CAAC,aAAa,CAAA;gBAC9E,CAAC;gBAED,8EAA8E;gBAC9E,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;oBACrB,MAAM,KAAK,CAAA;gBACZ,CAAC;gBAED,gCAAgC;gBAChC,OAAO,OAAO,CAAC,SAAS,IAAI,IAAI,CAAA;YACjC,CAAC;QACF,CAAC,CAAA;QAED,OAAO,UAAU,CAAA;IAClB,CAAC,CAAA;AACF,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Wraps a function to catch errors and return undefined instead of throwing.
3
+ * Optionally logs the error message and stack trace.
4
+ *
5
+ * function risky() { throw new Error("fail"); }
6
+
7
+ * const safeRisky = safe(risky); // prints error and stack
8
+ * const silentRisky = safe(risky, false); // no error printed
9
+ * const noStackRisky = safe(risky, true, false); // prints error, no stack
10
+ */
11
+ export declare function safe<T extends (...args: any[]) => any, C = null>(fn: T, printError?: boolean, printStack?: boolean, customReturn?: C): (...args: Parameters<T>) => ReturnType<T> | C;
12
+ //# sourceMappingURL=tryCatchSafe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tryCatchSafe.d.ts","sourceRoot":"","sources":["../../src/utils/tryCatchSafe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,wBAAgB,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,CAAC,GAAG,IAAI,EAC/D,EAAE,EAAE,CAAC,EACL,UAAU,GAAE,OAAc,EAC1B,UAAU,GAAE,OAAc,EAC1B,YAAY,GAAE,CAAa,GACzB,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAoC/C"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Wraps a function to catch errors and return undefined instead of throwing.
3
+ * Optionally logs the error message and stack trace.
4
+ *
5
+ * function risky() { throw new Error("fail"); }
6
+
7
+ * const safeRisky = safe(risky); // prints error and stack
8
+ * const silentRisky = safe(risky, false); // no error printed
9
+ * const noStackRisky = safe(risky, true, false); // prints error, no stack
10
+ */
11
+ import { print } from "./log.utils.js";
12
+ export function safe(fn, printError = true, printStack = true, customReturn = null) {
13
+ const getFileInfoFromStack = (stackTrace, functionName) => {
14
+ const lines = stackTrace.split("\n").map((line) => line.trim());
15
+ const fnLine = lines.find((line) => line.startsWith(`at ${functionName}`)) ||
16
+ lines.find((line) => /at .*:\d+:\d+/.test(line)) ||
17
+ lines[1] ||
18
+ "";
19
+ const regex = /at (?:\S+ \()?(.+):(\d+):(\d+)\)?$/; // captures the path:line:column after "at "
20
+ const match = fnLine.match(regex);
21
+ if (match) {
22
+ const [, path, line, col] = match;
23
+ return `${path}:${line}:${col}`;
24
+ }
25
+ return "";
26
+ };
27
+ return (...args) => {
28
+ try {
29
+ return fn(...args);
30
+ }
31
+ catch (e) {
32
+ if (printError) {
33
+ let fileInfo = "";
34
+ if (e instanceof Error && e.stack) {
35
+ fileInfo = getFileInfoFromStack(e.stack, fn.name);
36
+ }
37
+ const header = `Exception in ${fn.name}()${fileInfo ? ` at ${fileInfo}` : ""}:`;
38
+ if (printStack && e instanceof Error) {
39
+ print.red(`${header}\n${e.stack}`);
40
+ }
41
+ else {
42
+ print.red(`${header} ${e}`);
43
+ }
44
+ }
45
+ return customReturn;
46
+ }
47
+ };
48
+ }
49
+ //# sourceMappingURL=tryCatchSafe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tryCatchSafe.js","sourceRoot":"","sources":["../../src/utils/tryCatchSafe.ts"],"names":[],"mappings":"AAAA;;;;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,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;oBACnC,QAAQ,GAAG,oBAAoB,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,CAAA;gBAClD,CAAC;gBACD,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAA;gBAC/E,IAAI,UAAU,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;oBACtC,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAA;gBACnC,CAAC;qBAAM,CAAC;oBACP,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,CAAA;gBAC5B,CAAC;YACF,CAAC;YACD,OAAO,YAAY,CAAA;QACpB,CAAC;IACF,CAAC,CAAA;AACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare function isNullish(arg: any): boolean;
2
+ export declare function isString(arg: any): arg is string;
3
+ export declare function isNum(arg: any): arg is number;
4
+ export declare function isEmptyArray(arr: any): boolean;
5
+ export declare function isNonEmptyArray(arr: any): boolean;
6
+ export declare function isEmptyObject(obj: any): boolean;
7
+ export declare function objectsDeepEqual(obj1: any, obj2: any): boolean;
8
+ //# sourceMappingURL=typeChecks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeChecks.d.ts","sourceRoot":"","sources":["../../src/utils/typeChecks.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,WAEjC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,iBAEhC;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,iBAE7B;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,WAEpC;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,WAEvC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,WAMrC;AAGD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,WAsBpD"}
@@ -0,0 +1,43 @@
1
+ export function isNullish(arg) {
2
+ return arg === null || arg === undefined;
3
+ }
4
+ export function isString(arg) {
5
+ return typeof arg === "string";
6
+ }
7
+ export function isNum(arg) {
8
+ return typeof arg === "number";
9
+ }
10
+ export function isEmptyArray(arr) {
11
+ return Array.isArray(arr) && arr.length === 0;
12
+ }
13
+ export function isNonEmptyArray(arr) {
14
+ return Array.isArray(arr) && arr.length > 0;
15
+ }
16
+ export function isEmptyObject(obj) {
17
+ if (typeof obj !== "object" || obj === null) {
18
+ return false;
19
+ }
20
+ return Object.keys(obj).length === 0;
21
+ }
22
+ /* Checks if two objects are deeply equal */
23
+ export function objectsDeepEqual(obj1, obj2) {
24
+ if (obj1 === obj2)
25
+ return true;
26
+ if (isEmptyObject(obj1) && isEmptyObject(obj2))
27
+ return true;
28
+ if (typeof obj1 !== "object" || obj1 === null || typeof obj2 !== "object" || obj2 === null) {
29
+ return false;
30
+ }
31
+ const keys1 = Object.keys(obj1);
32
+ const keys2 = Object.keys(obj2);
33
+ if (keys1.length !== keys2.length) {
34
+ return false;
35
+ }
36
+ for (const key of keys1) {
37
+ if (!keys2.includes(key) || !objectsDeepEqual(obj1[key], obj2[key])) {
38
+ return false;
39
+ }
40
+ }
41
+ return true;
42
+ }
43
+ //# sourceMappingURL=typeChecks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeChecks.js","sourceRoot":"","sources":["../../src/utils/typeChecks.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAC,GAAQ;IACjC,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAQ;IAChC,OAAO,OAAO,GAAG,KAAK,QAAQ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b,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACrE,OAAO,KAAK,CAAA;QACb,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAA;AACZ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { User1, User2 } from "../types/index.js";
2
+ export declare function formatUserName(user: User1): User2;
3
+ //# sourceMappingURL=user.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.utils.d.ts","sourceRoot":"","sources":["../../src/utils/user.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAErD,wBAAgB,cAAc,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK,CAUjD"}
@@ -0,0 +1,11 @@
1
+ export function formatUserName(user) {
2
+ const formatted = {
3
+ id: user.id,
4
+ name: user.name.toUpperCase(),
5
+ email: user.email.toLowerCase(),
6
+ age: user.age ?? 0,
7
+ additionalInfo: "No additional info provided",
8
+ };
9
+ return formatted;
10
+ }
11
+ //# sourceMappingURL=user.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.utils.js","sourceRoot":"","sources":["../../src/utils/user.utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,IAAW;IACzC,MAAM,SAAS,GAAU;QACxB,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;QAC7B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;QAC/B,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;QAClB,cAAc,EAAE,6BAA6B;KAC7C,CAAA;IAED,OAAO,SAAS,CAAA;AACjB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@baklavabg/common-ts",
3
+ "version": "1.0.2",
4
+ "type": "module",
5
+ "description": "A comprehensive TypeScript library with common utility functions and custom types",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "npm run clean && tsc",
10
+ "clean": "rm -rf ./dist",
11
+ "dev": "tsc --watch",
12
+ "relink": "npm run build && npm link",
13
+ "prepublishOnly": "npm run build",
14
+ "cleanall": "npm run clean && rm -rf node_modules && rm package-lock.json",
15
+ "test": "vitest run",
16
+ "test:watch": "vitest",
17
+ "test:coverage": "vitest run --coverage",
18
+ "project:commit": "powershell -Command \"git add -A; git commit --all -m \\\"$((Get-Item (Get-Location)).Parent.Name)/$((Get-Item (Get-Location)).Name):$(Get-Date -Format 'yyyy-MM-dd_HH:mm:ss')\\\"; git push \"",
19
+ "project:commit:wsl": "git add -A && git commit -m \"$(basename $(dirname $(pwd)))/$(basename $(pwd)):$(date '+%Y-%m-%d_%H:%M:%S')\" && git push"
20
+ },
21
+ "author": "Your Name",
22
+ "license": "MIT",
23
+ "devDependencies": {
24
+ "@types/node": "^24.2.0",
25
+ "@vitest/coverage-v8": "^3.2.4",
26
+ "typescript": "^5.6.0",
27
+ "vitest": "^3.2.4"
28
+ },
29
+ "engines": {
30
+ "node": ">=18.0.0"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "local"
35
+ },
36
+ "dependencies": {
37
+ "console-log-colors": "^0.5.0"
38
+ },
39
+ "peerDependencies": {
40
+ "typescript": ">=5.0.0"
41
+ },
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/index.d.ts",
45
+ "import": "./dist/index.js",
46
+ "require": "./dist/index.js"
47
+ },
48
+ "./types": {
49
+ "types": "./dist/types/index.d.ts",
50
+ "import": "./dist/types/index.js",
51
+ "require": "./dist/types/index.js"
52
+ }
53
+ },
54
+ "files": [
55
+ "dist",
56
+ "README.md",
57
+ "LICENSE"
58
+ ]
59
+ }