'use strict';

// src/utils/index.ts
function shortenAddress(address, chars = 4) {
  if (!address) return "";
  return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
}
function isValidAddress(address) {
  return /^0x[a-fA-F0-9]{40}$/.test(address);
}
function checksumAddress(address) {
  return address.toLowerCase();
}
function formatNumber(value, options = {}) {
  const { decimals = 2, compact = false, currency, locale = "en-US" } = options;
  if (currency) {
    return new Intl.NumberFormat(locale, {
      style: "currency",
      currency,
      minimumFractionDigits: decimals,
      maximumFractionDigits: decimals,
      notation: compact ? "compact" : "standard"
    }).format(value);
  }
  return new Intl.NumberFormat(locale, {
    minimumFractionDigits: decimals,
    maximumFractionDigits: decimals,
    notation: compact ? "compact" : "standard"
  }).format(value);
}
function formatUSD(value, compact = false) {
  return formatNumber(value, { currency: "USD", compact });
}
function formatPercent(value, decimals = 2) {
  const sign = value >= 0 ? "+" : "";
  return `${sign}${value.toFixed(decimals)}%`;
}
function formatTokenAmount(amount, decimals = 6) {
  if (amount === 0) return "0";
  if (amount < 1e-6) return "<0.000001";
  if (amount < 1) return amount.toFixed(decimals);
  if (amount < 1e3) return amount.toFixed(4);
  if (amount < 1e6) return formatNumber(amount, { decimals: 2 });
  return formatNumber(amount, { decimals: 2, compact: true });
}
function formatDate(date, options = {
  year: "numeric",
  month: "short",
  day: "numeric"
}) {
  const d = typeof date === "string" ? new Date(date) : date;
  return d.toLocaleDateString("en-US", options);
}
function formatDateTime(date) {
  const d = typeof date === "string" ? new Date(date) : date;
  return d.toLocaleString("en-US", {
    year: "numeric",
    month: "short",
    day: "numeric",
    hour: "2-digit",
    minute: "2-digit"
  });
}
function formatRelativeTime(date) {
  const d = typeof date === "string" ? new Date(date) : date;
  const now = /* @__PURE__ */ new Date();
  const diffMs = now.getTime() - d.getTime();
  const diffSec = Math.floor(diffMs / 1e3);
  const diffMin = Math.floor(diffSec / 60);
  const diffHour = Math.floor(diffMin / 60);
  const diffDay = Math.floor(diffHour / 24);
  if (diffSec < 60) return "just now";
  if (diffMin < 60) return `${diffMin}m ago`;
  if (diffHour < 24) return `${diffHour}h ago`;
  if (diffDay < 7) return `${diffDay}d ago`;
  return formatDate(d);
}
function isValidEmail(email) {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return emailRegex.test(email);
}
function isValidPhone(phone) {
  const phoneRegex = /^\+?[1-9]\d{1,14}$/;
  return phoneRegex.test(phone.replace(/[\s-()]/g, ""));
}
function capitalize(str) {
  return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}
function truncate(str, length) {
  if (str.length <= length) return str;
  return `${str.slice(0, length)}...`;
}
function slugify(str) {
  return str.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
}
function sleep(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}
async function retry(fn, options = {}) {
  const { maxAttempts = 3, delay = 1e3, backoff = 2 } = options;
  let lastError;
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
    try {
      return await fn();
    } catch (error) {
      lastError = error instanceof Error ? error : new Error(String(error));
      if (attempt < maxAttempts) {
        await sleep(delay * Math.pow(backoff, attempt - 1));
      }
    }
  }
  throw lastError;
}
function omit(obj, keys) {
  const result = { ...obj };
  for (const key of keys) {
    delete result[key];
  }
  return result;
}
function pick(obj, keys) {
  const result = {};
  for (const key of keys) {
    if (key in obj) {
      result[key] = obj[key];
    }
  }
  return result;
}
var OneSDKError = class extends Error {
  constructor(message, code, details) {
    super(message);
    this.name = "OneSDKError";
    this.code = code;
    this.details = details;
  }
};
function isOneSDKError(error) {
  return error instanceof OneSDKError;
}

exports.OneSDKError = OneSDKError;
exports.capitalize = capitalize;
exports.checksumAddress = checksumAddress;
exports.formatDate = formatDate;
exports.formatDateTime = formatDateTime;
exports.formatNumber = formatNumber;
exports.formatPercent = formatPercent;
exports.formatRelativeTime = formatRelativeTime;
exports.formatTokenAmount = formatTokenAmount;
exports.formatUSD = formatUSD;
exports.isOneSDKError = isOneSDKError;
exports.isValidAddress = isValidAddress;
exports.isValidEmail = isValidEmail;
exports.isValidPhone = isValidPhone;
exports.omit = omit;
exports.pick = pick;
exports.retry = retry;
exports.shortenAddress = shortenAddress;
exports.sleep = sleep;
exports.slugify = slugify;
exports.truncate = truncate;
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map