vivth 1.3.7 → 1.4.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.
Files changed (34) hide show
  1. package/README.md +138 -6
  2. package/bun.lock +33 -33
  3. package/index.mjs +5 -1
  4. package/package.json +3 -3
  5. package/src/class/WorkerMainThread.mjs +2 -2
  6. package/src/class/WorkerMainThreadBundled.mjs +2 -2
  7. package/src/class/WorkerThread.mjs +2 -2
  8. package/src/common/Trace.mjs +1 -1
  9. package/src/common/TracePath.mjs +44 -0
  10. package/src/function/{Try.mjs → Tries.mjs} +3 -3
  11. package/src/function/TryAsyncCall.mjs +31 -0
  12. package/src/function/TryCall.mjs +29 -0
  13. package/src/function/TryNew.mjs +29 -0
  14. package/types/index.d.mts +5 -1
  15. package/types/src/bundler/FSInlineAnalyzer.d.mts +1 -1
  16. package/types/src/class/Console.d.mts +2 -2
  17. package/types/src/class/EventSignal.d.mts +1 -1
  18. package/types/src/class/LitExp.d.mts +2 -2
  19. package/types/src/class/Paths.d.mts +1 -1
  20. package/types/src/class/QChannel.d.mts +2 -2
  21. package/types/src/class/Signal.d.mts +1 -1
  22. package/types/src/class/WalkThrough.d.mts +1 -1
  23. package/types/src/class/WorkerMainThread.d.mts +3 -3
  24. package/types/src/class/WorkerMainThreadBundled.d.mts +3 -3
  25. package/types/src/class/WorkerThread.d.mts +2 -2
  26. package/types/src/common/Dev.d.mts +3 -3
  27. package/types/src/common/Trace.d.mts +1 -1
  28. package/types/src/common/TracePath.d.mts +22 -0
  29. package/types/src/doc/JSautoDOC.d.mts +1 -1
  30. package/types/src/doc/parsedFile.d.mts +1 -1
  31. package/types/src/function/{Try.d.mts → Tries.d.mts} +3 -3
  32. package/types/src/function/TryAsyncCall.d.mts +20 -0
  33. package/types/src/function/TryCall.d.mts +18 -0
  34. package/types/src/function/TryNew.d.mts +18 -0
