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

//#region src/url/search-params.ts
/**
* @file URL search-param coercion helpers — `urlSearchParamsAs*` normalise a
*   raw `string | null | undefined` value into a typed shape (array / boolean /
*   number / string) with a default. `urlSearchParamsGet*` take a
*   `URLSearchParams` instance and a key.
*/
const BooleanCtor = Boolean;
/**
* Convert a URL search parameter to an array.
*
* @example
*   ;```typescript
*   urlSearchParamsAsArray('a, b, c') // ['a', 'b', 'c']
*   urlSearchParamsAsArray(null) // []
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function urlSearchParamsAsArray(value) {
	return typeof value === "string" ? value.trim().split(/, */).map((v) => v.trim()).filter(BooleanCtor) : [];
}
/**
* Convert a URL search parameter to a boolean.
*
* @example
*   ;```typescript
*   urlSearchParamsAsBoolean('true') // true
*   urlSearchParamsAsBoolean('0') // false
*   urlSearchParamsAsBoolean(null) // false
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function urlSearchParamsAsBoolean(value, options) {
	const { defaultValue = false } = {
		__proto__: null,
		...options
	};
	if (typeof value === "string") {
		const trimmed = value.trim();
		if (trimmed === "") return !!defaultValue;
		const lowered = trimmed.toLowerCase();
		return lowered === "1" || lowered === "true" || lowered === "yes" || lowered === "on";
	}
	if (value === null || value === void 0) return !!defaultValue;
	return !!value;
}
/**
* Get number value from URLSearchParams with a default.
*
* @example
*   ;```typescript
*   const params = new URLSearchParams('limit=10')
*   urlSearchParamsAsNumber(params, 'limit') // 10
*   urlSearchParamsAsNumber(params, 'other') // 0
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function urlSearchParamsAsNumber(params, key, options) {
	const { defaultValue = 0 } = {
		__proto__: null,
		...options
	};
	if (params && typeof params.get === "function") {
		const value = params.get(key);
		if (value !== null) {
			const num = Number(value);
			return !require_primordials_number.NumberIsNaN(num) ? num : defaultValue;
		}
	}
	return defaultValue;
}
/**
* Get string value from URLSearchParams with a default.
*
* @example
*   ;```typescript
*   const params = new URLSearchParams('name=socket')
*   urlSearchParamsAsString(params, 'name') // 'socket'
*   urlSearchParamsAsString(params, 'other') // ''
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function urlSearchParamsAsString(params, key, options) {
	const { defaultValue = "" } = {
		__proto__: null,
		...options
	};
	if (params && typeof params.get === "function") {
		const value = params.get(key);
		return value !== null ? value : defaultValue;
	}
	return defaultValue;
}
/**
* Helper to get array from URLSearchParams.
*
* @example
*   ;```typescript
*   const params = new URLSearchParams('tags=a,b,c')
*   urlSearchParamsGetArray(params, 'tags') // ['a', 'b', 'c']
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function urlSearchParamsGetArray(params, key) {
	if (params && typeof params.getAll === "function") {
		const values = params.getAll(key);
		const firstValue = values[0];
		if (values.length === 1 && firstValue && firstValue.includes(",")) return /* @__PURE__ */ urlSearchParamsAsArray(firstValue);
		return values;
	}
	return [];
}
/**
* Helper to get boolean from URLSearchParams.
*
* @example
*   ;```typescript
*   const params = new URLSearchParams('debug=true')
*   urlSearchParamsGetBoolean(params, 'debug') // true
*   urlSearchParamsGetBoolean(params, 'other') // false
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function urlSearchParamsGetBoolean(params, key, options) {
	const { defaultValue = false } = {
		__proto__: null,
		...options
	};
	if (params && typeof params.get === "function") {
		const value = params.get(key);
		return value !== null ? /* @__PURE__ */ urlSearchParamsAsBoolean(value, { defaultValue }) : defaultValue;
	}
	return defaultValue;
}

//#endregion
exports.urlSearchParamsAsArray = urlSearchParamsAsArray;
exports.urlSearchParamsAsBoolean = urlSearchParamsAsBoolean;
exports.urlSearchParamsAsNumber = urlSearchParamsAsNumber;
exports.urlSearchParamsAsString = urlSearchParamsAsString;
exports.urlSearchParamsGetArray = urlSearchParamsGetArray;
exports.urlSearchParamsGetBoolean = urlSearchParamsGetBoolean;