mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-22 20:18:07 +00:00
19 lines
684 B
TypeScript
19 lines
684 B
TypeScript
// Normalizes HTTP path values used by plugin manifests and routes.
|
|
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
|
|
|
|
/** Normalizes plugin HTTP paths to leading-slash form with optional fallback. */
|
|
export function normalizePluginHttpPath(
|
|
path?: string | null,
|
|
fallback?: string | null,
|
|
): string | null {
|
|
const trimmed = normalizeOptionalString(path);
|
|
if (!trimmed) {
|
|
const fallbackTrimmed = normalizeOptionalString(fallback);
|
|
if (!fallbackTrimmed) {
|
|
return null;
|
|
}
|
|
return fallbackTrimmed.startsWith("/") ? fallbackTrimmed : `/${fallbackTrimmed}`;
|
|
}
|
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
}
|