package/README.md CHANGED
@@ -83,6 +83,7 @@ npm i vivth
83
83
  - [Dev](#dev)
84
84
  - [EventNameSpace](#eventnamespace)
85
85
  - [Trace](#trace)
86
+ - [TracePath](#tracepath)
86
87
  - [JSautoDOC](#jsautodoc)
87
88
  - [CreateImmutable](#createimmutable)
88
89
  - [EventCheck](#eventcheck)
@@ -92,8 +93,11 @@ npm i vivth
92
93
  - [IsAsync](#isasync)
93
94
  - [LazyFactory](#lazyfactory)
94
95
  - [Timeout](#timeout)
95
- - [Try](#try)
96
+ - [Tries](#tries)
96
97
  - [TryAsync](#tryasync)
98
+ - [TryAsyncCall](#tryasynccall)
99
+ - [TryCall](#trycall)
100
+ - [TryNew](#trynew)
97
101
  - [TrySync](#trysync)
98
102
  - [TsToMjs](#tstomjs)
99
103
  - [AnyButUndefined](#anybutundefined)
@@ -2926,7 +2930,7 @@ Dev.vivthDevCodeBlock(async ({ test }) => {
2926
2930
 
2927
2931
  #### reference:`Trace`
2928
2932
 
2929
- - returns position of stack trace as string, formatted as `fileName:lineNumber:columnNumber`;
2933
+ - returns position of stack trace as string, formatted like `fileName:lineNumber:columnNumber`;
2930
2934
  - extremely usefull for:
2931
2935
  > - jumping positions to code line;
2932
2936
  > - creating dynamic string id;
@@ -2948,6 +2952,40 @@ Console.log(Trace(3)); // "D://test.mjs:3:13"
2948
2952
 
2949
2953
  \*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2950
2954
 
2955
+ <h2 id="tracepath">TracePath</h2>
2956
+
2957
+ #### reference:`TracePath`
2958
+
2959
+ - get stack trace path that matched with truthy filterCallback;
2960
+ - returns position of stack trace as string, formatted like `fileName:lineNumber:columnNumber`;
2961
+ - extremely usefull for:
2962
+ > - jumping positions to code line;
2963
+ > - creating dynamic string id;
2964
+
2965
+ ```js
2966
+ /**
2967
+ * @param {(stackString:string)=>boolean} filterCallback
2968
+ * - stackString path are normalized to use forward slash;
2969
+ * - if return true, `TracePath` will return the current stackString;
2970
+ * - if return false, continue to check the stacks;
2971
+ * @returns {string|undefined}
2972
+ */
2973
+ ```
2974
+
2975
+ - <i>example</i>:
2976
+
2977
+ ```js
2978
+ import { TracePath, Console } from "vivth";
2979
+
2980
+ Console.log(
2981
+ TracePath((stackString) => {
2982
+ return stackString.includes("test.mjs");
2983
+ }),
2984
+ ); // "D://test.mjs:4:2"
2985
+ ```
2986
+
2987
+ \*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
2988
+
2951
2989
  <h2 id="jsautodoc">JSautoDOC</h2>
2952
2990
 
2953
2991
  #### reference:`JSautoDOC`
@@ -3265,9 +3303,9 @@ test();
3265
3303
 
3266
3304
  \*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
3267
3305
 
3268
- <h2 id="try">Try</h2>
3306
+ <h2 id="tries">Tries</h2>
3269
3307
 
3270
- #### reference:`Try`
3308
+ #### reference:`Tries`
3271
3309
 
3272
3310
  - function for error as value for chained operations;
3273
3311
  - utility function to brute force which key is able to run;
@@ -3294,9 +3332,9 @@ test();
3294
3332
  - <i>example</i>:
3295
3333
 
3296
3334
  ```js
3297
- import { Try } from "vivth";
3335
+ import { Tries } from "vivth";
3298
3336
 
3299
- const [[key, result], error] = await Try({
3337
+ const [[key, result], error] = await Tries({
3300
3338
  someRuntime: async ({ prevError }) => {
3301
3339
  // asuming on this one doesn't naturally throw error,
3302
3340
  // yet you need to continue to next key,
@@ -3361,6 +3399,100 @@ let [res, error] = await TryAsync(async () => {
3361
3399
 
3362
3400
  \*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
3363
3401
 
3402
+ <h2 id="tryasynccall">TryAsyncCall</h2>
3403
+
3404
+ #### reference:`TryAsyncCall`
3405
+
3406
+ - function helper to turn unsafe callback into safe one without tryCatch block;
3407
+ - usefull to flatten your source code;
3408
+
3409
+ ```js
3410
+ /**
3411
+ * @template {(...param:any[])=>Promise<any>} UNSAFEASYNCCALLBACK
3412
+ * @param {UNSAFEASYNCCALLBACK} unsafeAsyncCallback
3413
+ * @returns {(...param:Parameters<UNSAFEASYNCCALLBACK>)=> Promise<
3414
+ * [Awaited<ReturnType<UNSAFEASYNCCALLBACK>>,undefined]|
3415
+ * [undefined,Error]>}
3416
+ */
3417
+ ```
3418
+
3419
+ - <i>example</i>:
3420
+
3421
+ ```js
3422
+ import { TryAsyncCall } from "vivth";
3423
+
3424
+ (async () => {
3425
+ const [result, error] = await TryAsyncCall(unsafeAsyncCallback)(
3426
+ ...unsafeAsyncCallbackParameters,
3427
+ );
3428
+ if (!error) {
3429
+ // do something with result
3430
+ }
3431
+ })();
3432
+ ```
3433
+
3434
+ \*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
3435
+
3436
+ <h2 id="trycall">TryCall</h2>
3437
+
3438
+ #### reference:`TryCall`
3439
+
3440
+ - function helper to turn unsafe callback into safe one without tryCatch block;
3441
+ - usefull to flatten your source code;
3442
+
3443
+ ```js
3444
+ /**
3445
+ * @template {(...param:any[])=>any} UNSAFECALLBACK
3446
+ * @param {UNSAFECALLBACK} unsafeCallback
3447
+ * @returns {(...param:Parameters<UNSAFECALLBACK>)=>
3448
+ * [ReturnType<UNSAFECALLBACK>,undefined]|
3449
+ * [undefined,Error]}
3450
+ */
3451
+ ```
3452
+
3453
+ - <i>example</i>:
3454
+
3455
+ ```js
3456
+ import { TryCall } from "vivth";
3457
+
3458
+ const [result, error] = TryCall(unsafeCallback)(...unsafeCallbackParameters);
3459
+ if (!error) {
3460
+ // do something with result
3461
+ }
3462
+ ```
3463
+
3464
+ \*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
3465
+
3466
+ <h2 id="trynew">TryNew</h2>
3467
+
3468
+ #### reference:`TryNew`
3469
+
3470
+ - function helper to turn unsafe constructor call of classReference into safe one without tryCatch block;
3471
+ - usefull to flatten your source code;
3472
+
3473
+ ```js
3474
+ /**
3475
+ * @template {new (...args: any[]) => any} CLASSREF
3476
+ * @param {CLASSREF} classReference
3477
+ * @returns {(...args: ConstructorParameters<CLASSREF>) =>
3478
+ * [InstanceType<CLASSREF>, undefined]|
3479
+ * [undefined, Error]}
3480
+ */
3481
+ ```
3482
+
3483
+ - <i>example</i>:
3484
+
3485
+ ```js
3486
+ import { TryNew } from "vivth";
3487
+
3488
+ const [instance, error] = TryNew(ClassReference)(...classConstructorParameters);
3489
+ if (!error) {
3490
+ // do something with instance
3491
+ }
3492
+ ```
3493
+
3494
+ \*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
3495
+
3364
3496
  <h2 id="trysync">TrySync</h2>
3365
3497
 
3366
3498
  #### reference:`TrySync`
package/bun.lock CHANGED
@@ -6,16 +6,16 @@
6
6
  "dependencies": {
7
7
  "@types/mime-types": "^3.0.1",
8
8
  "chokidar": "^4.0.3",
9
- "esbuild": "^0.25.9",
9
+ "esbuild": "^0.25.12",
10
10
  "i": "^0.3.7",
11
11
  "mime-types": "^3.0.1",
12
12
  "pkg": "^5.8.1",
13
+ "prettier": "^3.6.2",
13
14
  },
14
15
  "devDependencies": {
15
16
  "@types/bun": "latest",
16
17
  "concurrently": "^9.2.1",
17
- "prettier": "^3.6.2",
18
- "typescript": "^5.9.2",
18
+ "typescript": "^5.9.3",
19
19
  "vivth": "link:vivth",
20
20
  },
21
21
  },
@@ -31,57 +31,57 @@
31
31
 
32
32
  "@babel/types": ["@babel/types@7.19.0", "", { "dependencies": { "@babel/helper-string-parser": "^7.18.10", "@babel/helper-validator-identifier": "^7.18.6", "to-fast-properties": "^2.0.0" } }, "sha512-YuGopBq3ke25BVSiS6fgF49Ul9gH1x70Bcr6bqRLjWCkcX8Hre1/5+z+IiWOIerRMSSEfGZVB9z9kyq7wVs9YA=="],
33
33
 
34
- "@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.25.9", "", { "os": "aix", "cpu": "ppc64" }, "sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA=="],
34
+ "@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.25.12", "", { "os": "aix", "cpu": "ppc64" }, "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA=="],
35
35
 
36
- "@esbuild/android-arm": ["@esbuild/android-arm@0.25.9", "", { "os": "android", "cpu": "arm" }, "sha512-5WNI1DaMtxQ7t7B6xa572XMXpHAaI/9Hnhk8lcxF4zVN4xstUgTlvuGDorBguKEnZO70qwEcLpfifMLoxiPqHQ=="],
36
+ "@esbuild/android-arm": ["@esbuild/android-arm@0.25.12", "", { "os": "android", "cpu": "arm" }, "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg=="],
37
37
 
38
- "@esbuild/android-arm64": ["@esbuild/android-arm64@0.25.9", "", { "os": "android", "cpu": "arm64" }, "sha512-IDrddSmpSv51ftWslJMvl3Q2ZT98fUSL2/rlUXuVqRXHCs5EUF1/f+jbjF5+NG9UffUDMCiTyh8iec7u8RlTLg=="],
38
+ "@esbuild/android-arm64": ["@esbuild/android-arm64@0.25.12", "", { "os": "android", "cpu": "arm64" }, "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg=="],
39
39
 
40
- "@esbuild/android-x64": ["@esbuild/android-x64@0.25.9", "", { "os": "android", "cpu": "x64" }, "sha512-I853iMZ1hWZdNllhVZKm34f4wErd4lMyeV7BLzEExGEIZYsOzqDWDf+y082izYUE8gtJnYHdeDpN/6tUdwvfiw=="],
40
+ "@esbuild/android-x64": ["@esbuild/android-x64@0.25.12", "", { "os": "android", "cpu": "x64" }, "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg=="],
41
41
 
42
- "@esbuild/darwin-arm64": ["@esbuild/darwin-arm64@0.25.9", "", { "os": "darwin", "cpu": "arm64" }, "sha512-XIpIDMAjOELi/9PB30vEbVMs3GV1v2zkkPnuyRRURbhqjyzIINwj+nbQATh4H9GxUgH1kFsEyQMxwiLFKUS6Rg=="],
42
+ "@esbuild/darwin-arm64": ["@esbuild/darwin-arm64@0.25.12", "", { "os": "darwin", "cpu": "arm64" }, "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg=="],
43
43
 
44
- "@esbuild/darwin-x64": ["@esbuild/darwin-x64@0.25.9", "", { "os": "darwin", "cpu": "x64" }, "sha512-jhHfBzjYTA1IQu8VyrjCX4ApJDnH+ez+IYVEoJHeqJm9VhG9Dh2BYaJritkYK3vMaXrf7Ogr/0MQ8/MeIefsPQ=="],
44
+ "@esbuild/darwin-x64": ["@esbuild/darwin-x64@0.25.12", "", { "os": "darwin", "cpu": "x64" }, "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA=="],
45
45
 
46
- "@esbuild/freebsd-arm64": ["@esbuild/freebsd-arm64@0.25.9", "", { "os": "freebsd", "cpu": "arm64" }, "sha512-z93DmbnY6fX9+KdD4Ue/H6sYs+bhFQJNCPZsi4XWJoYblUqT06MQUdBCpcSfuiN72AbqeBFu5LVQTjfXDE2A6Q=="],
46
+ "@esbuild/freebsd-arm64": ["@esbuild/freebsd-arm64@0.25.12", "", { "os": "freebsd", "cpu": "arm64" }, "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg=="],
47
47
 
48
- "@esbuild/freebsd-x64": ["@esbuild/freebsd-x64@0.25.9", "", { "os": "freebsd", "cpu": "x64" }, "sha512-mrKX6H/vOyo5v71YfXWJxLVxgy1kyt1MQaD8wZJgJfG4gq4DpQGpgTB74e5yBeQdyMTbgxp0YtNj7NuHN0PoZg=="],
48
+ "@esbuild/freebsd-x64": ["@esbuild/freebsd-x64@0.25.12", "", { "os": "freebsd", "cpu": "x64" }, "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ=="],
49
49
 
50
- "@esbuild/linux-arm": ["@esbuild/linux-arm@0.25.9", "", { "os": "linux", "cpu": "arm" }, "sha512-HBU2Xv78SMgaydBmdor38lg8YDnFKSARg1Q6AT0/y2ezUAKiZvc211RDFHlEZRFNRVhcMamiToo7bDx3VEOYQw=="],
50
+ "@esbuild/linux-arm": ["@esbuild/linux-arm@0.25.12", "", { "os": "linux", "cpu": "arm" }, "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw=="],
51
51
 
52
- "@esbuild/linux-arm64": ["@esbuild/linux-arm64@0.25.9", "", { "os": "linux", "cpu": "arm64" }, "sha512-BlB7bIcLT3G26urh5Dmse7fiLmLXnRlopw4s8DalgZ8ef79Jj4aUcYbk90g8iCa2467HX8SAIidbL7gsqXHdRw=="],
52
+ "@esbuild/linux-arm64": ["@esbuild/linux-arm64@0.25.12", "", { "os": "linux", "cpu": "arm64" }, "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ=="],
53
53
 
54
- "@esbuild/linux-ia32": ["@esbuild/linux-ia32@0.25.9", "", { "os": "linux", "cpu": "ia32" }, "sha512-e7S3MOJPZGp2QW6AK6+Ly81rC7oOSerQ+P8L0ta4FhVi+/j/v2yZzx5CqqDaWjtPFfYz21Vi1S0auHrap3Ma3A=="],
54
+ "@esbuild/linux-ia32": ["@esbuild/linux-ia32@0.25.12", "", { "os": "linux", "cpu": "ia32" }, "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA=="],
55
55
 
56
- "@esbuild/linux-loong64": ["@esbuild/linux-loong64@0.25.9", "", { "os": "linux", "cpu": "none" }, "sha512-Sbe10Bnn0oUAB2AalYztvGcK+o6YFFA/9829PhOCUS9vkJElXGdphz0A3DbMdP8gmKkqPmPcMJmJOrI3VYB1JQ=="],
56
+ "@esbuild/linux-loong64": ["@esbuild/linux-loong64@0.25.12", "", { "os": "linux", "cpu": "none" }, "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng=="],
57
57
 
58
- "@esbuild/linux-mips64el": ["@esbuild/linux-mips64el@0.25.9", "", { "os": "linux", "cpu": "none" }, "sha512-YcM5br0mVyZw2jcQeLIkhWtKPeVfAerES5PvOzaDxVtIyZ2NUBZKNLjC5z3/fUlDgT6w89VsxP2qzNipOaaDyA=="],
58
+ "@esbuild/linux-mips64el": ["@esbuild/linux-mips64el@0.25.12", "", { "os": "linux", "cpu": "none" }, "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw=="],
59
59
 
60
- "@esbuild/linux-ppc64": ["@esbuild/linux-ppc64@0.25.9", "", { "os": "linux", "cpu": "ppc64" }, "sha512-++0HQvasdo20JytyDpFvQtNrEsAgNG2CY1CLMwGXfFTKGBGQT3bOeLSYE2l1fYdvML5KUuwn9Z8L1EWe2tzs1w=="],
60
+ "@esbuild/linux-ppc64": ["@esbuild/linux-ppc64@0.25.12", "", { "os": "linux", "cpu": "ppc64" }, "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA=="],
61
61
 
62
- "@esbuild/linux-riscv64": ["@esbuild/linux-riscv64@0.25.9", "", { "os": "linux", "cpu": "none" }, "sha512-uNIBa279Y3fkjV+2cUjx36xkx7eSjb8IvnL01eXUKXez/CBHNRw5ekCGMPM0BcmqBxBcdgUWuUXmVWwm4CH9kg=="],
62
+ "@esbuild/linux-riscv64": ["@esbuild/linux-riscv64@0.25.12", "", { "os": "linux", "cpu": "none" }, "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w=="],
63
63
 
64
- "@esbuild/linux-s390x": ["@esbuild/linux-s390x@0.25.9", "", { "os": "linux", "cpu": "s390x" }, "sha512-Mfiphvp3MjC/lctb+7D287Xw1DGzqJPb/J2aHHcHxflUo+8tmN/6d4k6I2yFR7BVo5/g7x2Monq4+Yew0EHRIA=="],
64
+ "@esbuild/linux-s390x": ["@esbuild/linux-s390x@0.25.12", "", { "os": "linux", "cpu": "s390x" }, "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg=="],
65
65
 
66
- "@esbuild/linux-x64": ["@esbuild/linux-x64@0.25.9", "", { "os": "linux", "cpu": "x64" }, "sha512-iSwByxzRe48YVkmpbgoxVzn76BXjlYFXC7NvLYq+b+kDjyyk30J0JY47DIn8z1MO3K0oSl9fZoRmZPQI4Hklzg=="],
66
+ "@esbuild/linux-x64": ["@esbuild/linux-x64@0.25.12", "", { "os": "linux", "cpu": "x64" }, "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw=="],
67
67
 
68
- "@esbuild/netbsd-arm64": ["@esbuild/netbsd-arm64@0.25.9", "", { "os": "none", "cpu": "arm64" }, "sha512-9jNJl6FqaUG+COdQMjSCGW4QiMHH88xWbvZ+kRVblZsWrkXlABuGdFJ1E9L7HK+T0Yqd4akKNa/lO0+jDxQD4Q=="],
68
+ "@esbuild/netbsd-arm64": ["@esbuild/netbsd-arm64@0.25.12", "", { "os": "none", "cpu": "arm64" }, "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg=="],
69
69
 
70
- "@esbuild/netbsd-x64": ["@esbuild/netbsd-x64@0.25.9", "", { "os": "none", "cpu": "x64" }, "sha512-RLLdkflmqRG8KanPGOU7Rpg829ZHu8nFy5Pqdi9U01VYtG9Y0zOG6Vr2z4/S+/3zIyOxiK6cCeYNWOFR9QP87g=="],
70
+ "@esbuild/netbsd-x64": ["@esbuild/netbsd-x64@0.25.12", "", { "os": "none", "cpu": "x64" }, "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ=="],
71
71
 
72
- "@esbuild/openbsd-arm64": ["@esbuild/openbsd-arm64@0.25.9", "", { "os": "openbsd", "cpu": "arm64" }, "sha512-YaFBlPGeDasft5IIM+CQAhJAqS3St3nJzDEgsgFixcfZeyGPCd6eJBWzke5piZuZ7CtL656eOSYKk4Ls2C0FRQ=="],
72
+ "@esbuild/openbsd-arm64": ["@esbuild/openbsd-arm64@0.25.12", "", { "os": "openbsd", "cpu": "arm64" }, "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A=="],
73
73
 
74
- "@esbuild/openbsd-x64": ["@esbuild/openbsd-x64@0.25.9", "", { "os": "openbsd", "cpu": "x64" }, "sha512-1MkgTCuvMGWuqVtAvkpkXFmtL8XhWy+j4jaSO2wxfJtilVCi0ZE37b8uOdMItIHz4I6z1bWWtEX4CJwcKYLcuA=="],
74
+ "@esbuild/openbsd-x64": ["@esbuild/openbsd-x64@0.25.12", "", { "os": "openbsd", "cpu": "x64" }, "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw=="],
75
75
 
76
- "@esbuild/openharmony-arm64": ["@esbuild/openharmony-arm64@0.25.9", "", { "os": "none", "cpu": "arm64" }, "sha512-4Xd0xNiMVXKh6Fa7HEJQbrpP3m3DDn43jKxMjxLLRjWnRsfxjORYJlXPO4JNcXtOyfajXorRKY9NkOpTHptErg=="],
76
+ "@esbuild/openharmony-arm64": ["@esbuild/openharmony-arm64@0.25.12", "", { "os": "none", "cpu": "arm64" }, "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg=="],
77
77
 
78
- "@esbuild/sunos-x64": ["@esbuild/sunos-x64@0.25.9", "", { "os": "sunos", "cpu": "x64" }, "sha512-WjH4s6hzo00nNezhp3wFIAfmGZ8U7KtrJNlFMRKxiI9mxEK1scOMAaa9i4crUtu+tBr+0IN6JCuAcSBJZfnphw=="],
78
+ "@esbuild/sunos-x64": ["@esbuild/sunos-x64@0.25.12", "", { "os": "sunos", "cpu": "x64" }, "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w=="],
79
79
 
80
- "@esbuild/win32-arm64": ["@esbuild/win32-arm64@0.25.9", "", { "os": "win32", "cpu": "arm64" }, "sha512-mGFrVJHmZiRqmP8xFOc6b84/7xa5y5YvR1x8djzXpJBSv/UsNK6aqec+6JDjConTgvvQefdGhFDAs2DLAds6gQ=="],
80
+ "@esbuild/win32-arm64": ["@esbuild/win32-arm64@0.25.12", "", { "os": "win32", "cpu": "arm64" }, "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg=="],
81
81
 
82
- "@esbuild/win32-ia32": ["@esbuild/win32-ia32@0.25.9", "", { "os": "win32", "cpu": "ia32" }, "sha512-b33gLVU2k11nVx1OhX3C8QQP6UHQK4ZtN56oFWvVXvz2VkDoe6fbG8TOgHFxEvqeqohmRnIHe5A1+HADk4OQww=="],
82
+ "@esbuild/win32-ia32": ["@esbuild/win32-ia32@0.25.12", "", { "os": "win32", "cpu": "ia32" }, "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ=="],
83
83
 
84
- "@esbuild/win32-x64": ["@esbuild/win32-x64@0.25.9", "", { "os": "win32", "cpu": "x64" }, "sha512-PPOl1mi6lpLNQxnGoyAfschAodRFYXJ+9fs6WHXz7CSWKbOqiMZsubC+BQsVKuul+3vKLuwTHsS2c2y9EoKwxQ=="],
84
+ "@esbuild/win32-x64": ["@esbuild/win32-x64@0.25.12", "", { "os": "win32", "cpu": "x64" }, "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA=="],
85
85
 
86
86
  "@jridgewell/gen-mapping": ["@jridgewell/gen-mapping@0.3.13", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.0", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA=="],
87
87
 
@@ -97,7 +97,7 @@
97
97
 
98
98
  "@nodelib/fs.walk": ["@nodelib/fs.walk@1.2.8", "", { "dependencies": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" } }, "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg=="],
99
99
 
100
- "@types/bun": ["@types/bun@1.2.21", "", { "dependencies": { "bun-types": "1.2.21" } }, "sha512-NiDnvEqmbfQ6dmZ3EeUO577s4P5bf4HCTXtI6trMc6f6RzirY5IrF3aIookuSpyslFzrnvv2lmEWv5HyC1X79A=="],
100
+ "@types/bun": ["@types/bun@1.3.2", "", { "dependencies": { "bun-types": "1.3.2" } }, "sha512-t15P7k5UIgHKkxwnMNkJbWlh/617rkDGEdSsDbu+qNHTaz9SKf7aC8fiIlUdD5RPpH6GEkP0cK7WlvmrEBRtWg=="],
101
101
 
102
102
  "@types/mime-types": ["@types/mime-types@3.0.1", "", {}, "sha512-xRMsfuQbnRq1Ef+C+RKaENOxXX87Ygl38W1vDfPHRku02TgQr+Qd8iivLtAMcR0KF5/29xlnFihkTlbqFrGOVQ=="],
103
103
 
@@ -123,7 +123,7 @@
123
123
 
124
124
  "buffer": ["buffer@5.7.1", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ=="],
125
125
 
126
- "bun-types": ["bun-types@1.2.21", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-sa2Tj77Ijc/NTLS0/Odjq/qngmEPZfbfnOERi0KRUYhT9R8M4VBioWVmMWE5GrYbKMc+5lVybXygLdibHaqVqw=="],
126
+ "bun-types": ["bun-types@1.3.2", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-i/Gln4tbzKNuxP70OWhJRZz1MRfvqExowP7U6JKoI8cntFrtxg7RJK3jvz7wQW54UuvNC8tbKHHri5fy74FVqg=="],
127
127
 
128
128
  "chalk": ["chalk@4.1.2", "", { "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA=="],
129
129
 
@@ -157,7 +157,7 @@
157
157
 
158
158
  "end-of-stream": ["end-of-stream@1.4.5", "", { "dependencies": { "once": "^1.4.0" } }, "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg=="],
159
159
 
160
- "esbuild": ["esbuild@0.25.9", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.25.9", "@esbuild/android-arm": "0.25.9", "@esbuild/android-arm64": "0.25.9", "@esbuild/android-x64": "0.25.9", "@esbuild/darwin-arm64": "0.25.9", "@esbuild/darwin-x64": "0.25.9", "@esbuild/freebsd-arm64": "0.25.9", "@esbuild/freebsd-x64": "0.25.9", "@esbuild/linux-arm": "0.25.9", "@esbuild/linux-arm64": "0.25.9", "@esbuild/linux-ia32": "0.25.9", "@esbuild/linux-loong64": "0.25.9", "@esbuild/linux-mips64el": "0.25.9", "@esbuild/linux-ppc64": "0.25.9", "@esbuild/linux-riscv64": "0.25.9", "@esbuild/linux-s390x": "0.25.9", "@esbuild/linux-x64": "0.25.9", "@esbuild/netbsd-arm64": "0.25.9", "@esbuild/netbsd-x64": "0.25.9", "@esbuild/openbsd-arm64": "0.25.9", "@esbuild/openbsd-x64": "0.25.9", "@esbuild/openharmony-arm64": "0.25.9", "@esbuild/sunos-x64": "0.25.9", "@esbuild/win32-arm64": "0.25.9", "@esbuild/win32-ia32": "0.25.9", "@esbuild/win32-x64": "0.25.9" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-CRbODhYyQx3qp7ZEwzxOk4JBqmD/seJrzPa/cGjY1VtIn5E09Oi9/dB4JwctnfZ8Q8iT7rioVv5k/FNT/uf54g=="],
160
+ "esbuild": ["esbuild@0.25.12", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.25.12", "@esbuild/android-arm": "0.25.12", "@esbuild/android-arm64": "0.25.12", "@esbuild/android-x64": "0.25.12", "@esbuild/darwin-arm64": "0.25.12", "@esbuild/darwin-x64": "0.25.12", "@esbuild/freebsd-arm64": "0.25.12", "@esbuild/freebsd-x64": "0.25.12", "@esbuild/linux-arm": "0.25.12", "@esbuild/linux-arm64": "0.25.12", "@esbuild/linux-ia32": "0.25.12", "@esbuild/linux-loong64": "0.25.12", "@esbuild/linux-mips64el": "0.25.12", "@esbuild/linux-ppc64": "0.25.12", "@esbuild/linux-riscv64": "0.25.12", "@esbuild/linux-s390x": "0.25.12", "@esbuild/linux-x64": "0.25.12", "@esbuild/netbsd-arm64": "0.25.12", "@esbuild/netbsd-x64": "0.25.12", "@esbuild/openbsd-arm64": "0.25.12", "@esbuild/openbsd-x64": "0.25.12", "@esbuild/openharmony-arm64": "0.25.12", "@esbuild/sunos-x64": "0.25.12", "@esbuild/win32-arm64": "0.25.12", "@esbuild/win32-ia32": "0.25.12", "@esbuild/win32-x64": "0.25.12" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg=="],
161
161
 
162
162
  "escalade": ["escalade@3.2.0", "", {}, "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA=="],
163
163
 
@@ -331,7 +331,7 @@
331
331
 
332
332
  "tunnel-agent": ["tunnel-agent@0.6.0", "", { "dependencies": { "safe-buffer": "^5.0.1" } }, "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w=="],
333
333
 
334
- "typescript": ["typescript@5.9.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A=="],
334
+ "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
335
335
 
336
336
  "undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="],
337
337
 
package/index.mjs CHANGED
@@ -36,6 +36,7 @@ export { CreateStringID } from './src/common/CreateStringID.mjs';
36
36
  export { Dev } from './src/common/Dev.mjs';
37
37
  export { EventNameSpace } from './src/common/EventNameSpace.mjs';
38
38
  export { Trace } from './src/common/Trace.mjs';
39
+ export { TracePath } from './src/common/TracePath.mjs';
39
40
  export { JSautoDOC } from './src/doc/JSautoDOC.mjs';
40
41
  export { CreateImmutable } from './src/function/CreateImmutable.mjs';
41
42
  export { EventCheck } from './src/function/EventCheck.mjs';
@@ -45,8 +46,11 @@ export { GetRuntime } from './src/function/GetRuntime.mjs';
45
46
  export { IsAsync } from './src/function/IsAsync.mjs';
46
47
  export { LazyFactory } from './src/function/LazyFactory.mjs';
47
48
  export { Timeout } from './src/function/Timeout.mjs';
48
- export { Try } from './src/function/Try.mjs';
49
+ export { Tries } from './src/function/Tries.mjs';
49
50
  export { TryAsync } from './src/function/TryAsync.mjs';
51
+ export { TryAsyncCall } from './src/function/TryAsyncCall.mjs';
52
+ export { TryCall } from './src/function/TryCall.mjs';
53
+ export { TryNew } from './src/function/TryNew.mjs';
50
54
  export { TrySync } from './src/function/TrySync.mjs';
51
55
  export { TsToMjs } from './src/function/TsToMjs.mjs';
52
56
  /**
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "1.3.7",
3
+ "version": "1.4.0",
4
4
  "description": "library primitives",
5
5
  "main": "index.mjs",
6
6
  "types": "./types/index.d.mts",
7
7
  "devDependencies": {
8
8
  "@types/bun": "latest",
9
9
  "concurrently": "^9.2.1",
10
- "typescript": "^5.9.2",
10
+ "typescript": "^5.9.3",
11
11
  "vivth": "link:vivth"
12
12
  },
13
13
  "dependencies": {
14
14
  "prettier": "^3.6.2",
15
15
  "@types/mime-types": "^3.0.1",
16
16
  "chokidar": "^4.0.3",
17
- "esbuild": "^0.25.9",
17
+ "esbuild": "^0.25.12",
18
18
  "i": "^0.3.7",
19
19
  "mime-types": "^3.0.1",
20
20
  "pkg": "^5.8.1"
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { closeWorkerThreadEventObject } from '../common/eventObjects.mjs';
4
4
  import { GetRuntime } from '../function/GetRuntime.mjs';
5
- import { Try } from '../function/Try.mjs';
5
+ import { Tries } from '../function/Tries.mjs';
6
6
  import { TryAsync } from '../function/TryAsync.mjs';
7
7
  import { Console } from './Console.mjs';
8
8
  import { Derived } from './Derived.mjs';
@@ -179,7 +179,7 @@ export class WorkerMainThread {
179
179
  Console.error('invalid `Worker` inputed to `WorkerMainThread`;');
180
180
  return;
181
181
  }
182
- const [, errorCreatingWorker] = await Try({
182
+ const [, errorCreatingWorker] = await Tries({
183
183
  browser: async () => {
184
184
  if (runtime !== 'browser') {
185
185
  throw new Error('not a browser');
@@ -4,7 +4,7 @@ import { FSInline } from '../bundler/FSInline.mjs';
4
4
  import { Base64URL } from '../common/Base64URL.mjs';
5
5
  import { closeWorkerThreadEventObject } from '../common/eventObjects.mjs';
6
6
  import { GetRuntime } from '../function/GetRuntime.mjs';
7
- import { Try } from '../function/Try.mjs';
7
+ import { Tries } from '../function/Tries.mjs';
8
8
  import { Console } from './Console.mjs';
9
9
  import { Derived } from './Derived.mjs';
10
10
  import { Effect } from './Effect.mjs';
@@ -111,7 +111,7 @@ export class WorkerMainThread {
111
111
  Console.error('invalid `Worker` inputed to `WorkerMainThread`;');
112
112
  return;
113
113
  }
114
- const [, errorCreatingWorker] = await Try({
114
+ const [, errorCreatingWorker] = await Tries({
115
115
  browser: async () => {
116
116
  if (runtime !== 'browser') {
117
117
  throw new Error('not a browser');
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { closeWorkerThreadEventObject } from '../common/eventObjects.mjs';
4
4
  import { EventCheck } from '../function/EventCheck.mjs';
5
- import { Try } from '../function/Try.mjs';
5
+ import { Tries } from '../function/Tries.mjs';
6
6
  import { TryAsync } from '../function/TryAsync.mjs';
7
7
  import { Console } from './Console.mjs';
8
8
  import { QChannel } from './QChannel.mjs';
@@ -75,7 +75,7 @@ export class WorkerThread {
75
75
  constructor(handler) {
76
76
  this.handler = handler;
77
77
  const this_ = this;
78
- Try({
78
+ Tries({
79
79
  post: async () => {
80
80
  /**
81
81
  * @param {MessageEvent<RECEIVE>|RECEIVE} ev
@@ -4,7 +4,7 @@ import { Paths } from '../class/Paths.mjs';
4
4
 
5
5
  /**
6
6
  * @description
7
- * - returns position of stack trace as string, formatted as `fileName:lineNumber:columnNumber`;
7
+ * - returns position of stack trace as string, formatted like `fileName:lineNumber:columnNumber`;
8
8
  * - extremely usefull for:
9
9
  * >- jumping positions to code line;
10
10
  * >- creating dynamic string id;
@@ -0,0 +1,44 @@
1
+ // @ts-check
2
+
3
+ import { Paths } from '../class/Paths.mjs';
4
+
5
+ /**
6
+ * @description
7
+ * - get stack trace path that matched with truthy filterCallback;
8
+ * - returns position of stack trace as string, formatted like `fileName:lineNumber:columnNumber`;
9
+ * - extremely usefull for:
10
+ * >- jumping positions to code line;
11
+ * >- creating dynamic string id;
12
+ * @param {(stackString:string)=>boolean} filterCallback
13
+ * - stackString path are normalized to use forward slash;
14
+ * - if return true, `TracePath` will return the current stackString;
15
+ * - if return false, continue to check the stacks;
16
+ * @returns {string|undefined}
17
+ * @example
18
+ * import { TracePath, Console } from 'vivth';
19
+ *
20
+ * Console.log(
21
+ * TracePath((stackString) => {
22
+ * return stackString.includes('test.mjs');
23
+ * })
24
+ * ); // "D://test.mjs:4:2"
25
+ */
26
+ export function TracePath(filterCallback) {
27
+ const err = new Error();
28
+ const stacks = err.stack?.split('\n');
29
+ if (!stacks || !stacks.length) {
30
+ return;
31
+ }
32
+ for (let i = 0; i < stacks.length; i++) {
33
+ const stack = stacks[i];
34
+ if (!stack) {
35
+ return;
36
+ }
37
+ const check = stack.match(/([A-Z]:[^ ]*[0-9]|\/[^ )]+:\d+:\d+)/m);
38
+ const match = Paths.normalize(check?.[1] ?? stack.trim());
39
+ if (!filterCallback(match)) {
40
+ continue;
41
+ }
42
+ return match;
43
+ }
44
+ }
@@ -21,9 +21,9 @@ import { TryAsync } from './TryAsync.mjs';
21
21
  * | [[undefined, undefined], Error|undefined]
22
22
  * >}
23
23
  * @example
24
- * import { Try } from 'vivth';
24
+ * import { Tries } from 'vivth';
25
25
  *
26
- * const [[key, result], error] = await Try({
26
+ * const [[key, result], error] = await Tries({
27
27
  * someRuntime: async ({ prevError }) => {
28
28
  * // asuming on this one doesn't naturally throw error,
29
29
  * // yet you need to continue to next key,
@@ -51,7 +51,7 @@ import { TryAsync } from './TryAsync.mjs';
51
51
  * },
52
52
  * });
53
53
  */
54
- export async function Try(tryRecord) {
54
+ export async function Tries(tryRecord) {
55
55
  /**
56
56
  * @type {Error|undefined}
57
57
  */
@@ -0,0 +1,31 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @description
5
+ * - function helper to turn unsafe callback into safe one without tryCatch block;
6
+ * - usefull to flatten your source code;
7
+ * @template {(...param:any[])=>Promise<any>} UNSAFEASYNCCALLBACK
8
+ * @param {UNSAFEASYNCCALLBACK} unsafeAsyncCallback
9
+ * @returns {(...param:Parameters<UNSAFEASYNCCALLBACK>)=> Promise<
10
+ * [Awaited<ReturnType<UNSAFEASYNCCALLBACK>>,undefined]|
11
+ * [undefined,Error]>}
12
+ * @example
13
+ * import { TryAsyncCall } from 'vivth';
14
+ *
15
+ * (async() => {
16
+ * const [result, error] = await TryAsyncCall(unsafeAsyncCallback)(...unsafeAsyncCallbackParameters);
17
+ * if (!error) {
18
+ * // do something with result
19
+ * }
20
+ * })()
21
+ */
22
+ export function TryAsyncCall(unsafeAsyncCallback) {
23
+ // @ts-expect-error
24
+ return async (...params) => {
25
+ try {
26
+ return [await unsafeAsyncCallback(...params), undefined];
27
+ } catch (err) {
28
+ return [undefined, err];
29
+ }
30
+ };
31
+ }
@@ -0,0 +1,29 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @description
5
+ * - function helper to turn unsafe callback into safe one without tryCatch block;
6
+ * - usefull to flatten your source code;
7
+ * @template {(...param:any[])=>any} UNSAFECALLBACK
8
+ * @param {UNSAFECALLBACK} unsafeCallback
9
+ * @returns {(...param:Parameters<UNSAFECALLBACK>)=>
10
+ * [ReturnType<UNSAFECALLBACK>,undefined]|
11
+ * [undefined,Error]}
12
+ * @example
13
+ * import { TryCall } from 'vivth';
14
+ *
15
+ * const [result, error] = TryCall(unsafeCallback)(...unsafeCallbackParameters);
16
+ * if (!error) {
17
+ * // do something with result
18
+ * }
19
+ */
20
+ export function TryCall(unsafeCallback) {
21
+ // @ts-expect-error
22
+ return (...params) => {
23
+ try {
24
+ return [unsafeCallback(...params), undefined];
25
+ } catch (err) {
26
+ return [undefined, err];
27
+ }
28
+ };
29
+ }
@@ -0,0 +1,29 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @description
5
+ * - function helper to turn unsafe constructor call of classReference into safe one without tryCatch block;
6
+ * - usefull to flatten your source code;
7
+ * @template {new (...args: any[]) => any} CLASSREF
8
+ * @param {CLASSREF} classReference
9
+ * @returns {(...args: ConstructorParameters<CLASSREF>) =>
10
+ * [InstanceType<CLASSREF>, undefined]|
11
+ * [undefined, Error]}
12
+ * @example
13
+ * import { TryNew } from 'vivth';
14
+ *
15
+ * const [instance, error] = TryNew(ClassReference)(...classConstructorParameters)
16
+ * if(!error) {
17
+ * // do something with instance
18
+ * }
19
+ */
20
+ export function TryNew(classReference) {
21
+ // @ts-expect-error
22
+ return (...params) => {
23
+ try {
24
+ return [new classReference(...params), undefined];
25
+ } catch (err) {
26
+ return [undefined, err];
27
+ }
28
+ };
29
+ }
package/types/index.d.mts CHANGED
@@ -28,6 +28,7 @@ export { CreateStringID } from "./src/common/CreateStringID.mjs";
28
28
  export { Dev } from "./src/common/Dev.mjs";
29
29
  export { EventNameSpace } from "./src/common/EventNameSpace.mjs";
30
30
  export { Trace } from "./src/common/Trace.mjs";
31
+ export { TracePath } from "./src/common/TracePath.mjs";
31
32
  export { JSautoDOC } from "./src/doc/JSautoDOC.mjs";
32
33
  export { CreateImmutable } from "./src/function/CreateImmutable.mjs";
33
34
  export { EventCheck } from "./src/function/EventCheck.mjs";
@@ -37,8 +38,11 @@ export { GetRuntime } from "./src/function/GetRuntime.mjs";
37
38
  export { IsAsync } from "./src/function/IsAsync.mjs";
38
39
  export { LazyFactory } from "./src/function/LazyFactory.mjs";
39
40
  export { Timeout } from "./src/function/Timeout.mjs";
40
- export { Try } from "./src/function/Try.mjs";
41
+ export { Tries } from "./src/function/Tries.mjs";
41
42
  export { TryAsync } from "./src/function/TryAsync.mjs";
43
+ export { TryAsyncCall } from "./src/function/TryAsyncCall.mjs";
44
+ export { TryCall } from "./src/function/TryCall.mjs";
45
+ export { TryNew } from "./src/function/TryNew.mjs";
42
46
  export { TrySync } from "./src/function/TrySync.mjs";
43
47
  export { TsToMjs } from "./src/function/TsToMjs.mjs";
44
48
  export type AnyButUndefined = import("./src/types/AnyButUndefined.mjs").AnyButUndefined;
@@ -29,7 +29,7 @@ export class FSInlineAnalyzer {
29
29
  * @param {RegExp} ruleForFileFullPath
30
30
  * @returns {Promise<_dirReturn>}
31
31
  */
32
- static #dir: (dirName: string, ruleForFileFullPath: RegExp) => Promise<{
32
+ static "__#private@#dir": (dirName: string, ruleForFileFullPath: RegExp) => Promise<{
33
33
  path: string;
34
34
  buffer: Buffer<ArrayBuffer>;
35
35
  }[]>;
@@ -3,7 +3,7 @@
3
3
  * - class with static methods to print to standard console with bare minimum ANSI styles;
4
4
  */
5
5
  export class Console {
6
- static #ansi: {
6
+ static "__#private@#ansi": {
7
7
  reset: string;
8
8
  bold: string;
9
9
  colors: {
@@ -19,7 +19,7 @@ export class Console {
19
19
  * @param {any} data
20
20
  * @returns {void}
21
21
  */
22
- static #call: (prefix: string, mode: "log" | "info" | "error" | "warn", data: any) => void;
22
+ static "__#private@#call": (prefix: string, mode: "log" | "info" | "error" | "warn", data: any) => void;
23
23
  /**
24
24
  * @description
25
25
  * @param {any} data
@@ -18,7 +18,7 @@ export class EventSignal<ISLIST extends boolean> {
18
18
  /**
19
19
  * @type {QChannel<string>}
20
20
  */
21
- static #qChannelEventSignal: QChannel<string>;
21
+ static "__#private@#qChannelEventSignal": QChannel<string>;
22
22
  /**
23
23
  * @description
24
24
  * - the constructor it self is set to `private`;
@@ -75,14 +75,14 @@ export class LitExp<KEYS extends import("../types/LitExpKeyType.mjs").LitExpKeyT
75
75
  * @param {TemplateStringsArray} strings
76
76
  * @returns {ReturnType<typeof TrySync<string[]>>}
77
77
  */
78
- static #processTemplate<KEYS_1 extends import("../types/LitExpKeyType.mjs").LitExpKeyType>(instance_rules: KEYS_1, intance_values: (keyof KEYS_1)[], valueHandler: (value: keyof KEYS_1, regex: RegExp | false) => ReturnType<typeof TrySync<string>>, strings: TemplateStringsArray): ReturnType<typeof TrySync<string[]>>;
78
+ static "__#private@#processTemplate"<KEYS_1 extends import("../types/LitExpKeyType.mjs").LitExpKeyType>(instance_rules: KEYS_1, intance_values: (keyof KEYS_1)[], valueHandler: (value: keyof KEYS_1, regex: RegExp | false) => ReturnType<typeof TrySync<string>>, strings: TemplateStringsArray): ReturnType<typeof TrySync<string[]>>;
79
79
  /**
80
80
  * @template {LitExpKeyType} KEYS
81
81
  * @param {RegExp|false} regex
82
82
  * @param {keyof KEYS} value
83
83
  * @returns {ReturnType<typeof TrySync<string>>}
84
84
  */
85
- static #namedChapture<KEYS_1 extends import("../types/LitExpKeyType.mjs").LitExpKeyType>(value: keyof KEYS_1, regex: RegExp | false): ReturnType<typeof TrySync<string>>;
85
+ static "__#private@#namedChapture"<KEYS_1 extends import("../types/LitExpKeyType.mjs").LitExpKeyType>(value: keyof KEYS_1, regex: RegExp | false): ReturnType<typeof TrySync<string>>;
86
86
  /**
87
87
  * @private
88
88
  * @param {KEYS} keys
@@ -8,7 +8,7 @@ export class Paths {
8
8
  /**
9
9
  * @type {Paths|undefined}
10
10
  */
11
- static #instance: Paths | undefined;
11
+ static "__#private@#instance": Paths | undefined;
12
12
  /**
13
13
  * @description
14
14
  * - reference for rootPath
@@ -25,7 +25,7 @@ export class QChannel<DEFINEDANY extends import("../types/AnyButUndefined.mjs").
25
25
  /**
26
26
  * @type {Map<AnyButUndefined, [Promise<any>, {}]>}
27
27
  */
28
- static #uniquePromiser: Map<import("../types/AnyButUndefined.mjs").AnyButUndefined, [Promise<any>, {}]>;
28
+ static "__#private@#uniquePromiser": Map<import("../types/AnyButUndefined.mjs").AnyButUndefined, [Promise<any>, {}]>;
29
29
  /**
30
30
  * - ensures that each id has only one task running at a time.
31
31
  * - calls with the same id will wait for the previous call to finish.
@@ -33,7 +33,7 @@ export class QChannel<DEFINEDANY extends import("../types/AnyButUndefined.mjs").
33
33
  * @param {QChannel<any>} instance
34
34
  * @returns {Promise<QCBReturn>} Resolves when it's safe to proceed for the given id, returning a cleanup function
35
35
  */
36
- static #uniqueCB: (id: import("../types/AnyButUndefined.mjs").AnyButUndefined, instance: QChannel<any>) => Promise<import("../types/QCBReturn.mjs").QCBReturn>;
36
+ static "__#private@#uniqueCB": (id: import("../types/AnyButUndefined.mjs").AnyButUndefined, instance: QChannel<any>) => Promise<import("../types/QCBReturn.mjs").QCBReturn>;
37
37
  /**
38
38
  * @description
39
39
  * - first in first out handler
@@ -11,7 +11,7 @@ export class Signal<VALUE> {
11
11
  /**
12
12
  * @param {Signal<any>} signalInstance
13
13
  */
14
- static #notify: (signalInstance: Signal<any>) => void;
14
+ static "__#private@#notify": (signalInstance: Signal<any>) => void;
15
15
  /**
16
16
  * @description
17
17
  * - create a `Signal`;
@@ -10,7 +10,7 @@ export class WalkThrough {
10
10
  * @param {(...any:any[])=>void} callback
11
11
  * @returns {void}
12
12
  */
13
- static #handler: (iterator: Iterator<any, any, any>, callback: (...any: any[]) => void) => void;
13
+ static "__#private@#handler": (iterator: Iterator<any, any, any>, callback: (...any: any[]) => void) => void;
14
14
  /**
15
15
  * @description
16
16
  * - method helper to WalkThrough `Set`;
@@ -20,7 +20,7 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
20
20
  /**
21
21
  * @type {boolean}
22
22
  */
23
- static #isRegistered: boolean;
23
+ static "__#private@#isRegistered": boolean;
24
24
  /**
25
25
  * @description
26
26
  * - need to be called first, before any `WorkerMainThread` instantiation:
@@ -79,7 +79,7 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
79
79
  worker: string;
80
80
  root: string;
81
81
  }) => Promise<string>;
82
- static #options: import("worker_threads").WorkerOptions & {
82
+ static "__#private@#options": import("worker_threads").WorkerOptions & {
83
83
  type?: "module";
84
84
  };
85
85
  /**
@@ -104,7 +104,7 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
104
104
  * @param {(any:any)=>void} listener
105
105
  * @returns {Promise<void>}
106
106
  */
107
- static #workerFilehandler<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
107
+ static "__#private@#workerFilehandler"<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
108
108
  /**
109
109
  * @private
110
110
  * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
@@ -17,7 +17,7 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
17
17
  /**
18
18
  * @type {boolean}
19
19
  */
20
- static #isRegistered: boolean;
20
+ static "__#private@#isRegistered": boolean;
21
21
  /**
22
22
  * @param {Object} param0
23
23
  * @param {typeof WorkerMainThread["workerClass"]} param0.workerClass
@@ -38,7 +38,7 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
38
38
  worker: string;
39
39
  root: string;
40
40
  }) => Promise<string>;
41
- static #options: import("worker_threads").WorkerOptions & {
41
+ static "__#private@#options": import("worker_threads").WorkerOptions & {
42
42
  type?: "module";
43
43
  };
44
44
  /**
@@ -57,7 +57,7 @@ export class WorkerMainThread<WT extends WorkerThread<any, any>> {
57
57
  * @param {(any:any)=>void} listener
58
58
  * @returns {Promise<void>}
59
59
  */
60
- static #workerFilehandler<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
60
+ static "__#private@#workerFilehandler"<WT_1 extends WorkerThread<any, any>>(handler: string, options: WorkerOptions | import("worker_threads").WorkerOptions, worker: WorkerMainThread<WT_1>, listener: (any: any) => void): Promise<void>;
61
61
  /**
62
62
  * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[0]} handler
63
63
  * @param {Parameters<typeof WorkerMainThread<WT>["newVivthWorker"]>[1]} [options]
@@ -12,7 +12,7 @@ export class WorkerThread<RECEIVE, POST> {
12
12
  /**
13
13
  * @type {Parameters<typeof WorkerThread["setup"]>[0]|undefined}
14
14
  */
15
- static #refs: Parameters<(typeof WorkerThread)["setup"]>[0] | undefined;
15
+ static "__#private@#refs": Parameters<(typeof WorkerThread)["setup"]>[0] | undefined;
16
16
  /**
17
17
  * @description
18
18
  * - need to be called and exported as new `WorkerThread` class reference;
@@ -36,7 +36,7 @@ export class WorkerThread<RECEIVE, POST> {
36
36
  /**
37
37
  * @param {any} ev
38
38
  */
39
- static #isCloseWorkerEvent: (ev: any) => boolean;
39
+ static "__#private@#isCloseWorkerEvent": (ev: any) => boolean;
40
40
  /**
41
41
  * @description
42
42
  * - instantiate via created class from `setup` static method;
@@ -23,12 +23,12 @@ export class Dev {
23
23
  /**
24
24
  * @type {Signal<Map<string,Awaited<ReturnType<typeof TryAsync<boolean>>>>>}
25
25
  */
26
- static #notifications: Signal<Map<string, Awaited<ReturnType<typeof TryAsync<boolean>>>>>;
26
+ static "__#private@#notifications": Signal<Map<string, Awaited<ReturnType<typeof TryAsync<boolean>>>>>;
27
27
  /**
28
28
  * @type {DevTestCB}
29
29
  */
30
- static #test: DevTestCB;
31
- static #effectForCheck: Effect & {
30
+ static "__#private@#test": DevTestCB;
31
+ static "__#private@#effectForCheck": Effect & {
32
32
  "vivth:unwrapLazy;": () => Effect;
33
33
  };
34
34
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @description
3
- * - returns position of stack trace as string, formatted as `fileName:lineNumber:columnNumber`;
3
+ * - returns position of stack trace as string, formatted like `fileName:lineNumber:columnNumber`;
4
4
  * - extremely usefull for:
5
5
  * >- jumping positions to code line;
6
6
  * >- creating dynamic string id;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @description
3
+ * - get stack trace path that matched with truthy filterCallback;
4
+ * - returns position of stack trace as string, formatted like `fileName:lineNumber:columnNumber`;
5
+ * - extremely usefull for:
6
+ * >- jumping positions to code line;
7
+ * >- creating dynamic string id;
8
+ * @param {(stackString:string)=>boolean} filterCallback
9
+ * - stackString path are normalized to use forward slash;
10
+ * - if return true, `TracePath` will return the current stackString;
11
+ * - if return false, continue to check the stacks;
12
+ * @returns {string|undefined}
13
+ * @example
14
+ * import { TracePath, Console } from 'vivth';
15
+ *
16
+ * Console.log(
17
+ * TracePath((stackString) => {
18
+ * return stackString.includes('test.mjs');
19
+ * })
20
+ * ); // "D://test.mjs:4:2"
21
+ */
22
+ export function TracePath(filterCallback: (stackString: string) => boolean): string | undefined;
@@ -25,7 +25,7 @@ export class JSautoDOC {
25
25
  /**
26
26
  * @type {JSautoDOC|undefined}
27
27
  */
28
- static #instance: JSautoDOC | undefined;
28
+ static "__#private@#instance": JSautoDOC | undefined;
29
29
  /**
30
30
  * @description
31
31
  * @param {Object} [options]
@@ -3,7 +3,7 @@ export class parsedFile {
3
3
  * @param {string} exportName
4
4
  * @returns {boolean}
5
5
  */
6
- static #isExportNameValid: (exportName: string) => boolean;
6
+ static "__#private@#isExportNameValid": (exportName: string) => boolean;
7
7
  /**
8
8
  * @param {string} content
9
9
  * @returns { RegExpExecArray[] }
@@ -17,9 +17,9 @@
17
17
  * | [[undefined, undefined], Error|undefined]
18
18
  * >}
19
19
  * @example
20
- * import { Try } from 'vivth';
20
+ * import { Tries } from 'vivth';
21
21
  *
22
- * const [[key, result], error] = await Try({
22
+ * const [[key, result], error] = await Tries({
23
23
  * someRuntime: async ({ prevError }) => {
24
24
  * // asuming on this one doesn't naturally throw error,
25
25
  * // yet you need to continue to next key,
@@ -47,6 +47,6 @@
47
47
  * },
48
48
  * });
49
49
  */
50
- export function Try<KEY extends string, RETURNTYPE, RecordTryType extends Record<KEY, (err: {
50
+ export function Tries<KEY extends string, RETURNTYPE, RecordTryType extends Record<KEY, (err: {
51
51
  prevError: undefined | Error;
52
52
  }) => Promise<RETURNTYPE>>>(tryRecord: RecordTryType): Promise<[[keyof RecordTryType, RETURNTYPE], undefined] | [[undefined, undefined], Error | undefined]>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @description
3
+ * - function helper to turn unsafe callback into safe one without tryCatch block;
4
+ * - usefull to flatten your source code;
5
+ * @template {(...param:any[])=>Promise<any>} UNSAFEASYNCCALLBACK
6
+ * @param {UNSAFEASYNCCALLBACK} unsafeAsyncCallback
7
+ * @returns {(...param:Parameters<UNSAFEASYNCCALLBACK>)=> Promise<
8
+ * [Awaited<ReturnType<UNSAFEASYNCCALLBACK>>,undefined]|
9
+ * [undefined,Error]>}
10
+ * @example
11
+ * import { TryAsyncCall } from 'vivth';
12
+ *
13
+ * (async() => {
14
+ * const [result, error] = await TryAsyncCall(unsafeAsyncCallback)(...unsafeAsyncCallbackParameters);
15
+ * if (!error) {
16
+ * // do something with result
17
+ * }
18
+ * })()
19
+ */
20
+ export function TryAsyncCall<UNSAFEASYNCCALLBACK extends (...param: any[]) => Promise<any>>(unsafeAsyncCallback: UNSAFEASYNCCALLBACK): (...param: Parameters<UNSAFEASYNCCALLBACK>) => Promise<[Awaited<ReturnType<UNSAFEASYNCCALLBACK>>, undefined] | [undefined, Error]>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @description
3
+ * - function helper to turn unsafe callback into safe one without tryCatch block;
4
+ * - usefull to flatten your source code;
5
+ * @template {(...param:any[])=>any} UNSAFECALLBACK
6
+ * @param {UNSAFECALLBACK} unsafeCallback
7
+ * @returns {(...param:Parameters<UNSAFECALLBACK>)=>
8
+ * [ReturnType<UNSAFECALLBACK>,undefined]|
9
+ * [undefined,Error]}
10
+ * @example
11
+ * import { TryCall } from 'vivth';
12
+ *
13
+ * const [result, error] = TryCall(unsafeCallback)(...unsafeCallbackParameters);
14
+ * if (!error) {
15
+ * // do something with result
16
+ * }
17
+ */
18
+ export function TryCall<UNSAFECALLBACK extends (...param: any[]) => any>(unsafeCallback: UNSAFECALLBACK): (...param: Parameters<UNSAFECALLBACK>) => [ReturnType<UNSAFECALLBACK>, undefined] | [undefined, Error];
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @description
3
+ * - function helper to turn unsafe constructor call of classReference into safe one without tryCatch block;
4
+ * - usefull to flatten your source code;
5
+ * @template {new (...args: any[]) => any} CLASSREF
6
+ * @param {CLASSREF} classReference
7
+ * @returns {(...args: ConstructorParameters<CLASSREF>) =>
8
+ * [InstanceType<CLASSREF>, undefined]|
9
+ * [undefined, Error]}
10
+ * @example
11
+ * import { TryNew } from 'vivth';
12
+ *
13
+ * const [instance, error] = TryNew(ClassReference)(...classConstructorParameters)
14
+ * if(!error) {
15
+ * // do something with instance
16
+ * }
17
+ */
18
+ export function TryNew<CLASSREF extends new (...args: any[]) => any>(classReference: CLASSREF): (...args: ConstructorParameters<CLASSREF>) => [InstanceType<CLASSREF>, undefined] | [undefined, Error];