mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-26 17:32:16 +00:00
24 lines
701 B
TypeScript
24 lines
701 B
TypeScript
import path from "node:path";
|
|
|
|
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 base.trim().toLowerCase();
|
|
}
|
|
|
|
export function normalizeExecutableToken(token: string): string {
|
|
return stripWindowsExecutableSuffix(basenameLower(token));
|
|
}
|