fix: optimize routed CLI path (#1195) (thanks @gumadeiras)

This commit is contained in:
Peter Steinberger
2026-01-18 23:28:09 +00:00
parent fac0110e49
commit d5c8172197
9 changed files with 153 additions and 16 deletions

View File

@@ -5,6 +5,8 @@ export type BooleanParseOptions = {
const DEFAULT_TRUTHY = ["true", "1", "yes", "on"] as const;
const DEFAULT_FALSY = ["false", "0", "no", "off"] as const;
const DEFAULT_TRUTHY_SET = new Set<string>(DEFAULT_TRUTHY);
const DEFAULT_FALSY_SET = new Set<string>(DEFAULT_FALSY);
export function parseBooleanValue(
value: unknown,
@@ -16,9 +18,9 @@ export function parseBooleanValue(
if (!normalized) return undefined;
const truthy = options.truthy ?? DEFAULT_TRUTHY;
const falsy = options.falsy ?? DEFAULT_FALSY;
const truthySet = new Set<string>(truthy);
const falsySet = new Set<string>(falsy);
const truthySet = truthy === DEFAULT_TRUTHY ? DEFAULT_TRUTHY_SET : new Set(truthy);
const falsySet = falsy === DEFAULT_FALSY ? DEFAULT_FALSY_SET : new Set(falsy);
if (truthySet.has(normalized)) return true;
if (falsySet.has(normalized)) return false;
return undefined;
}
}