qwenproxy-cli 1.6.4 → 1.6.5

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,56 @@
1
+ /**
2
+ * timezone.ts — Locale-safe ASCII timezone header formatting and sanitization.
3
+ *
4
+ * Guarantees that HTTP headers passed into browser `window.fetch()` contain
5
+ * exclusively ISO-8859-1 code points (<= 255), preventing:
6
+ * `TypeError: Failed to read the 'headers' property from 'RequestInit': String contains non ISO-8859-1 code point`
7
+ * on systems configured with non-English locales (e.g. Russian, CJK, Arabic).
8
+ */
9
+
10
+ const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
11
+ const MONTHS = [
12
+ "Jan",
13
+ "Feb",
14
+ "Mar",
15
+ "Apr",
16
+ "May",
17
+ "Jun",
18
+ "Jul",
19
+ "Aug",
20
+ "Sep",
21
+ "Oct",
22
+ "Nov",
23
+ "Dec",
24
+ ];
25
+
26
+ /**
27
+ * Format a Date into standard English browser date string matching Chrome,
28
+ * guaranteed pure ASCII (<= 127).
29
+ * Example: "Tue Oct 20 2026 14:35:10 GMT-0300"
30
+ */
31
+ export function formatAsciiTimezone(date: Date = new Date()): string {
32
+ const dayName = DAYS[date.getDay()];
33
+ const monthName = MONTHS[date.getMonth()];
34
+ const day = String(date.getDate()).padStart(2, "0");
35
+ const year = date.getFullYear();
36
+ const hours = String(date.getHours()).padStart(2, "0");
37
+ const minutes = String(date.getMinutes()).padStart(2, "0");
38
+ const seconds = String(date.getSeconds()).padStart(2, "0");
39
+
40
+ const offsetMinutes = -date.getTimezoneOffset();
41
+ const sign = offsetMinutes >= 0 ? "+" : "-";
42
+ const absOffset = Math.abs(offsetMinutes);
43
+ const offsetHours = String(Math.floor(absOffset / 60)).padStart(2, "0");
44
+ const offsetMins = String(absOffset % 60).padStart(2, "0");
45
+ const tzOffset = `GMT${sign}${offsetHours}${offsetMins}`;
46
+
47
+ return `${dayName} ${monthName} ${day} ${year} ${hours}:${minutes}:${seconds} ${tzOffset}`;
48
+ }
49
+
50
+ /**
51
+ * Sanitizes header values for browser fetch, stripping any code points > 255.
52
+ */
53
+ export function sanitizeHeaderForFetch(val: string): string {
54
+ if (typeof val !== "string") return "";
55
+ return val.replace(/[^\x00-\xFF]/g, "");
56
+ }