mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 20:00:44 +00:00
32 lines
890 B
TypeScript
32 lines
890 B
TypeScript
export type CommandPathMatchRule =
|
|
| readonly string[]
|
|
| {
|
|
pattern: readonly string[];
|
|
exact?: boolean;
|
|
};
|
|
|
|
export function matchesCommandPath(
|
|
commandPath: string[],
|
|
pattern: readonly string[],
|
|
params?: { exact?: boolean },
|
|
): boolean {
|
|
if (pattern.some((segment, index) => commandPath[index] !== segment)) {
|
|
return false;
|
|
}
|
|
return !params?.exact || commandPath.length === pattern.length;
|
|
}
|
|
|
|
export function matchesCommandPathRule(commandPath: string[], rule: CommandPathMatchRule): boolean {
|
|
if (Array.isArray(rule)) {
|
|
return matchesCommandPath(commandPath, rule);
|
|
}
|
|
return matchesCommandPath(commandPath, rule.pattern, { exact: rule.exact });
|
|
}
|
|
|
|
export function matchesAnyCommandPath(
|
|
commandPath: string[],
|
|
rules: readonly CommandPathMatchRule[],
|
|
): boolean {
|
|
return rules.some((rule) => matchesCommandPathRule(commandPath, rule));
|
|
}
|