UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

37 lines (36 loc) 1.29 kB
import { s as normalizeOptionalLowercaseString } from "./string-coerce-mnp54Vah.js"; //#region src/utils/boolean.ts const DEFAULT_TRUTHY = [ "true", "1", "yes", "on" ]; const DEFAULT_FALSY = [ "false", "0", "no", "off" ]; const DEFAULT_TRUTHY_SET = new Set(DEFAULT_TRUTHY); const DEFAULT_FALSY_SET = new Set(DEFAULT_FALSY); /** Returns only real boolean values and leaves boolean-like strings for explicit parsing. */ function asBoolean(value) { return typeof value === "boolean" ? value : void 0; } /** Parses booleans and configured string literals, returning undefined for ambiguous input. */ function parseBooleanValue(value, options = {}) { const booleanValue = asBoolean(value); if (booleanValue !== void 0) return booleanValue; if (typeof value !== "string") return; const normalized = normalizeOptionalLowercaseString(value); if (!normalized) return; const truthy = options.truthy ?? DEFAULT_TRUTHY; const falsy = options.falsy ?? DEFAULT_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; } //#endregion export { parseBooleanValue as n, asBoolean as t };