safe-try-with-ai 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +39 -0
- package/package.json +2 -1
package/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface AISuggestion {
|
|
2
|
+
name: string;
|
|
3
|
+
message: string;
|
|
4
|
+
suggestion?: string;
|
|
5
|
+
fix?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface SafeTryOptions {
|
|
9
|
+
analyze?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type SafeTryResult<T> = [null, T] | [Error | AISuggestion, null];
|
|
13
|
+
|
|
14
|
+
export function safeTry<T>(
|
|
15
|
+
fn: () => T,
|
|
16
|
+
options?: SafeTryOptions
|
|
17
|
+
): SafeTryResult<T>;
|
|
18
|
+
|
|
19
|
+
export function safeTryAsync<T>(
|
|
20
|
+
fn: () => Promise<T>,
|
|
21
|
+
options?: SafeTryOptions
|
|
22
|
+
): Promise<SafeTryResult<T>>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Safely parse JSON with AI-style error suggestions
|
|
26
|
+
*/
|
|
27
|
+
export function safeTryJson<T = unknown>(
|
|
28
|
+
json: string,
|
|
29
|
+
options?: SafeTryOptions
|
|
30
|
+
): SafeTryResult<T>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Execute with a default fallback value on error
|
|
34
|
+
*/
|
|
35
|
+
export function safeTryDefault<T>(
|
|
36
|
+
fn: () => T,
|
|
37
|
+
defaultValue: T,
|
|
38
|
+
options?: SafeTryOptions
|
|
39
|
+
): T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "safe-try-with-ai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Clean error handling for JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"error-handling",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"author": "madhuka2002",
|
|
13
13
|
"type": "commonjs",
|
|
14
14
|
"main": "src/index.js",
|
|
15
|
+
"types": "index.d.ts",
|
|
15
16
|
"scripts": {
|
|
16
17
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
18
|
}
|