safe-try-with-ai 1.2.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.
- package/bin/safe-try.js +46 -0
- package/package.json +5 -1
package/bin/safe-try.js
ADDED
|
@@ -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
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Clean error handling for JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"error-handling",
|
|
@@ -8,10 +8,14 @@
|
|
|
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",
|
|
14
17
|
"main": "src/index.js",
|
|
18
|
+
"types": "index.d.ts",
|
|
15
19
|
"scripts": {
|
|
16
20
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
21
|
}
|