@open330/kiwimu 0.7.1 → 1.1.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/src/utils.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Shared utility functions used across the codebase.
3
+ */
4
+
5
+ /** Escape HTML special characters to prevent XSS in template output. */
6
+ export function escapeHtml(s: string): string {
7
+ return s
8
+ .replace(/&/g, "&")
9
+ .replace(/</g, "&lt;")
10
+ .replace(/>/g, "&gt;")
11
+ .replace(/"/g, "&quot;")
12
+ .replace(/'/g, "&#39;");
13
+ }
14
+
15
+ /** Strip markdown JSON code fences that LLMs often wrap around JSON output. */
16
+ export function stripJsonFences(raw: string): string {
17
+ return raw.replace(/^```json?\n?/m, "").replace(/\n?```\s*$/m, "").trim();
18
+ }
19
+
20
+ /**
21
+ * Normalize a title for comparison: lowercase, strip punctuation (keep
22
+ * alphanumeric, Korean characters, and spaces), collapse whitespace.
23
+ */
24
+ export function normalizeTitle(title: string): string {
25
+ return title
26
+ .toLowerCase()
27
+ .trim()
28
+ .replace(/[^\w\s가-힣ㄱ-ㅎㅏ-ㅣ]/g, "")
29
+ .replace(/\s+/g, " ");
30
+ }