"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_string = require('../primordials/string.js');
const require_primordials_array = require('../primordials/array.js');

//#region src/env/string.ts
/**
* @file `envAsString` — coerce an env-var-shaped value into a string. Defaults
*   to trimming whitespace; `trim: false` preserves the value as-is. Positional
*   second argument is back-compat for the legacy `defaultValue` form.
*/
/**
* Convert an environment variable value to a string.
*
* Back-compat overload: passing a bare string as the second argument is
* equivalent to `{ defaultValue: S }`.
*
* @example
*   ;```typescript
*   import { envAsString } from '@socketsecurity/lib/env/string'
*
*   envAsString('  hello  ') // 'hello' (trimmed)
*   envAsString('  hello  ', { trim: false }) // '  hello  '
*   envAsString(undefined) // ''
*   envAsString(null, 'n/a') // 'n/a' (legacy positional)
*   ```
*
* @param value - The value to convert.
* @param defaultValueOrOptions - Default (string) or options object.
*
* @returns The string value, or the default value
*/
/*@__NO_SIDE_EFFECTS__*/
function envAsString(value, defaultValueOrOptions = "") {
	/* c8 ignore stop */
	const { defaultValue = "", trim = true } = typeof defaultValueOrOptions === "object" && defaultValueOrOptions !== null && !require_primordials_array.ArrayIsArray(defaultValueOrOptions) && ("defaultValue" in defaultValueOrOptions || "trim" in defaultValueOrOptions) ? defaultValueOrOptions : { defaultValue: defaultValueOrOptions === void 0 ? "" : typeof defaultValueOrOptions === "string" ? defaultValueOrOptions : require_primordials_string.StringCtor(defaultValueOrOptions) };
	if (value === void 0 || value === null) return defaultValue === "" || !trim ? defaultValue : require_primordials_string.StringCtor(defaultValue).trim();
	if (typeof value === "string") return trim ? value.trim() : value;
	/* c8 ignore next 2 */
	const str = require_primordials_string.StringCtor(value);
	return trim ? str.trim() : str;
}

//#endregion
exports.envAsString = envAsString;