openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
34 lines (33 loc) • 888 B
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
//#region src/utils/boolean.ts
/**
* Shared boolean coercion helpers for config, env, and plugin SDK runtime inputs.
*
* `asBoolean` is intentionally strict; string parsing is opt-in through
* `parseBooleanValue` so schema callers do not silently accept ambiguous text.
*/
const DEFAULT_TRUTHY = [
"true",
"1",
"yes",
"on"
];
const DEFAULT_FALSY = [
"false",
"0",
"no",
"off"
];
function asBoolean(e) {
return typeof e === "boolean" ? e : void 0;
}
function parseBooleanValue(e, t = {}) {
const n = asBoolean(e);
if (n !== void 0) return n;
const r = normalizeOptionalLowercaseString(e);
if (!r) return;
if ((t.truthy ?? DEFAULT_TRUTHY).includes(r)) return true;
if ((t.falsy ?? DEFAULT_FALSY).includes(r)) return false;
}
//#endregion
export { parseBooleanValue as n, asBoolean as t };