"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });

//#region src/env/boolean.ts
/**
* Convert an environment variable value to a boolean.
*
* Back-compat overload: passing a bare boolean as the second argument is
* equivalent to `{ defaultValue: B }`.
*
* @example
*   ;```typescript
*   import { envAsBoolean } from '@socketsecurity/lib/env/boolean'
*
*   envAsBoolean('true') // true
*   envAsBoolean('1') // true
*   envAsBoolean('yes') // true
*   envAsBoolean('  true  ') // true (trimmed)
*   envAsBoolean('  true  ', { trim: false }) // false (strict)
*   envAsBoolean(undefined) // false
*   envAsBoolean(undefined, true) // true (legacy positional default)
*   ```
*
* @param value - The value to convert.
* @param defaultValueOrOptions - Default (boolean) or options object.
*
* @returns `true` if value is '1', 'true', or 'yes' (case-insensitive), `false`
*   otherwise.
*/
/*@__NO_SIDE_EFFECTS__*/
function envAsBoolean(value, defaultValueOrOptions = false) {
	const { defaultValue = false, trim = true } = typeof defaultValueOrOptions === "boolean" ? { defaultValue: defaultValueOrOptions } : defaultValueOrOptions ?? {};
	if (typeof value === "string") {
		const candidate = trim ? value.trim() : value;
		if (!candidate) return !!defaultValue;
		const lower = candidate.toLowerCase();
		return lower === "1" || lower === "true" || lower === "yes";
	}
	if (value === null || value === void 0) return !!defaultValue;
	return !!value;
}

//#endregion
exports.envAsBoolean = envAsBoolean;