mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-08 08:02:56 +00:00
25 lines
791 B
TypeScript
25 lines
791 B
TypeScript
import path from "node:path";
|
|
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
|
|
|
|
const WINDOWS_EXECUTABLE_SUFFIXES = [".exe", ".cmd", ".bat", ".com"] as const;
|
|
|
|
function stripWindowsExecutableSuffix(value: string): string {
|
|
for (const suffix of WINDOWS_EXECUTABLE_SUFFIXES) {
|
|
if (value.endsWith(suffix)) {
|
|
return value.slice(0, -suffix.length);
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
|
|
export function basenameLower(token: string): string {
|
|
const win = path.win32.basename(token);
|
|
const posix = path.posix.basename(token);
|
|
const base = win.length < posix.length ? win : posix;
|
|
return normalizeLowercaseStringOrEmpty(base);
|
|
}
|
|
|
|
export function normalizeExecutableToken(token: string): string {
|
|
return stripWindowsExecutableSuffix(basenameLower(token));
|
|
}
|