@happy-nut/monacori 0.1.0 → 0.1.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.
- package/README.md +6 -6
- package/assets/icon.png +0 -0
- package/dist/app-main.js +52 -3
- package/dist/assets.d.ts +4 -0
- package/dist/assets.js +30 -0
- package/dist/build.d.ts +12 -0
- package/dist/build.js +74 -0
- package/dist/cli.d.ts +5 -33
- package/dist/cli.js +7 -3529
- package/dist/commands.d.ts +1 -0
- package/dist/commands.js +678 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.js +11 -0
- package/dist/diff.d.ts +12 -0
- package/dist/diff.js +355 -0
- package/dist/git.d.ts +4 -0
- package/dist/git.js +23 -0
- package/dist/highlight.d.ts +1 -0
- package/dist/highlight.js +85 -0
- package/dist/preload.cjs +22 -0
- package/dist/preload.d.cts +1 -0
- package/dist/render.d.ts +32 -0
- package/dist/render.js +334 -0
- package/dist/server.d.ts +20 -0
- package/dist/server.js +175 -0
- package/dist/types.d.ts +97 -0
- package/dist/types.js +1 -0
- package/dist/util.d.ts +18 -0
- package/dist/util.js +144 -0
- package/dist/viewer.client.js +3343 -0
- package/dist/viewer.css +939 -0
- package/package.json +4 -2
- package/scripts/patch-electron-name.mjs +57 -0
package/dist/util.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
export function stripHtmlTags(value) {
|
|
5
|
+
return value.replace(/<[^>]*>/g, "");
|
|
6
|
+
}
|
|
7
|
+
export function decodeEntities(value) {
|
|
8
|
+
return value
|
|
9
|
+
.replace(/&#x([0-9a-fA-F]+);/g, (_match, hex) => String.fromCodePoint(parseInt(hex, 16)))
|
|
10
|
+
.replace(/&#(\d+);/g, (_match, dec) => String.fromCodePoint(parseInt(dec, 10)))
|
|
11
|
+
.replace(/</g, "<")
|
|
12
|
+
.replace(/>/g, ">")
|
|
13
|
+
.replace(/"/g, "\"")
|
|
14
|
+
.replace(/&/g, "&");
|
|
15
|
+
}
|
|
16
|
+
export function stripDiffPath(value) {
|
|
17
|
+
if (value === "/dev/null") {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
return value.replace(/^[ab]\//, "");
|
|
21
|
+
}
|
|
22
|
+
export function languageForPath(path) {
|
|
23
|
+
const lower = path.toLowerCase();
|
|
24
|
+
if (lower.endsWith(".ts") || lower.endsWith(".tsx"))
|
|
25
|
+
return "typescript";
|
|
26
|
+
if (lower.endsWith(".js") || lower.endsWith(".jsx") || lower.endsWith(".mjs") || lower.endsWith(".cjs"))
|
|
27
|
+
return "javascript";
|
|
28
|
+
if (lower.endsWith(".json"))
|
|
29
|
+
return "json";
|
|
30
|
+
if (lower.endsWith(".css") || lower.endsWith(".scss") || lower.endsWith(".sass"))
|
|
31
|
+
return "css";
|
|
32
|
+
if (lower.endsWith(".html") || lower.endsWith(".htm") || lower.endsWith(".xml") || lower.endsWith(".svg"))
|
|
33
|
+
return "markup";
|
|
34
|
+
if (lower.endsWith(".md") || lower.endsWith(".mdx"))
|
|
35
|
+
return "markdown";
|
|
36
|
+
if (lower.endsWith(".py"))
|
|
37
|
+
return "python";
|
|
38
|
+
if (lower.endsWith(".rb"))
|
|
39
|
+
return "ruby";
|
|
40
|
+
if (lower.endsWith(".go"))
|
|
41
|
+
return "go";
|
|
42
|
+
if (lower.endsWith(".rs"))
|
|
43
|
+
return "rust";
|
|
44
|
+
if (lower.endsWith(".java") || lower.endsWith(".kt") || lower.endsWith(".kts"))
|
|
45
|
+
return "java";
|
|
46
|
+
if (lower.endsWith(".sh") || lower.endsWith(".bash") || lower.endsWith(".zsh"))
|
|
47
|
+
return "shell";
|
|
48
|
+
if (lower.endsWith(".yml") || lower.endsWith(".yaml"))
|
|
49
|
+
return "yaml";
|
|
50
|
+
if (lower.endsWith(".toml"))
|
|
51
|
+
return "toml";
|
|
52
|
+
if (lower.endsWith(".sql"))
|
|
53
|
+
return "sql";
|
|
54
|
+
if (lower.endsWith(".http") || lower.endsWith(".rest"))
|
|
55
|
+
return "http";
|
|
56
|
+
return "text";
|
|
57
|
+
}
|
|
58
|
+
export function isLikelyBinary(path) {
|
|
59
|
+
const sample = readFileSync(path).subarray(0, 8000);
|
|
60
|
+
return sample.includes(0);
|
|
61
|
+
}
|
|
62
|
+
export function readOption(args, name) {
|
|
63
|
+
const index = args.indexOf(name);
|
|
64
|
+
if (index < 0) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const value = args[index + 1];
|
|
68
|
+
if (!value || value.startsWith("--")) {
|
|
69
|
+
throw new Error(`Missing value for ${name}`);
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
export function parsePositiveInteger(value, optionName) {
|
|
74
|
+
const parsed = Number(value);
|
|
75
|
+
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
76
|
+
throw new Error(`${optionName} must be a non-negative integer`);
|
|
77
|
+
}
|
|
78
|
+
return parsed;
|
|
79
|
+
}
|
|
80
|
+
export function readStdin() {
|
|
81
|
+
if (process.stdin.isTTY) {
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
return readFileSync(0, "utf8");
|
|
85
|
+
}
|
|
86
|
+
export function summarizeForState(content) {
|
|
87
|
+
const lines = content
|
|
88
|
+
.split(/\r?\n/)
|
|
89
|
+
.map((line) => line.trim())
|
|
90
|
+
.filter(Boolean)
|
|
91
|
+
.slice(0, 12);
|
|
92
|
+
return lines.map((line) => `- ${line.replace(/^-+\s*/, "")}`).join("\n");
|
|
93
|
+
}
|
|
94
|
+
export function codeBlock(content) {
|
|
95
|
+
return ["```", content, "```"].join("\n");
|
|
96
|
+
}
|
|
97
|
+
export function timestampForFile() {
|
|
98
|
+
return new Date().toISOString().replace(/[:.]/g, "-");
|
|
99
|
+
}
|
|
100
|
+
export function hashText(value) {
|
|
101
|
+
return createHash("sha1").update(value).digest("hex");
|
|
102
|
+
}
|
|
103
|
+
export function sanitizeFilePart(value) {
|
|
104
|
+
return value.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-|-$/g, "");
|
|
105
|
+
}
|
|
106
|
+
export function escapeHtml(value) {
|
|
107
|
+
return value
|
|
108
|
+
.replace(/&/g, "&")
|
|
109
|
+
.replace(/</g, "<")
|
|
110
|
+
.replace(/>/g, ">")
|
|
111
|
+
.replace(/"/g, """)
|
|
112
|
+
.replace(/'/g, "'");
|
|
113
|
+
}
|
|
114
|
+
export function jsonForScript(value) {
|
|
115
|
+
return JSON.stringify(value)
|
|
116
|
+
.replace(/</g, "\\u003c")
|
|
117
|
+
.replace(/>/g, "\\u003e")
|
|
118
|
+
.replace(/&/g, "\\u0026")
|
|
119
|
+
.replace(/\u2028/g, "\\u2028")
|
|
120
|
+
.replace(/\u2029/g, "\\u2029");
|
|
121
|
+
}
|
|
122
|
+
export function escapeAttr(value) {
|
|
123
|
+
return escapeHtml(value);
|
|
124
|
+
}
|
|
125
|
+
export function formatBytes(bytes) {
|
|
126
|
+
if (bytes < 1024) {
|
|
127
|
+
return `${bytes} B`;
|
|
128
|
+
}
|
|
129
|
+
const kib = bytes / 1024;
|
|
130
|
+
if (kib < 1024) {
|
|
131
|
+
return `${kib.toFixed(1)} KiB`;
|
|
132
|
+
}
|
|
133
|
+
return `${(kib / 1024).toFixed(1)} MiB`;
|
|
134
|
+
}
|
|
135
|
+
export function listRecentFiles(dir, limit) {
|
|
136
|
+
if (!existsSync(dir)) {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
return readdirSync(dir)
|
|
140
|
+
.map((name) => join(dir, name))
|
|
141
|
+
.filter((path) => statSync(path).isFile())
|
|
142
|
+
.sort((a, b) => statSync(b).mtimeMs - statSync(a).mtimeMs)
|
|
143
|
+
.slice(0, limit);
|
|
144
|
+
}
|