const a = /^[-−–+]?(\d+)?[.,]?(\d+)?$/;
function i(r) {
  return r === "." || r === "," || r === "-";
}
function l(r) {
  return r = r.trim(), r = r.replace(",", "."), r = r.replace("−", "-"), r = r.replace("–", "-"), r = r.replace("+", ""), r;
}
function o(r) {
  return parseFloat(l(r));
}
function c(r) {
  if (r = r.trim(), i(r))
    return r;
  if (/^-[^0-9.]/.test(r))
    return "-";
  const n = r.match(/^(.*)[.,][^0-9].*$/);
  if (n)
    return n[1] + ".";
  if (r.match(a))
    return l(r);
  const e = o(r);
  return isNaN(e) ? "" : String(+e);
}
function m(r, n) {
  n = n.trim();
  const e = c(n);
  if (n === "")
    return {
      value: void 0,
      cleanInput: e
    };
  if (!n.match(a))
    return {
      error: Error("Value is not a number"),
      cleanInput: e
    };
  if (i(n))
    return {
      error: Error("Enter a number"),
      cleanInput: e
    };
  const t = o(n);
  if (isNaN(t))
    return {
      error: Error("Value is not a number"),
      cleanInput: e
    };
  if (r.minValue !== void 0 && t < r.minValue)
    return {
      error: Error(`Value must be higher than ${r.minValue}`),
      value: t,
      cleanInput: e
    };
  if (r.maxValue !== void 0 && t > r.maxValue)
    return {
      error: Error(`Value must be less than ${r.maxValue}`),
      value: t,
      cleanInput: e
    };
  if (r.validate) {
    const u = r.validate(t);
    if (u)
      return {
        error: Error(u),
        value: t,
        cleanInput: e
      };
  }
  return {
    value: t,
    cleanInput: e
  };
}
export {
  m as parseNumber
};
//# sourceMappingURL=parseNumber.js.map
