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

//#region src/env/number.ts
/**
* @file `envAsNumber` — coerce an env-var-shaped value into a number. `mode:
*   'int'` uses `parseInt(_, 10)`; `mode: 'float'` uses `Number()`. Non-finite
*   results round-trip through `defaultValue` unless `allowInfinity: true` is
*   set.
*/
/**
* Convert an environment variable value to a number.
*
* Back-compat overload: passing a bare number as the second argument is
* equivalent to `{ defaultValue: N }`.
*
* @example
*   ;```typescript
*   import { envAsNumber } from '@socketsecurity/lib/env/number'
*
*   envAsNumber('3000') // 3000 (int mode)
*   envAsNumber('3.14', { mode: 'float' }) // 3.14
*   envAsNumber('abc') // 0
*   envAsNumber(undefined, 42) // 42 (legacy positional default)
*   ```
*
* @param value - The value to convert.
* @param defaultValueOrOptions - Default (number) or options object.
*
* @returns The parsed number, or the default value if parsing fails
*/
/*@__NO_SIDE_EFFECTS__*/
function envAsNumber(value, defaultValueOrOptions = 0) {
	const { allowInfinity = false, defaultValue = 0, mode = "int" } = typeof defaultValueOrOptions === "number" ? { defaultValue: defaultValueOrOptions } : defaultValueOrOptions ?? {};
	if (value === void 0 || value === null) return defaultValue;
	if (typeof value === "string") {
		if (!value) return defaultValue;
		/* c8 ignore start */
		const num = mode === "float" ? require_primordials_number.NumberCtor(value) : require_primordials_number.NumberParseInt(value, 10);
		if (require_primordials_number.NumberIsNaN(num)) return defaultValue;
		if (!require_primordials_number.NumberIsFinite(num)) return allowInfinity ? num : defaultValue;
		return num || 0;
	}
	/* c8 ignore start */
	const numOrNaN = mode === "float" ? require_primordials_number.NumberCtor(String(value)) : require_primordials_number.NumberParseInt(String(value), 10);
	return (require_primordials_number.NumberIsFinite(numOrNaN) ? numOrNaN : require_primordials_number.NumberCtor(defaultValue)) || 0;
	/* c8 ignore stop */
}

//#endregion
exports.envAsNumber = envAsNumber;