"use strict";
/* Socket Lib - Built with esbuild */
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 json_exports = {};
__export(json_exports, {
  isJsonPrimitive: () => isJsonPrimitive,
  jsonParse: () => jsonParse
});
module.exports = __toCommonJS(json_exports);
var import_strings = require("./strings");
const JSONParse = JSON.parse;
// @__NO_SIDE_EFFECTS__
function isBuffer(x) {
  if (!x || typeof x !== "object") {
    return false;
  }
  const obj = x;
  if (typeof obj["length"] !== "number") {
    return false;
  }
  if (typeof obj["copy"] !== "function" || typeof obj["slice"] !== "function") {
    return false;
  }
  if (typeof obj["length"] === "number" && obj["length"] > 0 && typeof obj[0] !== "number") {
    return false;
  }
  const Ctor = x.constructor;
  return !!(typeof Ctor?.isBuffer === "function" && Ctor.isBuffer(x));
}
// @__NO_SIDE_EFFECTS__
function isJsonPrimitive(value) {
  return value === null || typeof value === "boolean" || typeof value === "number" || typeof value === "string";
}
// @__NO_SIDE_EFFECTS__
function jsonParse(content, options) {
  const { filepath, reviver, throws } = {
    __proto__: null,
    ...options
  };
  const shouldThrow = throws === void 0 || !!throws;
  const jsonStr = /* @__PURE__ */ isBuffer(content) ? content.toString("utf8") : content;
  try {
    return JSONParse((0, import_strings.stripBom)(jsonStr), reviver);
  } catch (e) {
    if (shouldThrow) {
      const error = e;
      if (error && typeof filepath === "string") {
        error.message = `${filepath}: ${error.message}`;
      }
      throw error;
    }
  }
  return void 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  isJsonPrimitive,
  jsonParse
});
