safe-try-with-ai 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { safeTryJson } = require("../src/index.js");
6
+
7
+ // ANSI color codes
8
+ const COLORS = {
9
+ reset: "\x1b[0m",
10
+ green: "\x1b[32m",
11
+ red: "\x1b[31m",
12
+ blue: "\x1b[34m",
13
+ white: "\x1b[37m",
14
+ };
15
+
16
+ const green = (text) => COLORS.green + text + COLORS.reset;
17
+ const red = (text) => COLORS.red + text + COLORS.reset;
18
+ const blue = (text) => COLORS.blue + text + COLORS.reset;
19
+ const white = (text) => COLORS.white + text + COLORS.reset;
20
+
21
+ // CLI Args
22
+ const args = process.argv.slice(2);
23
+ if (args.length === 0) {
24
+ console.log(red("✖ No file specified"));
25
+ console.log("Usage: npx safe-try-with-ai <file.json> [--analyze]");
26
+ process.exit(1);
27
+ }
28
+
29
+ const filePath = path.resolve(args[0]);
30
+ const analyze = args.includes("--analyze");
31
+
32
+ // Read and validate JSON
33
+ const [err] = safeTryJson(() => fs.readFileSync(filePath, "utf8"), { analyze });
34
+
35
+ if (err) {
36
+ console.log(red("✖ JSON is invalid"));
37
+ console.log(white(` └─ Error: ${err.message}`));
38
+ if (analyze && err.suggestion) {
39
+ console.log(blue(` ├─ Suggestion: ${err.suggestion}`));
40
+ if (err.fix) console.log(green(` └─ Fix: ${err.fix}`));
41
+ }
42
+ process.exit(1);
43
+ } else {
44
+ console.log(green("✔ JSON is valid"));
45
+ process.exit(0);
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safe-try-with-ai",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Clean error handling for JavaScript",
5
5
  "keywords": [
6
6
  "error-handling",
@@ -8,6 +8,9 @@
8
8
  "functional",
9
9
  "AI"
10
10
  ],
11
+ "bin": {
12
+ "safe-try-with-ai": "./bin/safe-try.js"
13
+ },
11
14
  "license": "MIT",
12
15
  "author": "madhuka2002",
13
16
  "type": "commonjs",
package/index.d.ts DELETED
@@ -1,39 +0,0 @@
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;