"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);

// src/index.ts
var index_exports = {};
__export(index_exports, {
  camelize: () => camelize,
  camelize_str: () => camelize_str,
  clone: () => clone,
  compare: () => compare,
  is_object: () => is_object,
  is_object_literal: () => is_object_literal,
  merge: () => merge,
  mutate: () => mutate,
  snake_case: () => snake_case,
  snake_case_str: () => snake_case_str
});
module.exports = __toCommonJS(index_exports);
function camelize(source, depth = true) {
  const target = {};
  if (is_object_literal(source)) {
    const d = typeof depth === "number" && depth > 0 ? depth - 1 : depth;
    for (const key of Object.keys(source)) {
      const value = source[key];
      const camelizedKey = depth ? camelize_str(key) : key;
      if (is_object(value)) {
        target[camelizedKey] = camelize(value, d);
      } else {
        target[camelizedKey] = value;
      }
    }
  } else {
    return source;
  }
  return target;
}
function camelize_str(str) {
  return str.replace(/[_.-](\w|$)/g, (_, x) => x.toUpperCase());
}
function compare(el1, el2) {
  if (is_object_literal(el1) && is_object_literal(el2)) {
    const keys1 = Object.keys(el1).sort();
    const keys2 = Object.keys(el2).sort();
    if (keys1.length !== keys2.length) {
      return false;
    }
    return keys1.every(
      (key, i) => key === keys2[i] && compare(el1[key], el2[key])
    );
  }
  if (Array.isArray(el1) && Array.isArray(el2)) {
    if (el1.length !== el2.length) {
      return false;
    }
    return el1.every((item, i) => compare(item, el2[i]));
  }
  return el1 === el2;
}
function clone(target) {
  if (Array.isArray(target)) {
    return target.map((element) => clone(element));
  }
  if (target && typeof target === "object") {
    return mutate({}, target);
  }
  return target;
}
function is_object(obj) {
  return Boolean(obj) && typeof obj === "object" && !Array.isArray(obj);
}
function is_object_literal(obj) {
  if (typeof obj !== "object" || obj === null) {
    return false;
  }
  const proto = Object.getPrototypeOf(obj);
  if (proto === null) {
    return true;
  }
  let test = obj;
  while (true) {
    if (Object.getPrototypeOf(test = Object.getPrototypeOf(test)) === null)
      break;
  }
  return Object.getPrototypeOf(obj) === test;
}
function merge(...args) {
  return mutate({}, ...args);
}
function mutate(target, ...args) {
  for (let i = 0; i < args.length; i++) {
    const source = args[i];
    if (is_object_literal(source)) {
      if (target == null || !is_object_literal(target)) {
        target = {};
      }
      const targetObj = target;
      for (const name of Object.keys(source)) {
        if (/__proto__|prototype/.test(name)) {
          continue;
        }
        targetObj[name] = mutate(
          targetObj[name],
          source[name]
        );
      }
    } else if (Array.isArray(source)) {
      target = source.map((element) => clone(element));
    } else if (source !== void 0) {
      target = source;
    }
  }
  return target;
}
function snake_case(source, depth = true) {
  const target = {};
  if (is_object_literal(source)) {
    const d = typeof depth === "number" && depth > 0 ? depth - 1 : depth;
    for (const key of Object.keys(source)) {
      const value = source[key];
      const snakeKey = depth ? snake_case_str(key) : key;
      if (is_object(value)) {
        target[snakeKey] = snake_case(value, d);
      } else {
        target[snakeKey] = value;
      }
    }
  } else {
    return source;
  }
  return target;
}
function snake_case_str(str) {
  return str.replace(/([a-z\d])([A-Z]+)/g, "$1_$2").replace(/[-\s]+/g, "_").toLowerCase();
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  camelize,
  camelize_str,
  clone,
  compare,
  is_object,
  is_object_literal,
  merge,
  mutate,
  snake_case,
  snake_case_str
});
//# sourceMappingURL=index.cjs.map