@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 41 lines 1.34 KB
Raw
1 const POSTFIX_REGEX = /[?#].*$/;
2
3 export function sanitizePath(path: string): string {
4 return path.replace(POSTFIX_REGEX, "");
5 }
6
7 /**
8 * Normalizes a path to use forward slashes. This ensures paths are valid
9 * module specifiers and produce consistent output across platforms (e.g. Windows,
10 * where `path` APIs return backslash-separated paths).
11 */
12 export function toPosixPath(path: string): string {
13 return path.replace(/\\/g, "/");
14 }
15
16 export function hasNodejsCompat(
17 flags?: ReadonlyArray<string>,
18 compatibilityDate?: string,
19 ): boolean {
20 // Both nodejs_compat modes are runtime defaults from 2026-08-04, so builds
21 // for newer dates must enable the same transforms without a redundant flag.
22 if (
23 compatibilityDate !== undefined &&
24 compatibilityDate >= "2026-08-04" &&
25 !flags?.includes("no_nodejs_compat")
26 ) {
27 return true;
28 }
29 return flags?.some((flag) => flag === "nodejs_compat" || flag === "nodejs_compat_v2") ?? false;
30 }
31
32 export function hasNodejsAls(flags?: ReadonlyArray<string>): boolean {
33 return flags?.some((flag) => flag === "nodejs_als") ?? false;
34 }
35
36 export function resolvePluginApi<Api>(plugins: ReadonlyArray<unknown>, name: string) {
37 return plugins.find(
38 (plugin): plugin is { name: string; api: Api } =>
39 typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === name,
40 )?.api;
41 }