"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var search_params_exports = {};
__export(search_params_exports, {
  urlSearchParamsAsArray: () => urlSearchParamsAsArray,
  urlSearchParamsAsBoolean: () => urlSearchParamsAsBoolean,
  urlSearchParamsAsNumber: () => urlSearchParamsAsNumber,
  urlSearchParamsAsString: () => urlSearchParamsAsString,
  urlSearchParamsGetArray: () => urlSearchParamsGetArray,
  urlSearchParamsGetBoolean: () => urlSearchParamsGetBoolean
});
module.exports = __toCommonJS(search_params_exports);
var import_number = require("../primordials/number");
const BooleanCtor = Boolean;
// @__NO_SIDE_EFFECTS__
function urlSearchParamsAsArray(value) {
  return typeof value === "string" ? value.trim().split(/, */).map((v) => v.trim()).filter(BooleanCtor) : [];
}
// @__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;
}
// @__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 !(0, import_number.NumberIsNaN)(num) ? num : defaultValue;
    }
  }
  return defaultValue;
}
// @__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;
}
// @__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 [];
}
// @__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;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  urlSearchParamsAsArray,
  urlSearchParamsAsBoolean,
  urlSearchParamsAsNumber,
  urlSearchParamsAsString,
  urlSearchParamsGetArray,
  urlSearchParamsGetBoolean
});
